Fixed get_person_handles(sort_index=True)

Before did not include first_name in sorting (thanks Paul!)

Also added rebuilding all order_by fields when rebuilding
secondaries.
This commit is contained in:
Doug Blank 2016-05-01 16:47:58 -04:00
parent 780a4be62c
commit c8f3c25d84
3 changed files with 76 additions and 12 deletions

View File

@ -1711,7 +1711,7 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
# Save metadata
self.set_metadata('name_formats', self.name_formats)
self.set_metadata('researcher', self.owner)
# Bookmarks
self.set_metadata('bookmarks', self.bookmarks.get())
self.set_metadata('family_bookmarks', self.family_bookmarks.get())
@ -1722,7 +1722,7 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.set_metadata('media_bookmarks', self.media_bookmarks.get())
self.set_metadata('place_bookmarks', self.place_bookmarks.get())
self.set_metadata('note_bookmarks', self.note_bookmarks.get())
# Custom type values, sets
self.set_metadata('event_names', self.event_names)
self.set_metadata('fattr_names', self.family_attributes)
@ -1741,7 +1741,7 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.set_metadata('mattr_names', self.media_attributes)
self.set_metadata('eattr_names', self.event_attributes)
self.set_metadata('place_types', self.place_types)
# Save misc items:
if self.has_changed:
self.save_surname_list()
@ -2004,7 +2004,7 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
if filename.count("-") == 6:
backup, year, month, day, hour, minute, second = filename.split("-")
last_backup = time.strftime('%x %X', time.localtime(time.mktime(
(int(year), int(month), int(day), int(hour), int(minute), int(second),
(int(year), int(month), int(day), int(hour), int(minute), int(second),
0, 0, 0))))
return {
_("Number of people"): self.get_number_of_people(),
@ -2042,12 +2042,14 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
pa/matronymic not as they change for every generation!
returns a byte string
"""
if person.primary_name and person.primary_name.surname_list:
order_by = " ".join([x.surname for x in person.primary_name.surname_list if not
(int(x.origintype) in [NameOriginType.PATRONYMIC,
NameOriginType.MATRONYMIC]) ])
else:
order_by = ""
order_by = ""
if person.primary_name:
order_by_list = [surname.surname + " " + person.primary_name.first_name
for surname in person.primary_name.surname_list
if not (int(surname.origintype) in
[NameOriginType.PATRONYMIC,
NameOriginType.MATRONYMIC])]
order_by = " ".join(order_by_list)
return glocale.sort_key(order_by)
def _order_by_place_key(self, place):

View File

@ -116,9 +116,24 @@ def find_fullname(key, data):
Creating a fullname from raw data of a person, to use for sort and index
returns a byte string
"""
# data[3] -> primary_name
# data[3][4] -> primary given
# data[3][5] -> surname_list
# data[3][5][0] -> primary surnameobj
# data[3][5][0][0] -> primary surname
# data[3][5][0][1] -> primary surname prefix
# data[3][5][0][2] -> primary surname primary (bool)
# data[3][5][0][3] -> primary surname origin type
# data[3][5][0][4] -> primary surname connector
# [(surname + ' ' + given,
# surname prefix,
# surname primary,
# surname origin type,
# surname connector)]
fullname_data = [(data[3][5][0][0] + ' ' + data[3][4], # surname givenname
data[3][5][0][1], data[3][5][0][2],
data[3][5][0][3], data[3][5][0][4])]
# ignore if origin type is PATRONYMIC or MATRONYMIC
return __index_surname(fullname_data)
def find_surname(key, data):
@ -126,6 +141,7 @@ def find_surname(key, data):
Creating a surname from raw data of a person, to use for sort and index
returns a byte string
"""
# data[3][5] -> surname_list
return __index_surname(data[3][5])
def find_surname_name(key, data):
@ -396,7 +412,7 @@ class DbBsddbRead(DbReadBase, Callback):
self.has_changed = False
self.__tables = {
'Person':
'Person':
{
"handle_func": self.get_person_from_handle,
"gramps_id_func": self.get_person_from_gramps_id,
@ -498,7 +514,7 @@ class DbBsddbRead(DbReadBase, Callback):
return self.__tables[table]
elif func in self.__tables[table].keys():
return self.__tables[table][func]
else:
else:
return super().get_table_func(table, func)
def set_prefixes(self, person, media, family, source, citation, place,

View File

@ -1227,6 +1227,7 @@ class DBAPI(DbGeneric):
def rebuild_secondary(self, update):
gstats = self.get_gender_stats()
self.genderStats = GenderStats(gstats)
## Rebuild place order_by:
self.dbapi.execute("""select blob_data from place;""")
row = self.dbapi.fetchone()
while row:
@ -1235,6 +1236,51 @@ class DBAPI(DbGeneric):
cur2 = self.dbapi.execute("""UPDATE place SET order_by = ? WHERE handle = ?;""",
[order_by, place.handle])
row = self.dbapi.fetchone()
## Rebuild person order_by:
self.dbapi.execute("""select blob_data from person;""")
row = self.dbapi.fetchone()
while row:
person = Person.create(pickle.loads(row[0]))
order_by = self._order_by_person_key(person)
cur2 = self.dbapi.execute("""UPDATE person SET order_by = ? WHERE handle = ?;""",
[order_by, person.handle])
row = self.dbapi.fetchone()
## Rebuild citation order_by:
self.dbapi.execute("""select blob_data from citation;""")
row = self.dbapi.fetchone()
while row:
citation = Citation.create(pickle.loads(row[0]))
order_by = self._order_by_citation_key(citation)
cur2 = self.dbapi.execute("""UPDATE citation SET order_by = ? WHERE handle = ?;""",
[order_by, citation.handle])
row = self.dbapi.fetchone()
## Rebuild source order_by:
self.dbapi.execute("""select blob_data from source;""")
row = self.dbapi.fetchone()
while row:
source = Source.create(pickle.loads(row[0]))
order_by = self._order_by_source_key(source)
cur2 = self.dbapi.execute("""UPDATE source SET order_by = ? WHERE handle = ?;""",
[order_by, source.handle])
row = self.dbapi.fetchone()
## Rebuild tag order_by:
self.dbapi.execute("""select blob_data from tag;""")
row = self.dbapi.fetchone()
while row:
tag = Tag.create(pickle.loads(row[0]))
order_by = self._order_by_tag_key(tag.name)
cur2 = self.dbapi.execute("""UPDATE tag SET order_by = ? WHERE handle = ?;""",
[order_by, tag.handle])
row = self.dbapi.fetchone()
## Rebuild media order_by:
self.dbapi.execute("""select blob_data from media;""")
row = self.dbapi.fetchone()
while row:
media = Media.create(pickle.loads(row[0]))
order_by = self._order_by_media_key(media)
cur2 = self.dbapi.execute("""UPDATE media SET order_by = ? WHERE handle = ?;""",
[order_by, media.handle])
row = self.dbapi.fetchone()
def has_handle_for_person(self, key):
if isinstance(key, bytes):