Exemple #1
0
    def build_header(self):
        """
        Build up the header of the html file over the defaults of Html()
        """
        # add additional meta tags and stylesheet links to head section
        # create additional meta tags
        _meta1 = 'name="generator" content="%s %s %s"' % (
            PROGRAM_NAME, VERSION, URL_HOMEPAGE)
        meta = Html('meta', attr=_meta1)

        #set styles of the report as inline css
        self.build_style_declaration()

        # Gramps favicon en css
        fname1 = '/'.join([self._backend.datadir(), 'favicon.ico'])
        fname2 = '/'.join([self._backend.datadir(), _TEXTDOCSCREEN])
        fname3 = '/'.join([self._backend.datadir(), _HTMLSCREEN])

        # links for Gramps favicon and stylesheets
        links = Html(
            'link', rel='shortcut icon', href=fname1,
            type='image/x-icon') + (Html('link',
                                         rel='stylesheet',
                                         href=fname2,
                                         type='text/css',
                                         media='screen',
                                         indent=False), )
        if self.css_filename:
            links += (Html('link',
                           rel='stylesheet',
                           href=fname3,
                           type='text/css',
                           media='screen',
                           indent=False), )
        self._backend.html_header += (meta, links)
Exemple #2
0
def styledtext_to_html(
    styledtext: StyledText,
    space_format: int,
    contains_html: bool = False,
    link_format: Optional[str] = None,
):
    """Return the note in HTML format.

    Adapted from DynamicWeb.
    """
    backend = HtmlBackend()
    if link_format is not None:
        backend.build_link = build_link_factory(link_format)

    text = str(styledtext)

    if not text:
        return ""

    s_tags = styledtext.get_tags()
    html_list = Html("div", class_="grampsstylednote")
    if contains_html:
        markuptext = backend.add_markup_from_styled(text,
                                                    s_tags,
                                                    split="\n",
                                                    escape=False)
        html_list += markuptext
    else:
        markuptext = backend.add_markup_from_styled(text, s_tags, split="\n")
        linelist = []
        linenb = 1
        sigcount = 0
        for line in markuptext.split("\n"):
            [line, sigcount] = process_spaces(line, format=space_format)
            if sigcount == 0:
                # The rendering of an empty paragraph '<p></p>'
                # is undefined so we use a non-breaking space
                if linenb == 1:
                    linelist.append("&nbsp;")
                html_list.extend(Html("p") + linelist)
                linelist = []
                linenb = 1
            else:
                if linenb > 1:
                    linelist[-1] += "<br />"
                linelist.append(line)
                linenb += 1
        if linenb > 1:
            html_list.extend(Html("p") + linelist)
        # if the last line was blank, then as well as outputting the previous para,
        # which we have just done,
        # we also output a new blank para
        if sigcount == 0:
            linelist = ["&nbsp;"]
            html_list.extend(Html("p") + linelist)
    return "\n".join(html_list)
Exemple #3
0
    def __init__(self, report, the_lang, the_title, person_handle, has_add,
                 has_res, has_url):
        """
        @param: report        -- The instance of the main report class
                                 for this report
        @param: the_lang      -- The lang to process
        @param: the_title     -- The title page related to the language
        @param: person_handle -- the url, address and residence to use
                                 for the report
        @param: has_add       -- the address to use for the report
        @param: has_res       -- the residence to use for the report
        @param: has_url       -- the url to use for the report
        """
        person = report.database.get_person_from_handle(person_handle)
        BasePage.__init__(self, report, the_lang, the_title, person.gramps_id)
        self.bibli = Bibliography()

        self.uplink = True

        # set the file name and open file
        output_file, sio = self.report.create_file(person_handle, "addr")
        result = self.write_header(_("Address Book"))
        addressbookpage, dummy_head, dummy_body, outerwrapper = result

        # begin address book page division and section title
        with Html("div", class_="content",
                  id="AddressBookDetail") as addressbookdetail:
            outerwrapper += addressbookdetail

            link = self.new_person_link(person_handle,
                                        uplink=True,
                                        person=person)
            addressbookdetail += Html("h3", link)

            # individual has an address
            if has_add:
                addressbookdetail += self.display_addr_list(has_add, None)

            # individual has a residence
            if has_res:
                addressbookdetail.extend(
                    self.dump_residence(res) for res in has_res)

            # individual has a url
            if has_url:
                addressbookdetail += self.display_url_list(has_url)

        # add fullclear for proper styling
        # and footer section to page
        footer = self.write_footer(None)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(addressbookpage, output_file, sio, 0)
