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)
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)
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)
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)
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 += " " 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
def familylistpage(self, report, the_lang, the_title, fam_list): """ Create a family index @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: fam_list -- The handle for the place to add """ BasePage.__init__(self, report, the_lang, the_title) output_file, sio = self.report.create_file("families") result = self.write_header(self._("Families")) familieslistpage, dummy_head, dummy_body, outerwrapper = result ldatec = 0 # 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 they 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) # Assemble all the people, we no longer care about their families index = AlphabeticIndex(self.rlocale) for (person_handle, dummy_family) in pers_fam_dict.items(): person = self.r_db.get_person_from_handle(person_handle) surname = get_surname_from_person(self.r_db, person) index.addRecord(surname, person_handle) # Extract the buckets from the index index_list = [] index.resetBucketIterator() while index.nextBucket(): if index.bucketRecordCount != 0: index_list.append(index.bucketLabel) # Output the navigation # add alphabet navigation 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 # for each bucket, output the people and their families in that # bucket index.resetBucketIterator() output = [] dup_index = 0 while index.nextBucket(): if index.bucketRecordCount != 0: 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) # Assemble a dict of all the people in this bucket. surname_ppl_handle_dict = OrderedDict() while index.nextRecord(): # The records are returned sorted by recordName, # which is surname. we need to retain that order but # in addition sort by the rest of the name person_surname = index.recordName person_handle = index.recordData if person_surname in surname_ppl_handle_dict.keys(): surname_ppl_handle_dict[person_surname]\ .append(person_handle) else: surname_ppl_handle_dict[person_surname] = \ [person_handle] first_person = True for (surname, handle_list) in \ surname_ppl_handle_dict.items(): # 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: (ldatec, first_person, first_family) \ = self.__output_family(ldatec, family_handle, person_handle, tbody, bucket_letter, bucket_link, first_person, first_family) # 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)
def eventlistpage(self, report, the_lang, the_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: the_lang -- The lang to process @param: the_title -- The title page related to the language @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, the_lang, the_title) ldatec = 0 output_file, sio = self.report.create_file("events") result = self.write_header(self._("Events")) eventslistpage, dummy_head, dummy_body, outerwrapper = result # begin events list division with Html("div", class_="content", id="EventList") as eventlist: outerwrapper += 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... # Assemble all the event types index = AlphabeticIndex(self.rlocale) for (event_type, data_list) in sort_event_types(self.r_db, event_types, event_handle_list, self.rlocale): index.addRecord(event_type, data_list) # Extract the buckets from the index index_list = [] index.resetBucketIterator() while index.nextBucket(): if index.bucketRecordCount != 0: index_list.append(index.bucketLabel) # Output the navigation 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 # for each bucket, output the events in that bucket index.resetBucketIterator() output = [] dup_index = 0 while index.nextBucket(): if index.bucketRecordCount != 0: 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) first_letter = True while index.nextRecord(): _event_displayed = [] first_type = True event_type = index.recordName data_list = index.recordData # sort datalist by date of event and by event # handle... data_list = sorted(data_list, key=itemgetter(0, 1)) for (dummy_sort_value, event_handle) in data_list: (ldatec, first_letter, first_type, _event_displayed) \ = self.__output_event(ldatec, event_type, tbody, bucket_letter, bucket_link, first_letter, _event_displayed, first_type, event_handle) # add clearline for proper styling # add footer section footer = self.write_footer(ldatec) outerwrapper += (FULLCLEAR, footer) # send page ut for processing # and close the file self.xhtml_writer(eventslistpage, output_file, sio, ldatec)
def __init__(self, report, the_lang, the_title, ppl_handle_list, order_by=ORDER_BY_NAME, filename="surnames"): """ @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: 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, the_lang, the_title) if order_by == self.ORDER_BY_NAME: output_file, sio = self.report.create_file(filename) result = self.write_header(self._('Surnames')) else: output_file, sio = self.report.create_file("surnames_count") result = self.write_header(self._('Surnames by person count')) surnamelistpage, dummy_head, dummy_body, outerwrapper = result # begin surnames division with Html("div", class_="content", id="surnames") as surnamelist: outerwrapper += 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") # Assemble all the handles for each surname into a dictionary # We don't call sort_people because we don't care about sorting # individuals, only surnames surname_handle_dict = defaultdict(list) for person_handle in ppl_handle_list: person = self.r_db.get_person_from_handle(person_handle) surname = get_surname_from_person(self.r_db, person) surname_handle_dict[surname].append(person_handle) # add alphabet navigation... # only if surname list not surname count if order_by == self.ORDER_BY_NAME: # Assemble the AlphabeticIndex index = AlphabeticIndex(self.rlocale) for surname, handle_list in surname_handle_dict.items(): index.addRecord(surname, handle_list) # Extract the buckets from the index index_list = [] index.resetBucketIterator() while index.nextBucket(): if index.bucketRecordCount != 0: index_list.append(index.bucketLabel) # Output the navigation 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 if order_by == self.ORDER_BY_COUNT: # construct a dictionary of counts, for example # {3: ["brown", [handle1, handle2,handle3], # "smith", [handle4, handle5, handle6] # ], # 2: ["Jones", [handle7] # # }] count_ppl_handle_dict = defaultdict(list) for surname, data_list in surname_handle_dict.items(): count_ppl_handle_dict[len(data_list)].append \ ((surname,data_list)) # For each count, we construct and output a separate # AlphabeticIndex for all surnames with that count for (dummy_count, ppl_handles) in \ sorted(count_ppl_handle_dict.items(), reverse=True): # Construct the AplhabeticIndex for that count index = AlphabeticIndex(self.rlocale) for (surname, handle_list) in ppl_handles: index.addRecord(surname, handle_list) # Output the AlphabeticIndex for that count self.output_surname_records( index, tbody, name_format) else: # order_by == self.ORDER_BY_NAME # The AlphabeticIndex has already been constructed # Output the AlphabeticIndex self.output_surname_records(index, tbody, name_format) # create footer section # add clearline for proper styling footer = self.write_footer(None) outerwrapper += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(surnamelistpage, output_file, sio, 0) # 0 => current date modification
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)
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’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) body += (FULLCLEAR, footer) # send page out for processing # and close the file self.xhtml_writer(placelistpage, output_file, sio, ldatec)
def placelistpage(self, report, the_lang, the_title): """ Create a place index @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) output_file, sio = self.report.create_file("places") result = self.write_header(self._("Places")) placelistpage, dummy_head, dummy_body, outerwrapper = result ldatec = 0 # 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 # Assemble all the places index = AlphabeticIndex(self.rlocale) # self.report.obj_dict[PlaceName] is a dict with key place_name and # values (place_fname, place_name, place.gramps_id, event) for (place_name, value) in self.report.obj_dict[PlaceName].items(): index.addRecord(place_name, value) # Extract the buckets from the index index_list = [] index.resetBucketIterator() while index.nextBucket(): if index.bucketRecordCount != 0: index_list.append(index.bucketLabel) # Output the navigation alpha_nav = alphabet_navigation(index_list, self.rlocale) if alpha_nav: 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._("Name", "Place 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._("Name", "Place Name"), "ColumnName"], [self._("State/Province"), "ColumnState"], [self._("Country"), "ColumnCountry"] ] ) # begin table body tbody = Html("tbody") table += tbody # For each bucket, output the places in that bucket index.resetBucketIterator() output = [] dup_index = 0 while index.nextBucket(): if index.bucketRecordCount != 0: 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) # Assemble all the places in this bucket into a dict for # sorting place_dict = dict() while index.nextRecord(): place_name = index.recordName value = index.recordData place_dict[place_name] = value handle_list = sort_places(self.r_db, place_dict, self.rlocale) first_place = True for (pname, place_handle) in handle_list: (ldatec, first_place) \ = self.__output_place(ldatec, trow, first_place, pname, place_handle, bucket_letter, bucket_link) # 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)