Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 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)
Exemplo n.º 4
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
    """
    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 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
Exemplo n.º 5
0
    def PrintMedia(self, thumbs, mediapath):
        """
        Print some media infos via HTML class (Gramps)
        """

        LOG.info('Looking at media...')

        # Web page filename extensions

        _WEB_EXT = ['.html', '.htm', '.shtml', '.php', '.php3', '.cgi']

        # page title

        title = _('Gallery')

        fname = os.path.join(USER_PLUGINS, 'lxml', _('Gallery.html'))
        of = open(fname, "w")

        LOG.info('Empty "Gallery.hml" file created')

        # htmlinstance = page
        # ignored by current code...

        lang = xml_lang()
        page, head, body = Html.page(title, encoding='utf-8', lang=str(lang))
        head = body = ""

        self.text = []

        self.XHTMLWriter(fname, page, head, body, of, thumbs, mediapath)

        LOG.info('End (Media)')
Exemplo n.º 6
0
 def open(self):
     """
     overwrite method, htmlbackend creates a html object that is written on
     close
     """
     try:
         DocBackend.open(self)
     except IOError as msg:
         errmsg = "%s\n%s" % (_("Could not create %s") %
                              self._filename, msg)
         raise ReportError(errmsg)
     except:
         raise ReportError(_("Could not create %s") %
                                  self._filename)
     if not os.path.isdir(self.datadirfull()): 
         try:
             os.mkdir(self.datadirfull())
         except IOError as msg:
             errmsg = "%s\n%s" % (_("Could not create %s") %
                                  self.datadirfull(), msg)
             raise ReportError(errmsg)
         except:
             raise ReportError(_("Could not create %s") %
                                      self.datadirfull())
     self.html_page, self.html_header, self.html_body = Html.page(
                     lang=xml_lang(), title=self.title)
Exemplo n.º 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
Exemplo n.º 8
0
    def PrintMedia(self, thumbs, mediapath):
        """
        Print some media infos via HTML class (Gramps)
        """

        LOG.info('Looking at media...')

        # Web page filename extensions

        _WEB_EXT = ['.html', '.htm', '.shtml', '.php', '.php3', '.cgi']

        # page title

        title = _('Gallery')

        fname = os.path.join(USER_PLUGINS, 'lxml', _('Gallery.html'))
        of = open(fname, "w")

        LOG.info('Empty "Gallery.hml" file created')

        # htmlinstance = page
        # ignored by current code...

        lang = xml_lang()
        page, head, body = Html.page(title, encoding='utf-8', lang=str(lang))
        head = body = ""

        self.text = []

        self.XHTMLWriter(fname, page, head, body, of, thumbs, mediapath)

        LOG.info('End (Media)')
Exemplo n.º 9
0
    def PrintMedia(self, thumbs, mediapath):
        """
        Print some media infos via HTML class (Gramps)
        """

        LOG.info("Looking at media...")

        # Web page filename extensions

        _WEB_EXT = [".html", ".htm", ".shtml", ".php", ".php3", ".cgi"]

        # page title

        title = _("Gallery")

        fname = os.path.join(USER_PLUGINS, "lxml", _("Gallery.html"))
        of = open(fname, "w")

        LOG.info('Empty "Gallery.hml" file created')

        # htmlinstance = page
        # ignored by current code...

        lang = xml_lang()
        page, head, body = Html.page(title, encoding="utf-8", lang=str(lang))
        head = body = ""

        self.text = []

        self.XHTMLWriter(fname, page, head, body, of, thumbs, mediapath)

        LOG.info("End (Media)")
Exemplo n.º 10
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)
Exemplo n.º 11
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)
Exemplo n.º 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)
Exemplo n.º 13
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
Exemplo n.º 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
Exemplo n.º 15
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')]
Exemplo n.º 16
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)
Exemplo n.º 17
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()
Exemplo n.º 18
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
Exemplo n.º 19
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 + ' ')
Exemplo n.º 20
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)
Exemplo n.º 21
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)
Exemplo n.º 22
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
Exemplo n.º 23
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
Exemplo n.º 24
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
Exemplo n.º 25
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)
Exemplo n.º 26
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)
Exemplo n.º 27
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
Exemplo n.º 28
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)
Exemplo n.º 29
0
    def placelistpage(self, report, title, place_handles):
        """
        Create a place index

        @param: report        -- The instance of the main report class for
                                 this report
        @param: title         -- Is the title of the web page
        @param: place_handles -- The handle for the place to add
        """
        BasePage.__init__(self, report, title)

        output_file, sio = self.report.create_file("places")
        result = self.write_header(self._("Places"))
        placelistpage, dummy_head, dummy_body, outerwrapper = result
        ldatec = 0
        prev_letter = " "

        # begin places division
        with Html("div", class_="content", id="Places") as placelist:
            outerwrapper += placelist

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

            # begin alphabet navigation
            index_list = get_first_letters(self.r_db,
                                           place_handles,
                                           _KEYPLACE,
                                           rlocale=self.rlocale)
            alpha_nav = alphabet_navigation(index_list, self.rlocale)
            if alpha_nav is not None:
                placelist += alpha_nav

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

                # begin table head
                thead = Html("thead")
                table += thead

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

                if self.display_coordinates:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass
                             ) in [[self._("Letter"), "ColumnLetter"],
                                   [self._("Place Name | Name"), "ColumnName"],
                                   [self._("State/ Province"), "ColumnState"],
                                   [self._("Country"), "ColumnCountry"],
                                   [self._("Latitude"), "ColumnLatitude"],
                                   [self._("Longitude"), "ColumnLongitude"]])
                else:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass
                             ) in [[self._("Letter"), "ColumnLetter"],
                                   [self._("Place Name | Name"), "ColumnName"],
                                   [self._("State/ Province"), "ColumnState"],
                                   [self._("Country"), "ColumnCountry"]])

                # bug 9495 : incomplete display of place hierarchy labels
                def sort_by_place_name(obj):
                    """ sort by lower case place name. """
                    name = self.report.obj_dict[Place][obj][1]
                    return name.lower()

                handle_list = sorted(place_handles,
                                     key=lambda x: sort_by_place_name(x))
                first = True

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

                for place_handle in handle_list:
                    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 = self.report.obj_dict[Place][place_handle][
                            1]
                        main_location = get_main_location(self.r_db, place)

                        if plc_title and plc_title != " ":
                            letter = get_index_letter(first_letter(plc_title),
                                                      index_list, self.rlocale)
                        else:
                            letter = '&nbsp;'

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

                        tcell = Html("td", class_="ColumnLetter", inline=True)
                        trow += tcell
                        if first or primary_difference(letter, prev_letter,
                                                       self.rlocale):
                            first = False
                            prev_letter = letter
                            trow.attr = 'class = "BeginLetter"'

                            ttle = self._("Places beginning "
                                          "with letter %s") % letter
                            tcell += Html("a", letter, name=letter, title=ttle)
                        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;'

        # 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(placelistpage, output_file, sio, ldatec)
Exemplo n.º 30
0
    def medialistpage(self, report, title, sorted_media_handles):
        """
        Generate and output the Media index page.

        @param: report               -- The instance of the main report class
                                        for this report
        @param: title                -- Is the title of the web page
        @param: sorted_media_handles -- A list of the handles of the media to be
                                        displayed sorted by the media title
        """
        BasePage.__init__(self, report, title)

        output_file, sio = self.report.create_file("media")
        # save the media file name in case we create unused media pages
        self.cur_fname = self.report.cur_fname
        medialistpage, head, body = self.write_header(self._('Media'))

        ldatec = 0
        # begin gallery division
        with Html("div", class_="content", id="Gallery") as medialist:
            body += medialist

            msg = self._("This page contains an index of all the media objects "
                         "in the database, sorted by their title. Clicking on "
                         "the title will take you to that "
                         "media object&#8217;s page.  "
                         "If you see media size dimensions "
                         "above an image, click on the "
                         "image to see the full sized version.  ")
            medialist += Html("p", msg, id="description")

            # begin gallery table and table head
            with Html("table",
                      class_="infolist primobjlist gallerylist") as table:
                medialist += table

                # begin table head
                thead = Html("thead")
                table += thead

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

                trow.extend(
                    Html("th", trans, class_=colclass, inline=True)
                    for trans, colclass in [("&nbsp;", "ColumnRowLabel"),
                                            (self._("Media | Name"),
                                             "ColumnName"),
                                            (self._("Date"), "ColumnDate"),
                                            (self._("Mime Type"), "ColumnMime")]
                )

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

                index = 1
                if self.create_unused_media:
                    media_count = len(self.r_db.get_media_handles())
                else:
                    media_count = len(self.report.obj_dict[Media])
                message = _("Creating list of media pages")
                with self.r_user.progress(_("Narrated Web Site Report"),
                                          message, media_count + 1
                                 ) as step:
                    for media_handle in sorted_media_handles:
                        media = self.r_db.get_media_from_handle(media_handle)
                        if media:
                            if media.get_change_time() > ldatec:
                                ldatec = media.get_change_time()
                            title = media.get_description() or "[untitled]"

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

                            media_data_row = [
                                [index, "ColumnRowLabel"],
                                [self.media_ref_link(media_handle,
                                                     title), "ColumnName"],
                                [self.rlocale.get_date(media.get_date_object()),
                                 "ColumnDate"],
                                [media.get_mime_type(), "ColumnMime"]]

                            trow.extend(
                                Html("td", data, class_=colclass)
                                for data, colclass in media_data_row
                            )
                        step()
                        index += 1

                    def sort_by_desc_and_gid(obj):
                        """
                        Sort by media description and gramps ID
                        """
                        return (obj.desc, obj.gramps_id)

                    idx = 1
                    prev = None
                    total = len(self.unused_media_handles)
                    if total > 0:
                        trow += Html("tr")
                        trow.extend(
                            Html("td", Html("h4", " "), inline=True) +
                            Html("td",
                                 Html("h4",
                                      self._("Below unused media objects"),
                                      inline=True),
                                 class_="") +
                            Html("td", Html("h4", " "), inline=True) +
                            Html("td", Html("h4", " "), inline=True)
                        )
                        for media_handle in self.unused_media_handles:
                            media = self.r_db.get_media_from_handle(media_handle)
                            gc.collect() # Reduce memory usage when many images.
                            if idx == total:
                                next_ = None
                            else:
                                self.unused_media_handles[idx]
                            trow += Html("tr")
                            media_data_row = [
                                [index, "ColumnRowLabel"],
                                [self.media_ref_link(media_handle,
                                                     media.get_description()),
                                 "ColumnName"],
                                [self.rlocale.get_date(media.get_date_object()),
                                 "ColumnDate"],
                                [media.get_mime_type(), "ColumnMime"]]
                            trow.extend(
                                Html("td", data, class_=colclass)
                                for data, colclass in media_data_row
                            )
                            prev = media_handle
                            step()
                            index += 1
                            idx += 1

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

        # send page out for processing
        # and close the file
        self.report.cur_fname = self.cur_fname
        self.xhtml_writer(medialistpage, output_file, sio, ldatec)
Exemplo n.º 31
0
    def placelistpage(self, report, title, place_handles):
        """
        Create a place index

        @param: report        -- The instance of the main report class for
                                 this report
        @param: title         -- Is the title of the web page
        @param: place_handles -- The handle for the place to add
        """
        BasePage.__init__(self, report, title)

        output_file, sio = self.report.create_file("places")
        placelistpage, head, body = self.write_header(self._("Places"))
        ldatec = 0
        prev_letter = " "

        # begin places division
        with Html("div", class_="content", id="Places") as placelist:
            body += placelist

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

            # begin alphabet navigation
            index_list = get_first_letters(self.r_db, place_handles,
                                           _KEYPLACE, rlocale=self.rlocale)
            alpha_nav = alphabet_navigation(index_list, self.rlocale)
            if alpha_nav is not None:
                placelist += alpha_nav

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

                # begin table head
                thead = Html("thead")
                table += thead

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

                if self.display_coordinates:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass) in [
                            [self._("Letter"), "ColumnLetter"],
                            [self._("Place Name | Name"), "ColumnName"],
                            [self._("State/ Province"), "ColumnState"],
                            [self._("Country"), "ColumnCountry"],
                            [self._("Latitude"), "ColumnLatitude"],
                            [self._("Longitude"), "ColumnLongitude"]
                        ]
                    )
                else:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass) in [
                            [self._("Letter"), "ColumnLetter"],
                            [self._("Place Name | Name"), "ColumnName"],
                            [self._("State/ Province"), "ColumnState"],
                            [self._("Country"), "ColumnCountry"]
                        ]
                    )

                # bug 9495 : incomplete display of place hierarchy labels
                def sort_by_place_name(obj):
                    """ sort by lower case place name. """
                    name = self.report.obj_dict[Place][obj][1]
                    return name.lower()

                handle_list = sorted(place_handles,
                                     key=lambda x: sort_by_place_name(x))
                first = True

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

                for place_handle in handle_list:
                    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 = self.report.obj_dict[Place][place_handle][1]
                        main_location = get_main_location(self.r_db, place)

                        if plc_title and plc_title != " ":
                            letter = get_index_letter(first_letter(plc_title),
                                                      index_list,
                                                      self.rlocale)
                        else:
                            letter = '&nbsp;'

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

                        tcell = Html("td", class_="ColumnLetter", inline=True)
                        trow += tcell
                        if first or primary_difference(letter, prev_letter,
                                                       self.rlocale):
                            first = False
                            prev_letter = letter
                            trow.attr = 'class = "BeginLetter"'

                            ttle = self._("Places beginning "
                                          "with letter %s") % letter
                            tcell += Html("a", letter, name=letter, title=ttle)
                        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;'

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

        # send page out for processing
        # and close the file
        self.xhtml_writer(placelistpage, output_file, sio, ldatec)
Exemplo n.º 32
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)
Exemplo n.º 33
0
    def sourcelistpage(self, report, title, source_handles):
        """
        Generate and output the Sources index page.

        @param: report         -- The instance of the main report class for
                                  this report
        @param: title          -- Is the title of the web page
        @param: source_handles -- A list of the handles of the sources to be
                                  displayed
        """
        BasePage.__init__(self, report, title)

        source_dict = {}

        output_file, sio = self.report.create_file("sources")
        sourcelistpage, head, body = self.write_header(self._("Sources"))

        # begin source list division
        with Html("div", class_="content", id="Sources") as sourceslist:
            body += 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._("Source Name|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)
        body += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(sourcelistpage, output_file, sio, 0)
Exemplo n.º 34
0
    def eventlistpage(self, report, title, event_types, event_handle_list):
        """
        Will create the event list page

        @param: report            -- The instance of the main report class for
                                     this report
        @param: title             -- Is the title of the web page
        @param: event_types       -- A list of the type in the events database
        @param: event_handle_list -- A list of event handles
        """
        BasePage.__init__(self, report, title)
        ldatec = 0
        prev_letter = " "

        output_file, sio = self.report.create_file("events")
        eventslistpage, head, body = self.write_header(self._("Events"))

        # begin events list  division
        with Html("div", class_="content", id="EventList") as eventlist:
            body += eventlist

            msg = self._("This page contains an index of all the events in the "
                         "database, sorted by their type and date (if one is "
                         "present). Clicking on an event&#8217;s Gramps ID "
                         "will open a page for that event.")
            eventlist += Html("p", msg, id="description")

            # get alphabet navigation...
            index_list = get_first_letters(self.r_db, event_types,
                                           _ALPHAEVENT)
            alpha_nav = alphabet_navigation(index_list, self.rlocale)
            if alpha_nav:
                eventlist += alpha_nav

            # begin alphabet event table
            with Html("table",
                      class_="infolist primobjlist alphaevent") as table:
                eventlist += table

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

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

                trow.extend(
                    Html("th", label, class_=colclass, inline=True)
                    for (label, colclass) in [(self._("Letter"),
                                               "ColumnRowLabel"),
                                              (self._("Type"), "ColumnType"),
                                              (self._("Date"), "ColumnDate"),
                                              (self._("Gramps ID"),
                                               "ColumnGRAMPSID"),
                                              (self._("Person"), "ColumnPerson")
                                             ]
                )

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

                # separate events by their type and then thier event handles
                for (evt_type,
                     data_list) in sort_event_types(self.r_db,
                                                    event_types,
                                                    event_handle_list,
                                                    self.rlocale):
                    first = True
                    _event_displayed = []

                    # sort datalist by date of event and by event handle...
                    data_list = sorted(data_list, key=itemgetter(0, 1))
                    first_event = True

                    for (sort_value, event_handle) in data_list:
                        event = self.r_db.get_event_from_handle(event_handle)
                        _type = event.get_type()
                        gid = event.get_gramps_id()
                        if event.get_change_time() > ldatec:
                            ldatec = event.get_change_time()

                        # check to see if we have listed this gramps_id yet?
                        if gid not in _event_displayed:

                            # family event
                            if int(_type) in _EVENTMAP:
                                handle_list = set(
                                    self.r_db.find_backlink_handles(
                                        event_handle,
                                        include_classes=['Family', 'Person']))
                            else:
                                handle_list = set(
                                    self.r_db.find_backlink_handles(
                                        event_handle,
                                        include_classes=['Person']))
                            if handle_list:

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

                                # set up hyperlinked letter for
                                # alphabet_navigation
                                tcell = Html("td", class_="ColumnLetter",
                                             inline=True)
                                trow += tcell

                                if evt_type and not evt_type.isspace():
                                    letter = get_index_letter(
                                        self._(str(evt_type)[0].capitalize()),
                                        index_list, self.rlocale)
                                else:
                                    letter = "&nbsp;"

                                if first or primary_difference(letter,
                                                               prev_letter,
                                                               self.rlocale):
                                    first = False
                                    prev_letter = letter
                                    t_a = 'class = "BeginLetter BeginType"'
                                    trow.attr = t_a
                                    ttle = self._("Event types beginning "
                                                  "with letter %s") % letter
                                    tcell += Html("a", letter, name=letter,
                                                  id_=letter, title=ttle,
                                                  inline=True)
                                else:
                                    tcell += "&nbsp;"

                                # display Event type if first in the list
                                tcell = Html("td", class_="ColumnType",
                                             title=self._(evt_type),
                                             inline=True)
                                trow += tcell
                                if first_event:
                                    tcell += self._(evt_type)
                                    if trow.attr == "":
                                        trow.attr = 'class = "BeginType"'
                                else:
                                    tcell += "&nbsp;"

                                # event date
                                tcell = Html("td", class_="ColumnDate",
                                             inline=True)
                                trow += tcell
                                date = Date.EMPTY
                                if event:
                                    date = event.get_date_object()
                                    if date and date is not Date.EMPTY:
                                        tcell += self.rlocale.get_date(date)
                                else:
                                    tcell += "&nbsp;"

                                # Gramps ID
                                trow += Html("td", class_="ColumnGRAMPSID") + (
                                    self.event_grampsid_link(event_handle,
                                                             gid, None)
                                    )

                                # Person(s) column
                                tcell = Html("td", class_="ColumnPerson")
                                trow += tcell

                                # classname can either be a person or a family
                                first_person = True

                                # get person(s) for ColumnPerson
                                sorted_list = sorted(handle_list)
                                self.complete_people(tcell, first_person,
                                                     sorted_list,
                                                     uplink=False)

                        _event_displayed.append(gid)
                        first_event = False

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

        # send page ut for processing
        # and close the file
        self.xhtml_writer(eventslistpage, output_file, sio, ldatec)
Exemplo n.º 35
0
    def familylistpage(self, report, title, fam_list):
        """
        Create a family index

        @param: report   -- The instance of the main report class for
                            this report
        @param: title    -- Is the title of the web page
        @param: fam_list -- The handle for the place to add
        """
        BasePage.__init__(self, report, title)

        output_file, sio = self.report.create_file("families")
        familieslistpage, head, body = self.write_header(self._("Families"))
        ldatec = 0
        prev_letter = " "

        # begin Family Division
        with Html("div", class_="content", id="Relationships") as relationlist:
            body += relationlist

            # Families list page message
            msg = self._("This page contains an index of all the "
                         "families/ relationships in the "
                         "database, sorted by their family name/ surname. "
                         "Clicking on a person&#8217;s "
                         "name will take you to their "
                         "family/ relationship&#8217;s page.")
            relationlist += Html("p", msg, id="description")

            # go through all the families, and construct a dictionary of all the
            # people and the families thay are involved in. Note that the people
            # in the list may be involved in OTHER families, that are not listed
            # because they are not in the original family list.
            pers_fam_dict = defaultdict(list)
            for family_handle in fam_list:
                family = self.r_db.get_family_from_handle(family_handle)
                if family:
                    if family.get_change_time() > ldatec:
                        ldatec = family.get_change_time()
                    husband_handle = family.get_father_handle()
                    spouse_handle = family.get_mother_handle()
                    if husband_handle:
                        pers_fam_dict[husband_handle].append(family)
                    if spouse_handle:
                        pers_fam_dict[spouse_handle].append(family)

            # add alphabet navigation
            index_list = get_first_letters(self.r_db, pers_fam_dict.keys(),
                                           _KEYPERSON, rlocale=self.rlocale)
            alpha_nav = alphabet_navigation(index_list, self.rlocale)
            if alpha_nav:
                relationlist += alpha_nav

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

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

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

               # set up page columns
                trow.extend(
                    Html("th", trans, class_=colclass, inline=True)
                    for trans, colclass in [(self._("Letter"),
                                             "ColumnRowLabel"),
                                            (self._("Person"), "ColumnPartner"),
                                            (self._("Family"), "ColumnPartner"),
                                            (self._("Marriage"), "ColumnDate"),
                                            (self._("Divorce"), "ColumnDate")]
                    )

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

                # begin displaying index list
                ppl_handle_list = sort_people(self.r_db, pers_fam_dict.keys(),
                                              self.rlocale)
                first = True
                for (surname, handle_list) in ppl_handle_list:

                    if surname and not surname.isspace():
                        letter = get_index_letter(first_letter(surname),
                                                  index_list,
                                                  self.rlocale)
                    else:
                        letter = '&nbsp;'

                    # get person from sorted database list
                    for person_handle in sorted(
                            handle_list, key=self.sort_on_name_and_grampsid):
                        person = self.r_db.get_person_from_handle(person_handle)
                        if person:
                            family_list = person.get_family_handle_list()
                            first_family = True
                            for family_handle in family_list:
                                get_family = self.r_db.get_family_from_handle
                                family = get_family(family_handle)
                                trow = Html("tr")
                                tbody += trow

                                tcell = Html("td", class_="ColumnRowLabel")
                                trow += tcell

                                if first or primary_difference(letter,
                                                               prev_letter,
                                                               self.rlocale):
                                    first = False
                                    prev_letter = letter
                                    trow.attr = 'class="BeginLetter"'
                                    ttle = self._("Families beginning with "
                                                  "letter ")
                                    tcell += Html("a", letter, name=letter,
                                                  title=ttle + letter,
                                                  inline=True)
                                else:
                                    tcell += '&nbsp;'

                                tcell = Html("td", class_="ColumnPartner")
                                trow += tcell

                                if first_family:
                                    trow.attr = 'class ="BeginFamily"'

                                    tcell += self.new_person_link(
                                        person_handle, uplink=self.uplink)

                                    first_family = False
                                else:
                                    tcell += '&nbsp;'

                                tcell = Html("td", class_="ColumnPartner")
                                trow += tcell

                                tcell += self.family_link(
                                    family.get_handle(),
                                    self.report.get_family_name(family),
                                    family.get_gramps_id(), self.uplink)

                                # family events; such as marriage and divorce
                                # events
                                fam_evt_ref_list = family.get_event_ref_list()
                                tcell1 = Html("td", class_="ColumnDate",
                                              inline=True)
                                tcell2 = Html("td", class_="ColumnDate",
                                              inline=True)
                                trow += (tcell1, tcell2)

                                if fam_evt_ref_list:
                                    fam_evt_srt_ref_list = sorted(
                                        fam_evt_ref_list,
                                        key=self.sort_on_grampsid)
                                    for evt_ref in fam_evt_srt_ref_list:
                                        evt = self.r_db.get_event_from_handle(
                                            evt_ref.ref)
                                        if evt:
                                            evt_type = evt.get_type()
                                            if evt_type in [EventType.MARRIAGE,
                                                            EventType.DIVORCE]:

                                                cell = self.rlocale.get_date(
                                                    evt.get_date_object())
                                                if (evt_type ==
                                                        EventType.MARRIAGE):
                                                    tcell1 += cell
                                                else:
                                                    tcell1 += '&nbsp;'

                                                if (evt_type ==
                                                        EventType.DIVORCE):
                                                    tcell2 += cell
                                                else:
                                                    tcell2 += '&nbsp;'
                                else:
                                    tcell1 += '&nbsp;'
                                    tcell2 += '&nbsp;'
                                first_family = False

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

        # send page out for processing
        # and close the file
        self.xhtml_writer(familieslistpage, output_file, sio, ldatec)
Exemplo n.º 36
0
    def __init__(self, report, title, has_url_addr_res):
        """
        @param: report           -- The instance of the main report class
                                    for this report
        @param: title            -- Is the title of the web page
        @param: has_url_addr_res -- The url, address and residence to use
                                    for the report
        """
        BasePage.__init__(self, report, title)

        # Name the file, and create it
        output_file, sio = self.report.create_file("addressbook")

        # Add xml, doctype, meta and stylesheets
        addressbooklistpage, head, body = self.write_header(_("Address Book"))

        # begin AddressBookList division
        with Html("div", class_="content",
                  id="AddressBookList") as addressbooklist:
            body += addressbooklist

            # Address Book Page message
            msg = _("This page contains an index of all the individuals in "
                    "the database, sorted by their surname, with one of the "
                    "following: Address, Residence, or Web Links. "
                    "Selecting the person&#8217;s name will take you "
                    "to their individual Address Book page.")
            addressbooklist += Html("p", msg, id="description")

            # begin Address Book table
            with Html("table",
                      class_="infolist primobjlist addressbook") as table:
                addressbooklist += table

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

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

                trow.extend(
                    Html("th", label, class_=colclass, inline=True)
                    for (label, colclass) in [
                        ["&nbsp;", "ColumnRowLabel"],
                        [_("Full Name"), "ColumnName"],
                        [_("Address"), "ColumnAddress"],
                        [_("Residence"), "ColumnResidence"],
                        [_("Web Links"), "ColumnWebLinks"]
                    ]
                )

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

                index = 1
                for (sort_name, person_handle,
                     has_add, has_res,
                     has_url) in has_url_addr_res:

                    address = None
                    residence = None
                    weblinks = None

                    # has address but no residence event
                    if has_add and not has_res:
                        address = "X"

                    # has residence, but no addresses
                    elif has_res and not has_add:
                        residence = "X"

                    # has residence and addresses too
                    elif has_add and has_res:
                        address = "X"
                        residence = "X"

                    # has Web Links
                    if has_url:
                        weblinks = "X"

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

                    trow.extend(
                        Html("td", data or "&nbsp;", class_=colclass,
                             inline=True)
                        for (colclass, data) in [
                            ["ColumnRowLabel", index],
                            ["ColumnName",
                             self.addressbook_link(person_handle)],
                            ["ColumnAddress", address],
                            ["ColumnResidence", residence],
                            ["ColumnWebLinks", weblinks]
                        ]
                    )
                    index += 1

        # Add footer and clearline
        footer = self.write_footer(None)
        body += (FULLCLEAR, footer)

        # send the page out for processing
        # and close the file
        self.xhtml_writer(addressbooklistpage, output_file, sio, 0)
Exemplo n.º 37
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)
Exemplo n.º 38
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)
Exemplo n.º 39
0
    def __init__(self, report, title, ppl_handle_list,
                 order_by=ORDER_BY_NAME, filename="surnames"):
        """
        @param: report          -- The instance of the main report class for
                                   this report
        @param: title           -- Is the title of the web page
        @param: ppl_handle_list -- The list of people for whom we need to create
                                   a page.
        @param: order_by        -- The way to sort surnames :
                                   Surnames or Surnames count
        @param: filename        -- The name to use for the Surnames page
        """
        BasePage.__init__(self, report, title)
        prev_surname = ""
        prev_letter = " "

        if order_by == self.ORDER_BY_NAME:
            output_file, sio = self.report.create_file(filename)
            surnamelistpage, head, body = self.write_header(self._('Surnames'))
        else:
            output_file, sio = self.report.create_file("surnames_count")
            (surnamelistpage, head,
             body) = self.write_header(self._('Surnames by person count'))

        # begin surnames division
        with Html("div", class_="content", id="surnames") as surnamelist:
            body += surnamelist

            # page message
            msg = self._('This page contains an index of all the '
                         'surnames in the database. Selecting a link '
                         'will lead to a list of individuals in the '
                         'database with this same surname.')
            surnamelist += Html("p", msg, id="description")

            # add alphabet navigation...
            # only if surname list not surname count
            if order_by == self.ORDER_BY_NAME:
                index_list = get_first_letters(self.r_db, ppl_handle_list,
                                               _KEYPERSON, rlocale=self.rlocale)
                alpha_nav = alphabet_navigation(index_list, self.rlocale)
                if alpha_nav is not None:
                    surnamelist += alpha_nav

            if order_by == self.ORDER_BY_COUNT:
                table_id = 'SortByCount'
            else:
                table_id = 'SortByName'

            # begin surnamelist table and table head
            with Html("table", class_="infolist primobjlist surnamelist",
                      id=table_id) as table:
                surnamelist += table

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

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

                trow += Html("th", self._("Letter"), class_="ColumnLetter",
                             inline=True)

                # create table header surname hyperlink
                fname = self.report.surname_fname + self.ext
                tcell = Html("th", class_="ColumnSurname", inline=True)
                trow += tcell
                hyper = Html("a", self._("Surname"),
                             href=fname, title=self._("Surnames"))
                tcell += hyper

                # create table header number of people hyperlink
                fname = "surnames_count" + self.ext
                tcell = Html("th", class_="ColumnQuantity", inline=True)
                trow += tcell
                num_people = self._("Number of People")
                hyper = Html("a", num_people, href=fname, title=num_people)
                tcell += hyper

                name_format = self.report.options['name_format']
                # begin table body
                with Html("tbody") as tbody:
                    table += tbody

                    ppl_handle_list = sort_people(self.r_db, ppl_handle_list,
                                                  self.rlocale)
                    if order_by == self.ORDER_BY_COUNT:
                        temp_list = {}
                        for (surname, data_list) in ppl_handle_list:
                            index_val = "%90d_%s" % (999999999-len(data_list),
                                                     surname)
                            temp_list[index_val] = (surname, data_list)

                        lkey = self.rlocale.sort_key
                        ppl_handle_list = (temp_list[key]
                                           for key in sorted(temp_list,
                                                             key=lkey))

                    first = True
                    first_surname = True

                    for (surname, data_list) in ppl_handle_list:

                        if surname and not surname.isspace():
                            letter = first_letter(surname)
                            if order_by == self.ORDER_BY_NAME:
                                # There will only be an alphabetic index list if
                                # the ORDER_BY_NAME page is being generated
                                letter = get_index_letter(letter, index_list,
                                                          self.rlocale)
                        else:
                            letter = '&nbsp;'
                            surname = self._("<absent>")

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

                        tcell = Html("td", class_="ColumnLetter", inline=True)
                        trow += tcell

                        if first or primary_difference(letter, prev_letter,
                                                       self.rlocale):
                            first = False
                            prev_letter = letter
                            trow.attr = 'class = "BeginLetter"'
                            ttle = self._("Surnames beginning with "
                                          "letter %s") % letter
                            hyper = Html("a", letter, name=letter,
                                         title=ttle, inline=True)
                            tcell += hyper
                        elif first_surname or surname != prev_surname:
                            first_surname = False
                            tcell += "&nbsp;"
                            prev_surname = surname

                        # In case the user choose a format name like "*SURNAME*"
                        # We must display this field in upper case. So we use
                        # the english format of format_name to find if this is
                        # the case.
                        # name_format = self.report.options['name_format']
                        nme_format = _nd.name_formats[name_format][1]
                        if "SURNAME" in nme_format:
                            surnamed = surname.upper()
                        else:
                            surnamed = surname
                        trow += Html("td",
                                     self.surname_link(name_to_md5(surname),
                                                       surnamed),
                                     class_="ColumnSurname", inline=True)

                        trow += Html("td", len(data_list),
                                     class_="ColumnQuantity", inline=True)

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

        # send page out for processing
        # and close the file
        self.xhtml_writer(surnamelistpage,
                          output_file, sio, 0) # 0 => current date modification
Exemplo n.º 40
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)
Exemplo n.º 41
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)