Exemple #4
0
def alphabet_navigation(sorted_alpha_index, rlocale=glocale):
    """
    Will create the alphabet navigation bar for classes IndividualListPage,
    SurnameListPage, PlaceListPage, and EventList

    @param: index_list -- a dictionary of either letters or words
    @param: rlocale    -- The locale to use
    """
    # if no letters, return None to its callers
    if not sorted_alpha_index:
        return None

    num_ltrs = len(sorted_alpha_index)
    num_of_cols = 26
    num_of_rows = ((num_ltrs // num_of_cols) + 1)

    # begin alphabet navigation division
    with Html("div", id="alphanav") as alphabetnavigation:

        index = 0
        output = []
        dup_index = 0
        for dummy_row in range(num_of_rows):
            unordered = Html("ul")

            cols = 0
            while cols <= num_of_cols and index < num_ltrs:
                menu_item = sorted_alpha_index[index]
                if menu_item == ' ':
                    menu_item = '&nbsp;'
                # adding title to hyperlink menu for screen readers and
                # braille writers
                title_txt = "Alphabet Menu: %s" % menu_item
                title_str = rlocale.translation.sgettext(title_txt)
                # deal with multiple ellipsis which are generated for overflow,
                # underflow and inflow labels
                link = menu_item
                if menu_item in output:
                    link = "%s (%i)" % (menu_item, dup_index)
                    dup_index += 1
                output.append(menu_item)

                hyper = Html("a",
                             menu_item,
                             title=title_str,
                             href="#%s" % link)
                unordered.extend(Html("li", hyper, inline=True))

                index += 1
                cols += 1
            num_of_rows -= 1

            alphabetnavigation += unordered

    return alphabetnavigation
Exemple #5
0
def alphabet_navigation(index_list, rlocale=glocale):
    """
    Will create the alphabet navigation bar for classes IndividualListPage,
    SurnameListPage, PlaceListPage, and EventList

    @param: index_list -- a dictionary of either letters or words
    @param: rlocale    -- The locale to use
    """
    sorted_set = defaultdict(int)

    for menu_item in index_list:
        sorted_set[menu_item] += 1

    # remove the number of each occurance of each letter
    sorted_alpha_index = sorted(sorted_set, key=rlocale.sort_key)

    # if no letters, return None to its callers
    if not sorted_alpha_index:
        return None

    num_ltrs = len(sorted_alpha_index)
    num_of_cols = 26
    num_of_rows = ((num_ltrs // num_of_cols) + 1)

    # begin alphabet navigation division
    with Html("div", id="alphanav") as alphabetnavigation:

        index = 0
        for dummy_row in range(num_of_rows):
            unordered = Html("ul")

            cols = 0
            while cols <= num_of_cols and index < num_ltrs:
                menu_item = sorted_alpha_index[index]
                if menu_item == ' ':
                    menu_item = '&nbsp;'
                # adding title to hyperlink menu for screen readers and
                # braille writers
                title_txt = "Alphabet Menu: %s" % menu_item
                title_str = rlocale.translation.sgettext(title_txt)
                hyper = Html("a",
                             menu_item,
                             title=title_str,
                             href="#%s" % menu_item)
                unordered.extend(Html("li", hyper, inline=True))

                index += 1
                cols += 1
            num_of_rows -= 1

            alphabetnavigation += unordered

    return alphabetnavigation
Exemple #6
0
def styled_note(styledtext, format, contains_html=False):
    """Return the note in HTML format.

    Adapted from DynamicWeb.
    """
    _backend = HtmlBackend()

    text = str(styledtext)

    if (not text): return ('')

    s_tags = styledtext.get_tags()
    htmllist = Html("div", class_="grampsstylednote")
    if contains_html:
        markuptext = _backend.add_markup_from_styled(text,
                                                     s_tags,
                                                     split='\n',
                                                     escape=False)
        htmllist += markuptext
    else:
        markuptext = _backend.add_markup_from_styled(text, s_tags, split='\n')
        linelist = []
        linenb = 1
        sigcount = 0
        for line in markuptext.split('\n'):
            [line, sigcount] = process_spaces(line, format)
            if sigcount == 0:
                # The rendering of an empty paragraph '<p></p>'
                # is undefined so we use a non-breaking space
                if linenb == 1:
                    linelist.append('&nbsp;')
                htmllist.extend(Html('p') + linelist)
                linelist = []
                linenb = 1
            else:
                if linenb > 1:
                    linelist[-1] += '<br />'
                linelist.append(line)
                linenb += 1
        if linenb > 1:
            htmllist.extend(Html('p') + linelist)
        # if the last line was blank, then as well as outputting the previous para,
        # which we have just done,
        # we also output a new blank para
        if sigcount == 0:
            linelist = ["&nbsp;"]
            htmllist.extend(Html('p') + linelist)
    return '\n'.join(htmllist)
Exemple #7
0
    def surname_link(self, fname, name, opt_val=None, uplink=False):
        """
        Create a link to the surname page.

        @param: fname   -- Path to the file name
        @param: name    -- Name to see in the link
        @param: opt_val -- Option value to use
        @param: uplink  -- If True, then "../../../" is inserted in front of
                           the result.
        """
        url = self.report.build_url_fname_html(fname, "srn", uplink)
        try:  # some characters don't have a unicode name
            char = uniname(name[0])
        except (ValueError, TypeError) as dummy_err:
            char = " "
        hyper = Html("a",
                     html_escape(name),
                     href=url,
                     title="%s starting with %s" % (name, char),
                     inline=True)
        if opt_val is not None:
            hyper += opt_val

        # return hyperlink to its caller
        return hyper
Exemple #8
0
    def __init__(self, report, langs):
        """
        Create an index for multi language.
        We will be redirected to the good page depending of the browser
        language. If the browser language is unknown, we use the first
        defined in the display tab of the narrative web configuration.

        @param: report -- The instance of the main report class
                          for this report
        @param: langs  -- The languages to process
        """
        BasePage.__init__(self, report, None, "index")
        output_file, sio = report.create_file("index", ext="index")
        page, head, body = Html.page('index', self.report.encoding,
                                     langs[0][0])
        body.attr = ' onload="lang();"'
        my_langs = "["
        for lang in langs:
            my_langs += "'" + lang[0].replace('_', '-')
            my_langs += "', "
        my_langs += "]"
        with Html("script", type="text/javascript") as jsc:
            head += jsc
            jsc += REDIRECT % (my_langs, self.ext)

        # send page out for processing
        # and close the file
        self.xhtml_writer(page, output_file, sio, 0)
        self.report.close_file(output_file, sio, 0)
Exemple #9
0
 def media_nav_link(self, handle, name, uplink=False):
     """
     Creates the Media Page Navigation hyperlinks for Next and Prev
     """
     url = self.report.build_url_fname_html(handle, "img", uplink)
     name = html_escape(name)
     return Html("a", name, name=name, id=name, href=url,
                 title=name, inline=True)
Exemple #10
0
    def add_media(self,
                  name,
                  pos,
                  w_cm,
                  h_cm,
                  alt='',
                  style_name=None,
                  crop=None):
        """
        Overwrite base method
        """
        self._empty = 0
        size = int(max(w_cm, h_cm) * float(150.0 / 2.54))
        refname = "is%s" % os.path.basename(name)

        imdir = self._backend.datadirfull()

        try:
            resize_to_jpeg(name,
                           imdir + os.sep + refname,
                           size,
                           size,
                           crop=crop)
        except:
            LOG.warn(
                _("Could not create jpeg version of image %(name)s") %
                {'name': name})
            return

        if len(alt):
            alt = '<br />'.join(alt)

        if pos not in ["right", "left"]:
            if len(alt):
                self.htmllist[-1] += Html('div') + (Html(
                    'img', src=imdir + os.sep + refname, border='0',
                    alt=alt), Html('p', class_="DDR-Caption") + alt)
            else:
                self.htmllist[-1] += Html('img',
                                          src=imdir + os.sep + refname,
                                          border='0',
                                          alt=alt)
        else:
            if len(alt):
                self.htmllist[-1] += Html(
                    'div', style_="float: %s; padding: 5px; margin: 0;" % pos
                ) + (Html(
                    'img', src=imdir + os.sep + refname, border='0',
                    alt=alt), Html('p', class_="DDR-Caption") + alt)
            else:
                self.htmllist[-1] += Html('img',
                                          src=imdir + os.sep + refname,
                                          border='0',
                                          alt=alt,
                                          align=pos)
Exemple #11
0
    def thumb_hyper_image(self, thumbnail_url, subdir, fname, name):
        """
        eplaces media_link() because it doesn't work for this instance
        """
        name = html_escape(name)
        url = "/".join(self.report.build_subdirs(subdir, fname) +
                       [fname]) + self.ext

        with Html("div", class_="thumbnail") as thumbnail:
            #snapshot += thumbnail

            if not self.create_thumbs_only:
                thumbnail_link = Html("a", href=url, title=name) + (Html(
                    "img", src=thumbnail_url, alt=name))
            else:
                thumbnail_link = Html("img", src=thumbnail_url, alt=name)
            thumbnail += thumbnail_link
        return thumbnail
Exemple #12
0
    def thumbnail_link(self, name, index):
        """
        creates a hyperlink for Thumbnail Preview Reference...

        @param: name    -- The image description
        @param: index   -- The image index
        """
        return Html("a", index, title=html_escape(name),
                    href="#%d" % index)
Exemple #13
0
 def start_table(self, name, style):
     """
     Overwrite base method
     """
     self.first_row = True
     styles = self.get_style_sheet()
     self._tbl = styles.get_table_style(style)
     self.htmllist += [Html('table', width=str(self._tbl.get_width())+'%',
                             cellspacing='0')]
Exemple #14
0
 def start_cell(self, style_name, span=1):
     """
     Overwrite base method
     """
     if self.use_table_headers and self.first_row:
         tag = "th"
     else:
         tag = "td"
     self._empty = 1
     if span > 1:
         self.htmllist += (Html(tag, colspan=str(span), class_=style_name),)
         self._col += span
     else:
         self.htmllist += (Html(tag, colspan=str(span),
                                width=str(self._tbl.get_column_width(
                                    self._col))+ '%',
                                class_=style_name),)
     self._col += 1
Exemple #15
0
    def family_map_link_for_parent(self, handle, name):
        """
        Creates a link to the family map for the father or the mother

        @param: handle -- The person handle
        @param: name   -- The name for this person to display
        """
        url = self.report.fam_link[handle]
        title = self._("Family Map for %s") % name
        return Html("a", title, href=url,
                    title=title, class_="family_map", inline=True)
Exemple #16
0
    def open(self, filename):
        """
        Overwrite base method
        """
        self._backend = HtmlBackend(filename)
        self._backend.open()
        self.htmllist += [self._backend.html_body]
        #start a gramps report
        self.htmllist += [Html('div', id="grampstextdoc")]

        self.build_header()
Exemple #17
0
 def start_paragraph(self, style_name, leader=None):
     """
     Overwrite base method
     """
     style_sheet = self.get_style_sheet()
     style = style_sheet.get_paragraph_style(style_name)
     level = style.get_header_level()
     if level == 0:
         #a normal paragraph
         self.htmllist += (Html('p', class_=style_name, inline=True), )
     elif level == 1:
         if self.__title_written == -1 and \
                 style_name.upper().find('TITLE') != -1:
             self.__title_written = 0
             self.htmllist += (Html('div', id="header"), )
             self.htmllist += (Html('h1',
                                    class_=style_name,
                                    id='SiteTitle',
                                    inline=True), )
         else:
             self.htmllist += (Html('h1', class_=style_name, inline=True), )
     elif 2 <= level <= 5:
         tag = 'h' + str(level + 1)
         self.htmllist += (Html(tag, class_=style_name, inline=True), )
     else:
         # a low level header
         self.htmllist += (Html('div',
                                id='grampsheading',
                                class_=style_name), )
     if leader is not None:
         self.write_text(leader + ' ')
Exemple #18
0
    def event_grampsid_link(self, handle, grampsid, uplink):
        """
        Create a hyperlink from event handle, but show grampsid

        @param: handle   -- The handle for the event
        @param: grampsid -- The gramps ID to display
        @param: uplink   -- If True, then "../../../" is inserted in front of
                            the result.
        """
        url = self.report.build_url_fname_html(handle, "evt", uplink)

        # return hyperlink to its caller
        return Html("a", grampsid, href=url, title=grampsid, inline=True)
Exemple #19
0
    def media_nav_link(self, handle, name, uplink=False):
        """
        Creates the Media Page Navigation hyperlinks for Next and Prev

        @param: handle -- The media handle
        @param: name   -- The name to use for the link
        @param: uplink -- If True, then "../../../" is inserted in front of the
                          result.
        """
        url = self.report.build_url_fname_html(handle, "img", uplink)
        name = html_escape(name)
        return Html("a", name, name=name, id=name, href=url,
                    title=name, inline=True)
Exemple #20
0
 def __output_place(self, ldatec, tbody, first_place, pname, place_handle,
                    letter, bucket_link):
     place = self.r_db.get_place_from_handle(place_handle)
     if place:
         if place.get_change_time() > ldatec:
             ldatec = place.get_change_time()
         plc_title = pname
         main_location = get_main_location(self.r_db, place)
         if not plc_title or plc_title == " ":
             letter = "&nbsp;"
         trow = Html("tr")
         tbody += trow
         tcell = Html("td", class_="ColumnLetter", inline=True)
         trow += tcell
         if first_place:
             # or primary_difference(letter, prev_letter, self.rlocale):
             first_place = False
             # prev_letter = letter
             trow.attr = 'class = "BeginLetter"'
             ttle = self._("Places beginning " "with letter %s") % letter
             tcell += Html("a",
                           letter,
                           name=letter,
                           title=ttle,
                           id_=bucket_link)
         else:
             tcell += "&nbsp;"
         trow += Html("td",
                      self.place_link(place.get_handle(), plc_title,
                                      place.get_gramps_id()),
                      class_="ColumnName")
         trow.extend(
             Html("td", data or "&nbsp;", class_=colclass, inline=True)
             for (colclass, data) in [[
                 "ColumnState",
                 main_location.get(PlaceType.STATE, '')
             ], ["ColumnCountry",
                 main_location.get(PlaceType.COUNTRY, '')]])
         if self.display_coordinates:
             tcell1 = Html("td", class_="ColumnLatitude", inline=True)
             tcell2 = Html("td", class_="ColumnLongitude", inline=True)
             trow += tcell1, tcell2
             if place.lat and place.long:
                 latitude, longitude = conv_lat_lon(place.lat, place.long,
                                                    "DEG")
                 tcell1 += latitude
                 tcell2 += longitude
             else:
                 tcell1 += '&nbsp;'
                 tcell2 += '&nbsp;'
     return (ldatec, first_place)
Exemple #21
0
    def thumb_hyper_image(self, thumbnail_url, subdir, fname, name):
        """
        replaces media_link() because it doesn't work for this instance

        @param: thumnail_url -- The url for this thumbnail
        @param: subdir       -- The subdir prefix to add
        @param: fname        -- The file name for this image
        @param: name         -- The image description
        """
        name = html_escape(name)
        url = "/".join(self.report.build_subdirs(subdir,
                                                 fname) + [fname]) + self.ext
        with Html("div", class_="thumbnail") as thumbnail:
                    #snapshot += thumbnail

            if not self.create_thumbs_only:
                thumbnail_link = Html("a", href=url, title=name) + (
                    Html("img", src=thumbnail_url, alt=name)
                )
            else:
                thumbnail_link = Html("img", src=thumbnail_url,
                                      alt=name)
            thumbnail += thumbnail_link
        return thumbnail
Exemple #22
0
    def surname_link(self, fname, name, opt_val=None, uplink=False):
        """
        Create a link to the surname page.

        @param: fname   -- Path to the file name
        @param: name    -- Name to see in the link
        @param: opt_val -- Option value to use
        @param: uplink  -- If True, then "../../../" is inserted in front of
                           the result.
        """
        url = self.report.build_url_fname_html(fname, "srn", uplink)
        hyper = Html("a", html_escape(name), href=url, title=name, inline=True)
        if opt_val is not None:
            hyper += opt_val

        # return hyperlink to its caller
        return hyper
Exemple #23
0
    def __init__(self, report, the_lang, the_title):
        """
        @param: report    -- The instance of the main report class for
                             this report
        @param: the_lang  -- The lang to process
        @param: the_title -- The title page related to the language
        """
        BasePage.__init__(self, report, the_lang, the_title)
        ldatec = 0

        output_file, sio = self.report.create_file(report.intro_fname)
        result = self.write_header(self._('Introduction'))
        intropage, head, dummy_body, outerwrapper = result

        # begin Introduction division
        with Html("div", class_="content", id="Introduction") as section:
            outerwrapper += section

            introimg = self.add_image('introimg', head)
            if introimg is not None:
                section += introimg

            note_id = report.options['intronote']
            ldatec = None
            if note_id:
                note = self.r_db.get_note_from_gramps_id(note_id)
                if note:
                    note_text = self.get_note_format(note, False)

                    # attach note
                    section += note_text

                    # last modification of this note
                    ldatec = note.get_change_time()

        # add clearline for proper styling
        # create footer section
        footer = self.write_footer(ldatec)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(intropage, output_file, sio, ldatec)
Exemple #24
0
    def __init__(self, report, title):
        """
        @param: report -- The instance of the main report class for
                          this report
        @param: title  -- Is the title of the web page
        """
        BasePage.__init__(self, report, title)
        ldatec = 0

        output_file, sio = self.report.create_file("index")
        result = self.write_header(self._('Home'))
        homepage, head, dummy_body, outerwrapper = result

        # begin home division
        with Html("div", class_="content", id="Home") as section:
            outerwrapper += section

            homeimg = self.add_image('homeimg', head)
            if homeimg is not None:
                section += homeimg

            note_id = report.options['homenote']
            ldatec = None
            if note_id:
                note = self.r_db.get_note_from_gramps_id(note_id)
                if note:
                    note_text = self.get_note_format(note, False)

                    # attach note
                    section += note_text

                    # last modification of this note
                    ldatec = note.get_change_time()

        # create clear line for proper styling
        # create footer section
        footer = self.write_footer(ldatec)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(homepage, output_file, sio, ldatec)
Exemple #25
0
    def media_ref_link(self, handle, name, uplink=False):
        """
        Create a reference link to a media

        @param: handle -- The media handle
        @param: name   -- The name to use for the link
        @param: uplink -- If True, then "../../../" is inserted in front of the
                          result.
        """
        # get media url
        url = self.report.build_url_fname_html(handle, "img", uplink)

        # get name
        name = html_escape(name)

        # begin hyper link
        hyper = Html("a", name, href=url, title=name)

        # return hyperlink to its callers
        return hyper
Exemple #26
0
    def __init__(self, report, the_lang, the_title, step):
        """
        @param: report        -- The instance of the main report class
                                 for this report
        @param: the_lang      -- The lang to process
        @param: the_title     -- The title page related to the language
        @param: step          -- Use to continue the progess bar
        """
        import os
        BasePage.__init__(self, report, the_lang, the_title)
        self.bibli = Bibliography()
        self.uplink = False
        self.report = report
        # set the file name and open file
        output_file, sio = self.report.create_file("statistics")
        result = self.write_header(_("Statistics"))
        addressbookpage, dummy_head, dummy_body, outerwrapper = result
        (males,
         females,
         unknown) = self.get_gender(report.database.iter_person_handles())

        step()
        mobjects = report.database.get_number_of_media()
        npersons = report.database.get_number_of_people()
        nfamilies = report.database.get_number_of_families()
        nsurnames = len(set(report.database.surname_list))
        notfound = []
        total_media = 0
        mbytes = "0"
        chars = 0
        for media in report.database.iter_media():
            total_media += 1
            fullname = media_path_full(report.database, media.get_path())
            try:
                chars += os.path.getsize(fullname)
                length = len(str(chars))
                if chars <= 999999:
                    mbytes = self._("less than 1")
                else:
                    mbytes = str(chars)[:(length-6)]
            except OSError:
                notfound.append(media.get_path())


        with Html("div", class_="content", id='EventDetail') as section:
            section += Html("h3", self._("Database overview"), inline=True)
        outerwrapper += section
        with Html("div", class_="content", id='subsection narrative') as sec11:
            sec11 += Html("h4", self._("Individuals"), inline=True)
        outerwrapper += sec11
        with Html("div", class_="content", id='subsection narrative') as sec1:
            sec1 += Html("br", self._("Number of individuals") + self.colon +
                         "%d" % npersons, inline=True)
            sec1 += Html("br", self._("Males") + self.colon +
                         "%d" % males, inline=True)
            sec1 += Html("br", self._("Females") + self.colon +
                         "%d" % females, inline=True)
            sec1 += Html("br", self._("Individuals with unknown gender") +
                         self.colon + "%d" % unknown, inline=True)
        outerwrapper += sec1
        with Html("div", class_="content", id='subsection narrative') as sec2:
            sec2 += Html("h4", self._("Family Information"), inline=True)
            sec2 += Html("br", self._("Number of families") + self.colon +
                         "%d" % nfamilies, inline=True)
            sec2 += Html("br", self._("Unique surnames") + self.colon +
                         "%d" % nsurnames, inline=True)
        outerwrapper += sec2
        with Html("div", class_="content", id='subsection narrative') as sec3:
            sec3 += Html("h4", self._("Media Objects"), inline=True)
            sec3 += Html("br",
                         self._("Total number of media object references") +
                         self.colon + "%d" % total_media, inline=True)
            sec3 += Html("br", self._("Number of unique media objects") +
                         self.colon + "%d" % mobjects, inline=True)
            sec3 += Html("br", self._("Total size of media objects") +
                         self.colon +
                         "%8s %s" % (mbytes, self._("MB", "Megabyte")),
                         inline=True)
            sec3 += Html("br", self._("Missing Media Objects") +
                         self.colon + "%d" % len(notfound), inline=True)
        outerwrapper += sec3
        with Html("div", class_="content", id='subsection narrative') as sec4:
            sec4 += Html("h4", self._("Miscellaneous"), inline=True)
            sec4 += Html("br", self._("Number of events") + self.colon +
                         "%d" % report.database.get_number_of_events(),
                         inline=True)
            sec4 += Html("br", self._("Number of places") + self.colon +
                         "%d" % report.database.get_number_of_places(),
                         inline=True)
            nsources = report.database.get_number_of_sources()
            sec4 += Html("br", self._("Number of sources") +
                         self.colon + "%d" % nsources,
                         inline=True)
            ncitations = report.database.get_number_of_citations()
            sec4 += Html("br", self._("Number of citations") +
                         self.colon + "%d" % ncitations,
                         inline=True)
            nrepo = report.database.get_number_of_repositories()
            sec4 += Html("br", self._("Number of repositories") +
                         self.colon + "%d" % nrepo,
                         inline=True)
        outerwrapper += sec4

        (males,
         females,
         unknown) = self.get_gender(self.report.bkref_dict[Person].keys())

        origin = " :<br/>" + report.filter.get_name(self.rlocale)
        with Html("div", class_="content", id='EventDetail') as section:
            section += Html("h3",
                            self._("Narrative web content report for") + origin,
                            inline=True)
        outerwrapper += section
        with Html("div", class_="content", id='subsection narrative') as sec5:
            sec5 += Html("h4", self._("Individuals"), inline=True)
            sec5 += Html("br", self._("Number of individuals") + self.colon +
                         "%d" % len(self.report.bkref_dict[Person]),
                         inline=True)
            sec5 += Html("br", self._("Males") + self.colon +
                         "%d" % males, inline=True)
            sec5 += Html("br", self._("Females") + self.colon +
                         "%d" % females, inline=True)
            sec5 += Html("br", self._("Individuals with unknown gender") +
                         self.colon + "%d" % unknown, inline=True)
        outerwrapper += sec5
        with Html("div", class_="content", id='subsection narrative') as sec6:
            sec6 += Html("h4", self._("Family Information"), inline=True)
            sec6 += Html("br", self._("Number of families") + self.colon +
                         "%d" % len(self.report.bkref_dict[Family]),
                         inline=True)
        outerwrapper += sec6
        with Html("div", class_="content", id='subsection narrative') as sec7:
            sec7 += Html("h4", self._("Miscellaneous"), inline=True)
            sec7 += Html("br", self._("Number of events") + self.colon +
                         "%d" % len(self.report.bkref_dict[Event]),
                         inline=True)
            sec7 += Html("br", self._("Number of places") + self.colon +
                         "%d" % len(self.report.bkref_dict[Place]),
                         inline=True)
            sec7 += Html("br", self._("Number of sources") + self.colon +
                         "%d" % len(self.report.bkref_dict[Source]),
                         inline=True)
            sec7 += Html("br", self._("Number of citations") + self.colon +
                         "%d" % len(self.report.bkref_dict[Citation]),
                         inline=True)
            sec7 += Html("br", self._("Number of repositories") + self.colon +
                         "%d" % len(self.report.bkref_dict[Repository]),
                         inline=True)
        outerwrapper += sec7

        # add fullclear for proper styling
        # and footer section to page
        footer = self.write_footer(None)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(addressbookpage, output_file, sio, 0)
Exemple #27
0
    def __init__(self, report, title):
        """
        @param: report -- The instance of the main report class for this report
        @param: title  -- Is the title of the web page
        """
        BasePage.__init__(self, report, title)

        # do NOT include a Download Page
        if not self.report.inc_download:
            return

        # menu options for class
        # download and description #1

        dlfname1 = self.report.dl_fname1
        dldescr1 = self.report.dl_descr1

        # download and description #2
        dlfname2 = self.report.dl_fname2
        dldescr2 = self.report.dl_descr2

        # if no filenames at all, return???
        if dlfname1 or dlfname2:

            output_file, sio = self.report.create_file("download")
            downloadpage, head, body = self.write_header(self._('Download'))

            # begin download page and table
            with Html("div", class_="content", id="Download") as download:
                body += download

                msg = self._("This page is for the user/ creator "
                             "of this Family Tree/ Narrative website "
                             "to share a couple of files with you "
                             "regarding their family.  If there are "
                             "any files listed "
                             "below, clicking on them will allow you "
                             "to download them. The "
                             "download page and files have the same "
                             "copyright as the remainder "
                             "of these web pages.")
                download += Html("p", msg, id="description")

                # begin download table and table head
                with Html("table", class_="infolist download") as table:
                    download += table

                    thead = Html("thead")
                    table += thead

                    trow = Html("tr")
                    thead += trow

                    trow.extend(
                        Html("th",
                             label,
                             class_="Column" + colclass,
                             inline=True)
                        for (label, colclass) in [(
                            self._("File Name"),
                            "Filename"), (self._("Description"),
                                          "Description"),
                                                  (self._("Last Modified"),
                                                   "Modified")])
                    # table body
                    tbody = Html("tbody")
                    table += tbody

                    # if dlfname1 is not None, show it???
                    if dlfname1:

                        trow = Html("tr", id='Row01')
                        tbody += trow

                        fname = os.path.basename(dlfname1)
                        # TODO dlfname1 is filename, convert disk path to URL
                        tcell = Html("td", class_="ColumnFilename") + (Html(
                            "a",
                            fname,
                            href=dlfname1,
                            title=html_escape(dldescr1)))
                        trow += tcell

                        dldescr1 = dldescr1 or "&nbsp;"
                        trow += Html("td",
                                     dldescr1,
                                     class_="ColumnDescription",
                                     inline=True)

                        tcell = Html("td",
                                     class_="ColumnModified",
                                     inline=True)
                        trow += tcell
                        if os.path.exists(dlfname1):
                            modified = os.stat(dlfname1).st_mtime
                            last_mod = datetime.datetime.fromtimestamp(
                                modified)
                            tcell += last_mod
                        else:
                            tcell += "&nbsp;"

                    # if download filename #2, show it???
                    if dlfname2:

                        # begin row #2
                        trow = Html("tr", id='Row02')
                        tbody += trow

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

                        dldescr2 = dldescr2 or "&nbsp;"
                        trow += Html("td",
                                     dldescr2,
                                     class_="ColumnDescription",
                                     inline=True)

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

            # clear line for proper styling
            # create footer section
            footer = self.write_footer(None)
            body += (FULLCLEAR, footer)

            # send page out for processing
            # and close the file
            self.xhtml_writer(downloadpage, output_file, sio, 0)
Exemple #28
0
    def sourcelistpage(self, report, the_lang, the_title, source_handles):
        """
        Generate and output the Sources index page.

        @param: report         -- The instance of the main report class for
                                  this report
        @param: the_lang       -- The lang to process
        @param: the_title      -- The title page related to the language
        @param: source_handles -- A list of the handles of the sources to be
                                  displayed
        """
        BasePage.__init__(self, report, the_lang, the_title)

        source_dict = {}

        output_file, sio = self.report.create_file("sources")
        result = self.write_header(self._("Sources"))
        sourcelistpage, dummy_head, dummy_body, outerwrapper = result

        # begin source list division
        with Html("div", class_="content", id="Sources") as sourceslist:
            outerwrapper += sourceslist

            # Sort the sources
            for handle in source_handles:
                source = self.r_db.get_source_from_handle(handle)
                if source is not None:
                    key = source.get_title() + source.get_author()
                    key += str(source.get_gramps_id())
                    source_dict[key] = (source, handle)

            keys = sorted(source_dict, key=self.rlocale.sort_key)

            msg = self._("This page contains an index of all the sources "
                         "in the database, sorted by their title. "
                         "Clicking on a source&#8217;s "
                         "title will take you to that source&#8217;s page.")
            sourceslist += Html("p", msg, id="description")

            # begin sourcelist table and table head
            with Html("table",
                      class_="infolist primobjlist sourcelist") as table:
                sourceslist += table
                thead = Html("thead")
                table += thead

                trow = Html("tr")
                thead += trow

                header_row = [
                    (self._("Number"), "ColumnRowLabel"),
                    (self._("Author"), "ColumnAuthor"),
                    (self._("Name", "Source Name"), "ColumnName")]

                trow.extend(
                    Html("th", label or "&nbsp;", class_=colclass, inline=True)
                    for (label, colclass) in header_row
                )

                # begin table body
                tbody = Html("tbody")
                table += tbody

                for index, key in enumerate(keys):
                    source, source_handle = source_dict[key]

                    trow = Html("tr") + (
                        Html("td", index + 1, class_="ColumnRowLabel",
                             inline=True)
                    )
                    tbody += trow
                    trow.extend(
                        Html("td", source.get_author(), class_="ColumnAuthor",
                             inline=True)
                    )
                    trow.extend(
                        Html("td", self.source_link(source_handle,
                                                    source.get_title(),
                                                    source.get_gramps_id()),
                             class_="ColumnName")
                    )

        # add clearline for proper styling
        # add footer section
        footer = self.write_footer(None)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(sourcelistpage, output_file, sio, 0)
Exemple #29
0
    def sourcepage(self, report, the_lang, the_title, source_handle):
        """
        Generate and output an individual Source page.

        @param: report        -- The instance of the main report class
                                 for this report
        @param: the_lang      -- The lang to process
        @param: the_title     -- The title page related to the language
        @param: source_handle -- The handle of the source to be output
        """
        source = report.database.get_source_from_handle(source_handle)
        BasePage.__init__(self, report, the_lang, the_title,
                          source.get_gramps_id())
        if not source:
            return

        self.page_title = source.get_title()

        inc_repositories = self.report.options["inc_repository"]
        self.navigation = self.report.options['navigation']
        self.citationreferents = self.report.options['citationreferents']

        output_file, sio = self.report.create_file(source_handle, "src")
        self.uplink = True
        result = self.write_header("%s - %s" % (self._('Sources'),
                                                self.page_title))
        sourcepage, dummy_head, dummy_body, outerwrapper = result

        ldatec = 0
        # begin source detail division
        with Html("div", class_="content", id="SourceDetail") as sourcedetail:
            outerwrapper += sourcedetail

            media_list = source.get_media_list()
            if self.create_media and media_list:
                thumbnail = self.disp_first_img_as_thumbnail(media_list,
                                                             source)
                if thumbnail is not None:
                    sourcedetail += thumbnail

            # add section title
            sourcedetail += Html("h3", html_escape(source.get_title()),
                                 inline=True)

            # begin sources table
            with Html("table", class_="infolist source") as table:
                sourcedetail += table

                tbody = Html("tbody")
                table += tbody

                source_gid = False
                if not self.noid and self.gid:
                    source_gid = source.get_gramps_id()

                    # last modification of this source
                    ldatec = source.get_change_time()

                for (label, value) in [(self._("Gramps ID"), source_gid),
                                       (self._("Author"), source.get_author()),
                                       (self._("Abbreviation"),
                                        source.get_abbreviation()),
                                       (self._("Publication information"),
                                        source.get_publication_info())]:
                    if value:
                        trow = Html("tr") + (
                            Html("td", label, class_="ColumnAttribute",
                                 inline=True),
                            Html("td", value, class_="ColumnValue", inline=True)
                        )
                        tbody += trow

            # Tags
            tags = self.show_tags(source)
            if tags and self.report.inc_tags:
                trow = Html("tr") + (
                    Html("td", self._("Tags"),
                         class_="ColumnAttribute", inline=True),
                    Html("td", tags,
                         class_="ColumnValue", inline=True)
                    )
                tbody += trow

            # Source notes
            notelist = self.display_note_list(source.get_note_list(), Source)
            if notelist is not None:
                sourcedetail += notelist

            # additional media from Source (if any?)
            if self.create_media and media_list:
                sourcemedia = self.disp_add_img_as_gallery(media_list, source)
                if sourcemedia is not None:
                    sourcedetail += sourcemedia

            # Source Data Map...
            src_data_map = self.write_srcattr(source.get_attribute_list())
            if src_data_map is not None:
                sourcedetail += src_data_map

            # Source Repository list
            if inc_repositories:
                repo_list = self.dump_repository_ref_list(
                    source.get_reporef_list())
                if repo_list is not None:
                    sourcedetail += repo_list

            # Source references list
            ref_list = self.display_bkref_list(Source, source_handle)
            if ref_list is not None:
                sourcedetail += ref_list

        # add clearline for proper styling
        # add footer section
        footer = self.write_footer(ldatec)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(sourcepage, output_file, sio, ldatec)
Exemple #30
0
    def placepage(self, report, title, place_handle):
        """
        Create a place page

        @param: report            -- The instance of the main report class for
                                     this report
        @param: title             -- Is the title of the web page
        @param: place_handle -- The handle for the place to add
        """
        place = report.database.get_place_from_handle(place_handle)
        if not place:
            return
        BasePage.__init__(self, report, title, place.get_gramps_id())
        self.bibli = Bibliography()
        place_name = self.report.obj_dict[Place][place_handle][1]
        ldatec = place.get_change_time()

        output_file, sio = self.report.create_file(place_handle, "plc")
        self.uplink = True
        self.page_title = place_name
        placepage, head, body, outerwrapper = self.write_header(_("Places"))

        self.placemappages = self.report.options['placemappages']
        self.mapservice = self.report.options['mapservice']
        self.googlemapkey = self.report.options['googlemapkey']

        # begin PlaceDetail Division
        with Html("div", class_="content", id="PlaceDetail") as placedetail:
            outerwrapper += placedetail

            if self.create_media:
                media_list = place.get_media_list()
                thumbnail = self.disp_first_img_as_thumbnail(media_list, place)
                if thumbnail is not None:
                    placedetail += thumbnail

            # add section title
            placedetail += Html("h3", html_escape(place_name), inline=True)

            # begin summaryarea division and places table
            with Html("div", id='summaryarea') as summaryarea:
                placedetail += summaryarea

                with Html("table", class_="infolist place") as table:
                    summaryarea += table

                    # list the place fields
                    self.dump_place(place, table)

            # place gallery
            if self.create_media:
                placegallery = self.disp_add_img_as_gallery(media_list, place)
                if placegallery is not None:
                    placedetail += placegallery

            # place notes
            notelist = self.display_note_list(place.get_note_list())
            if notelist is not None:
                placedetail += notelist

            # place urls
            urllinks = self.display_url_list(place.get_url_list())
            if urllinks is not None:
                placedetail += urllinks

            # add place map here
            # Link to Gramps marker
            fname = "/".join(['images', 'marker.png'])
            marker_path = self.report.build_url_image("marker.png", "images",
                                                      self.uplink)

            if self.placemappages:
                if place and (place.lat and place.long):
                    latitude, longitude = conv_lat_lon(place.get_latitude(),
                                                       place.get_longitude(),
                                                       "D.D8")
                    placetitle = place_name

                    # add narrative-maps CSS...
                    fname = "/".join(["css", "narrative-maps.css"])
                    url = self.report.build_url_fname(fname, None, self.uplink)
                    head += Html("link",
                                 href=url,
                                 type="text/css",
                                 media="screen",
                                 rel="stylesheet")

                    # add MapService specific javascript code
                    src_js = GOOGLE_MAPS + "api/js?sensor=false"
                    if self.mapservice == "Google":
                        if self.googlemapkey:
                            src_js += "&key=" + self.googlemapkey
                        head += Html("script",
                                     type="text/javascript",
                                     src=src_js,
                                     inline=True)
                    else:
                        url = self.secure_mode
                        url += ("maxcdn.bootstrapcdn.com/bootstrap/3.3.7/"
                                "css/bootstrap.min.css")
                        head += Html("link",
                                     href=url,
                                     type="text/javascript",
                                     rel="stylesheet")
                        src_js = self.secure_mode
                        src_js += (
                            "ajax.googleapis.com/ajax/libs/jquery/1.9.1/"
                            "jquery.min.js")
                        head += Html("script",
                                     type="text/javascript",
                                     src=src_js,
                                     inline=True)
                        src_js = self.secure_mode
                        src_js += "openlayers.org/en/latest/build/ol.js"
                        head += Html("script",
                                     type="text/javascript",
                                     src=src_js,
                                     inline=True)
                        url = self.secure_mode
                        url += "openlayers.org/en/latest/css/ol.css"
                        head += Html("link",
                                     href=url,
                                     type="text/javascript",
                                     rel="stylesheet")
                        src_js = self.secure_mode
                        src_js += ("maxcdn.bootstrapcdn.com/bootstrap/3.3.7/"
                                   "js/bootstrap.min.js")
                        head += Html("script",
                                     type="text/javascript",
                                     src=src_js,
                                     inline=True)

                    # section title
                    placedetail += Html("h4", self._("Place Map"), inline=True)

                    # begin map_canvas division
                    with Html("div", id="map_canvas", inline=True) as canvas:
                        placedetail += canvas

                        # Begin inline javascript code because jsc is a
                        # docstring, it does NOT have to be properly indented
                        if self.mapservice == "Google":
                            with Html("script",
                                      type="text/javascript",
                                      indent=False) as jsc:
                                head += jsc

                                # Google adds Latitude/ Longitude to its maps...
                                plce = placetitle.replace("'", "\\'")
                                jsc += MARKER_PATH % marker_path
                                jsc += MARKERS % ([[
                                    plce, latitude, longitude, 1
                                ]], latitude, longitude, 10)

                        else:
                            # OpenStreetMap (OSM) adds Longitude/ Latitude
                            # to its maps, and needs a country code in
                            # lowercase letters...
                            with Html("script", type="text/javascript") as jsc:
                                canvas += jsc
                                #param1 = xml_lang()[3:5].lower()
                                jsc += MARKER_PATH % marker_path
                                jsc += OSM_MARKERS % ([[
                                    float(longitude),
                                    float(latitude), placetitle
                                ]], longitude, latitude, 10)

            # add javascript function call to body element
            body.attr += ' onload = "initialize();" '

            # add div for popups.
            with Html("div", id="popup", inline=True) as popup:
                placedetail += popup

            # source references
            srcrefs = self.display_ind_sources(place)
            if srcrefs is not None:
                placedetail += srcrefs

            # References list
            ref_list = self.display_bkref_list(Place, place_handle)
            if ref_list is not None:
                placedetail += ref_list

        # add clearline for proper styling
        # add footer section
        footer = self.write_footer(ldatec)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(placepage, output_file, sio, ldatec)