def get_first_letters(place_list, rlocale=glocale): """ get the first letters of the place name list @param: handle_list -- The place name list The first letter (or letters if there is a contraction) are extracted from """ index_list = [] for place in place_list: ltr = first_letter(place) index_list.append(ltr) # Now remove letters where there is not a primary difference index_list.sort(key=rlocale.sort_key) first = True prev_index = None for nkey in index_list[:]: #iterate over a slice copy of the list if first or primary_difference(prev_index, nkey, rlocale): first = False prev_index = nkey else: index_list.remove(nkey) # return menu set letters for alphabet_navigation return index_list
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 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 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 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)