def sort_people(dbase, handle_list, rlocale=glocale): """ will sort the database people by surname @param: dbase -- The instance of the database @param: handle_list -- The list of handles of people to sort @param: rlocale -- The locale related to the language used for the sort @result: -- A list sorted by surname, each element of which consists of a tuple of (surname, list of handles) where the list of handles is sorted by primary surname, first name, suffix. Surname uses group_as, but primary surname does not. get the primary name if group as get the group_as surname else get the primary surname of the primary name and correct for [global] group_as name correct for surnames that are space or None for each surname sort handles by the surname, first name and suffix construct a list of surnames and list of handles """ sname_sub = defaultdict(list) sortnames = {} for person_handle in handle_list: person = dbase.get_person_from_handle(person_handle) surname = get_surname_from_person(dbase, person) sortnames[person_handle] = _nd.sort_string(person.get_primary_name()) sname_sub[surname].append(person_handle) sorted_lists = [] temp_list = sorted(sname_sub, key=rlocale.sort_key) for name in temp_list: if isinstance(name, bytes): name = name.decode('utf-8') slist = sorted(((sortnames[x], x) for x in sname_sub[name]), key=lambda x: rlocale.sort_key(x[0])) entries = [x[1] for x in slist] sorted_lists.append((name, entries)) return sorted_lists
def __init__(self, child_ref_list, db): Gtk.ListStore.__init__(self, int, str, str, str, str, str, str, str, str, str, str, str, str, bool, object) self.db = db for index, child_ref in enumerate(child_ref_list): child = db.get_person_from_handle(child_ref.ref) if child: self.append(row=[ index + 1, child.get_gramps_id(), name_displayer.display(child), gender_map[ child.get_gender()], str(child_ref.get_father_relation()), str(child_ref.get_mother_relation()), self.column_birth_day(child), self.column_death_day(child), self.column_birth_place(child), self.column_death_place(child), name_displayer.sort_string(child.primary_name), self.column_birth_sort(child), self.column_death_sort(child), child_ref.get_privacy(), child_ref ])
def sort_val_from_handle(self, handle): if self.namespace == 'Person': name = self.db.get_person_from_handle(handle).get_primary_name() sortname = _nd.sort_string(name) elif self.namespace == 'Family': sortname = family_name(self.db.get_family_from_handle(handle), self.db) elif self.namespace == 'Event': sortname = self.db.get_event_from_handle(handle).get_description() elif self.namespace == 'Source': sortname = self.db.get_source_from_handle(handle).get_title() elif self.namespace == 'Citation': sortname = self.db.get_citation_from_handle(handle).get_page() elif self.namespace == 'Place': sortname = self.db.get_place_from_handle(handle).get_title() elif self.namespace == 'Media': sortname = self.db.get_object_from_handle(handle).get_description() elif self.namespace == 'Repository': sortname = self.db.get_repository_from_handle(handle).get_name() elif self.namespace == 'Note': gid = self.db.get_note_from_handle(handle).get_gramps_id() sortname = gid return (sortname, handle)
def sort_val_from_handle(self, handle): if self.namespace == 'Person': name = self.db.get_person_from_handle(handle).get_primary_name() sortname = _nd.sort_string(name) elif self.namespace == 'Family': sortname = family_name( self.db.get_family_from_handle(handle),self.db) elif self.namespace == 'Event': sortname = self.db.get_event_from_handle(handle).get_description() elif self.namespace == 'Source': sortname = self.db.get_source_from_handle(handle).get_title() elif self.namespace == 'Citation': sortname = self.db.get_citation_from_handle(handle).get_page() elif self.namespace == 'Place': place = self.db.get_place_from_handle(handle) sortname = _pd.display(self.db, place) elif self.namespace == 'Media': sortname = self.db.get_media_from_handle(handle).get_description() elif self.namespace == 'Repository': sortname = self.db.get_repository_from_handle(handle).get_name() elif self.namespace == 'Note': gid = self.db.get_note_from_handle(handle).get_gramps_id() sortname = gid return (sortname, handle)
def sort_people(dbase, handle_list, rlocale=glocale): """ will sort the database people by surname """ sname_sub = defaultdict(list) sortnames = {} for person_handle in handle_list: person = dbase.get_person_from_handle(person_handle) primary_name = person.get_primary_name() if primary_name.group_as: surname = primary_name.group_as else: group_map = _nd.primary_surname(primary_name) surname = dbase.get_name_group_mapping(group_map) # Treat people who have no name with those whose name is just # 'whitespace' if surname is None or surname.isspace(): surname = '' sortnames[person_handle] = _nd.sort_string(primary_name) sname_sub[surname].append(person_handle) sorted_lists = [] temp_list = sorted(sname_sub, key=rlocale.sort_key) for name in temp_list: if isinstance(name, bytes): name = name.decode('utf-8') slist = sorted(((sortnames[x], x) for x in sname_sub[name]), key=lambda x: rlocale.sort_key(x[0])) entries = [x[1] for x in slist] sorted_lists.append((name, entries)) return sorted_lists
def __init__(self, child_ref_list, db): Gtk.ListStore.__init__(self, int, str, str, str, str, str, str, str, str, str, str, str, str, bool, object) self.db = db for index, child_ref in enumerate(child_ref_list): child = db.get_person_from_handle(child_ref.ref) if child: self.append(row=[ index + 1, child.get_gramps_id(), name_displayer.display(child), gender_map[child.get_gender()], str(child_ref.get_father_relation()), str(child_ref.get_mother_relation()), self.column_birth_day(child), self.column_death_day(child), self.column_birth_place(child), self.column_death_place(child), name_displayer.sort_string(child.primary_name), self.column_birth_sort(child), self.column_death_sort(child), child_ref.get_privacy(), child_ref ])
def write_sortstring(self, prname): """Write the SORT-STRING property of a VCard.""" # TODO only add sort-string if needed self.writeln("SORT-STRING:%s" % self.esc(_nd.sort_string(prname)))
def __get_person_keyname(dbase, handle): """ .... """ person = dbase.get_person_from_handle(handle) return _nd.sort_string(person.get_primary_name())