Adding an additional download file to webreport

Newbie at hacking the code!
Running 5.1.2 and linux mint

I want to add another download option to the Narrative web report and hacked the download.py to add another section for dlfname3 , thus;
# if download filename #3, show it???
if dlfname3:

                    # begin row #3
                    trow = Html("tr", id='Row03')
                    tbody += trow

                    fname = os.path.basename(dlfname3)
                    tcell = Html("td", class_="ColumnFilename") + (
                        Html("a", fname, href=dlfname3,
                             title=html_escape(dldescr3))
                    )
                    trow += tcell

                    dldescr3 = dldescr3 or " "
                    trow += Html("td", dldescr3,
                                 class_="ColumnDescription", inline=True)

                    tcell = Html("td", id='Col04',
                                 class_="ColumnModified", inline=True)
                    trow += tcell
                    if os.path.exists(dlfname3):
                        modified = os.stat(dlfname3).st_mtime
                        last_mod = datetime.datetime.fromtimestamp(modified)
                        tcell += last_mod
                    else:
                        tcell += " "

and declared it below so all three sections (one for each file) seem like they are identical, thus

    # download and description #3
    dlfname3 = self.report.dl_fname3
    dldescr3 = self.report.dl_descr3

I then added the two additional command line input variables to the bash script I normally run, thus;
dl_descr3=DNA traceability2 graph,
down_fname3=Geraldinia-MillstreetDNA-FamilyLines-$(date +“%F”).pdf,\

But I guess the parser of the command line script cannot digest these additional inputs and pass them to the program so when I run it I get;

Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/gramps/cli/plug/init.py”, line 702, in cl_report
my_report.write_report()
File “/usr/lib/python3/dist-packages/gramps/plugins/webreport/narrativeweb.py”, line 408, in write_report
self.base_pages()
File “/usr/lib/python3/dist-packages/gramps/plugins/webreport/narrativeweb.py”, line 1241, in base_pages
DownloadPage(self, self.title)
File “/usr/lib/python3/dist-packages/gramps/plugins/webreport/download.py”, line 91, in init
dlfname3 = self.report.dl_fname3
AttributeError: ‘NavWebReport’ object has no attribute ‘dl_fname3’
Cleaning up.

Can some kind soul point me where I should patch the command-line parser correctly.

Of course if this is not all I need to accomplish then advise as well please.

Stay safe and healthy!
brian

I am not a coder but…

You would first need to define “dl_fname3” in the file that sets the narrweb in play: narrativeweb.py

You need to modify narrativeweb.py for that.
Where do you set dlfname3 ?

    # download and description #3
    dlfname3 = self.report.dl_fname3
    dldescr3 = self.report.dl_descr3

You need to add the following in the narrativeweb.py file:

in the init method:

        # Download Options Tab
        self.inc_download = self.options['incdownload']
        self.dl_fname1 = self.options['down_fname1']
        self.dl_descr1 = self.options['dl_descr1']
        self.dl_fname2 = self.options['down_fname2']
        self.dl_descr2 = self.options['dl_descr2']
        self.dl_fname3 = self.options['down_fname3']
        self.dl_descr3 = self.options['dl_descr3']

and in the __add_download_options method:

        self.__down_fname3 = DestinationOption(
            _("Download Filename"),
            os.path.join(config.get('paths.website-directory'), ""))
        self.__down_fname3.set_help(
            _("File to be used for downloading of database"))
        addopt("down_fname3", self.__down_fname3)

        self.__dl_descr3 = StringOption(_("Description for download"),
                                        _('My new Family Tree'))
        self.__dl_descr3.set_help(_('Give a description for this file.'))
        addopt("dl_descr3", self.__dl_descr3)

Hope that helps and I didn’t miss something

2 Likes

Is there other people interested in more than two downloads ?

1 Like

I create the feature request #11626 for that.
The associated PR is https://github.com/gramps-project/gramps/pull/1024

3 Likes

Thank you Serge,
I am increasingly seeing people mistrusting the available download files if we do not also supply a MD5 hash which they can verify as “authentic”.

Even the narrative website itself now must really be deployed as https and no longer http. Maybe think of building in links to “certbot”, for example, or secure virtual hosts.

Maybe that’s too far but some deployment advice might be appreciated.

Gramps should probably factor-in some security paradigms to assist the average user.

I mean my cousins will trust me but other collaborators don’t really know me from the next stranger and in this world of cyber-threats everything we do should attempt to lower the risk to others we deal with.
Static HTML is intrinsically safer that the dynamic reports also available but I wanted to see if I could supply some other variations on the standard offering, so that is why I finally said to myself “…just learn how to do it yourself…”.

thank you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.