コード例 #1
0
ファイル: place.py プロジェクト: tiansworld/gramps
 def __output_place(self, ldatec, tbody, first_place, pname, place_handle,
                    letter, bucket_link):
     place = self.r_db.get_place_from_handle(place_handle)
     if place:
         if place.get_change_time() > ldatec:
             ldatec = place.get_change_time()
         plc_title = pname
         main_location = get_main_location(self.r_db, place)
         if not plc_title or plc_title == " ":
             letter = " "
         trow = Html("tr")
         tbody += trow
         tcell = Html("td", class_="ColumnLetter", inline=True)
         trow += tcell
         if first_place:
             # or primary_difference(letter, prev_letter, self.rlocale):
             first_place = False
             # prev_letter = letter
             trow.attr = 'class = "BeginLetter"'
             ttle = self._("Places beginning " "with letter %s") % letter
             tcell += Html("a",
                           letter,
                           name=letter,
                           title=ttle,
                           id_=bucket_link)
         else:
             tcell += " "
         trow += Html("td",
                      self.place_link(place.get_handle(), plc_title,
                                      place.get_gramps_id()),
                      class_="ColumnName")
         trow.extend(
             Html("td", data or " ", 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 += ' '
                 tcell2 += ' '
     return (ldatec, first_place)
コード例 #2
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’s "
                "title will take you to that place’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 = ' '

                        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 += " "

                        trow += Html("td",
                                     self.place_link(place.get_handle(),
                                                     plc_title,
                                                     place.get_gramps_id()),
                                     class_="ColumnName")

                        trow.extend(
                            Html("td",
                                 data or " ",
                                 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 += ' '
                                tcell2 += ' '

        # 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)
コード例 #3
0
ファイル: family.py プロジェクト: naciohr/gramps-official
    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")
        result = self.write_header(self._("Families"))
        familieslistpage, dummy_head, dummy_body, outerwrapper = result
        ldatec = 0
        prev_letter = " "

        # begin Family Division
        with Html("div", class_="content", id="Relationships") as relationlist:
            outerwrapper += 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’s "
                         "name will take you to their "
                         "family/ relationship’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 = ' '

                    # 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 += ' '

                                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 += ' '

                                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 += ' '

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

        # 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(familieslistpage, output_file, sio, ldatec)
コード例 #4
0
ファイル: family.py プロジェクト: SNoiraud/gramps
    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’s "
                         "name will take you to their "
                         "family/ relationship’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 = ' '

                    # 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 += ' '

                                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 += ' '

                                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 += ' '

                                                if (evt_type ==
                                                        EventType.DIVORCE):
                                                    tcell2 += cell
                                                else:
                                                    tcell2 += ' '
                                else:
                                    tcell1 += ' '
                                    tcell2 += ' '
                                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)
コード例 #5
0
ファイル: event.py プロジェクト: vantu5z/gramps
    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’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 = " "

                                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 += " "

                                # 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 += " "

                                # 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 += " "

                                # 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)
コード例 #6
0
ファイル: family.py プロジェクト: tiansworld/gramps
    def __output_family(self, ldatec, family_handle, person_handle,
                        tbody, letter, bucket_link, first_person, first_family):
        """
        Generate and output the data for a single family

        @param: ldatec          -- Last change date and time (updated)
        @param: family_handle   -- The family_handle to be output
        @param: person_handle   -- The person_handle to be output
        @param: tbody           -- The current HTML body into which the data is
                                   assembled
        @param: letter          -- The AlphabeticIndex bucket for this event
        @param: first_person    -- Whether this is the first person for this
                                   letter
        @param: first_family    -- Whether this is the first family of this
                                   person

        @returns: Returns a tuple of updated (ldatec, first_person,
                                              first_family)
        @rtype: tuple
        """
        family = self.r_db.get_family_from_handle(family_handle)
        if family.get_change_time() > ldatec:
            ldatec = family.get_change_time()

        trow = Html("tr")
        tbody += trow
        tcell = Html("td", class_="ColumnRowLabel")
        trow += tcell
        if first_person:
            first_person = False
            first_family = False
            # Update the ColumnRowLabel cell
            trow.attr = 'class="BeginLetter BeginFamily"'
            ttle = self._("Families beginning with "
                "letter ")
            tcell += Html("a", letter, name=letter, title=ttle + letter,
                          id_=bucket_link)
            #  and create the populated ColumnPartner for the person
            tcell = Html("td", class_="ColumnPartner")
            tcell += self.new_person_link(person_handle, uplink=self.uplink)
            trow += tcell
        elif first_family:
            first_family = False
            # Update the ColumnRowLabel cell
            trow.attr = 'class ="BeginFamily"'
            #  and create the populated ColumnPartner for the person
            tcell = Html("td", class_="ColumnPartner")
            tcell += self.new_person_link(person_handle, uplink=self.uplink)
            trow += tcell
        else:
            # Create the blank ColumnPartner row for the person
            tcell = Html("td", class_="ColumnPartner")
            tcell += ' '
            trow += tcell

        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 += ' '
                        if evt_type == EventType.DIVORCE:
                            tcell2 += cell
                        else:
                            tcell2 += ' '

        else:
            tcell1 += ' '
            tcell2 += ' '
        first_family = False
        return (ldatec, first_person, first_family)
コード例 #7
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 = ' '
                            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
コード例 #8
0
ファイル: event.py プロジェクト: tiansworld/gramps
    def __output_event(self, ldatec, event_type, tbody, bucket_letter,
                       bucket_link, first_letter, _event_displayed, first_type,
                       event_handle):
        """
        Generate and output the data for a single event

        @param: ldatec          -- Last change date and time (updated)
        @param: event_type      -- The event type name processed for XML etc
        @param: tbody           -- The current HTML body into which the data is
                                   assembled
        @param: bucket_letter   -- The AlphabeticIndex bucket for this event
        @param: bucket_link     -- ????
        @param: first_letter    -- Whether this is the first event for this
                                   letter
        @param: event_displayed -- List of events already displayed
        @param: first_type      -- Whether this is the first event of this type
        @param: event_handle    -- Handle of the event to be output

        :returns: Returns a tuple of updated ldatec, first_letter, first_type,
                    _event_displayed
        :rtype: tuple

        """
        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:
            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 first_letter:
                    first_letter = False
                    first_type = False
                    # Update the ColumnLetter cell and
                    # create a populated ColumnType
                    t_a = 'class = "BeginLetter BeginType"'
                    trow.attr = t_a
                    letter = bucket_letter
                    ttle = self._("Event types beginning "
                                  "with letter %s") % letter
                    tcell += Html("a",
                                  letter,
                                  name=letter,
                                  id_=bucket_link,
                                  title=ttle)
                    tcell = Html("td",
                                 class_="ColumnType",
                                 title=self._(event_type),
                                 inline=True)
                    tcell += self._(event_type)
                elif first_type:
                    first_type = False
                    # Update the ColumnLetter cell and
                    # create a populated ColumnType cell
                    trow.attr = 'class = "BeginType"'
                    tcell = Html("td",
                                 class_="ColumnType",
                                 title=self._(event_type),
                                 inline=True)
                    tcell += self._(event_type)
                else:
                    tcell = Html("td",
                                 class_="ColumnType",
                                 title="&nbsp;",
                                 inline=True)
                    tcell += "&nbsp;"  # create a non-populated ColumnType
                # Add the ColumnType cell
                trow += tcell
                # 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)
        return (ldatec, first_letter, first_type, _event_displayed)
コード例 #9
0
ファイル: surnamelist.py プロジェクト: tiansworld/gramps
    def output_surname_records(self, index, tbody, name_format):
        """
        Output all the surnames in the index.

        @param: index   -- An ICU AlphabeticIndex where the names are surnames
                           and the data is a list of people handles with that
                           surname
        @param: tbody   -- The HTML body to which the lines are added
        @param: name_format -- The name format from the report options
        """
        index.resetBucketIterator()
        output = []
        dup_index = 0
        while index.nextBucket():
            if index.bucketRecordCount != 0:
                trow = Html("tr")
                tbody += trow

                tcell = Html("td", class_="ColumnLetter", inline=True)
                trow += tcell
                trow.attr = 'class = "BeginLetter"'
                bucket_letter = index.bucketLabel
                bucket_link = bucket_letter
                if bucket_letter in output:
                    bucket_link = "%s (%i)" % (bucket_letter, dup_index)
                    dup_index += 1
                output.append(bucket_letter)
                try:  # some characters don't have a unicode name
                    char = uniname(bucket_letter)
                except (ValueError, TypeError) as dummy_err:
                    char = " "
                ttle = self._("Surnames beginning with "
                              "letter '%s' %s") % \
                              (bucket_letter, char)
                hyper = Html("a",
                             index.bucketLabel,
                             name=index.bucketLabel,
                             id_=bucket_link,
                             title=ttle)
                tcell += hyper

                first = True
                while index.nextRecord():
                    surname = index.recordName
                    if not first:
                        trow = Html("tr")
                        tbody += trow

                        tcell = Html("td", class_="ColumnLetter", inline=True)
                        trow += tcell
                    first = False
                    if not surname or surname.isspace():
                        surname = self._("<absent>")
                    # 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(index.recordData),
                                 class_="ColumnQuantity",
                                 inline=True)
コード例 #10
0
ファイル: event.py プロジェクト: cz172638/gramps
    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)
コード例 #11
0
ファイル: place.py プロジェクト: prculley/gramps
    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)