Skip to content

Commit

Permalink
Peoplemodel mostly working
Browse files Browse the repository at this point in the history
  • Loading branch information
dsblank committed Oct 12, 2024
1 parent c014c15 commit 43ea2b2
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 99 deletions.
23 changes: 12 additions & 11 deletions gramps/gen/db/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
Source,
Tag,
)
from ..lib.serialize import from_dict
from ..lib.genderstats import GenderStats
from ..lib.researcher import Researcher
from ..updatecallback import UpdateCallback
Expand Down Expand Up @@ -1355,7 +1356,7 @@ def _get_from_handle(self, obj_key, obj_class, handle):
raise HandleError("Handle is empty")
data = self._get_raw_data(obj_key, handle)
if data:
return obj_class.create(data)
return from_dict(data)
raise HandleError(f"Handle {handle} not found")

def get_event_from_handle(self, handle):
Expand Down Expand Up @@ -1396,39 +1397,39 @@ def get_tag_from_handle(self, handle):

def get_person_from_gramps_id(self, gramps_id):
data = self._get_raw_person_from_id_data(gramps_id)
return Person.create(data)
return from_dict(data)

def get_family_from_gramps_id(self, gramps_id):
data = self._get_raw_family_from_id_data(gramps_id)
return Family.create(data)
return from_dict(data)

def get_citation_from_gramps_id(self, gramps_id):
data = self._get_raw_citation_from_id_data(gramps_id)
return Citation.create(data)
return from_dict(data)

def get_source_from_gramps_id(self, gramps_id):
data = self._get_raw_source_from_id_data(gramps_id)
return Source.create(data)
return from_dict(data)

def get_event_from_gramps_id(self, gramps_id):
data = self._get_raw_event_from_id_data(gramps_id)
return Event.create(data)
return from_dict(data)

def get_media_from_gramps_id(self, gramps_id):
data = self._get_raw_media_from_id_data(gramps_id)
return Media.create(data)
return from_dict(data)

def get_place_from_gramps_id(self, gramps_id):
data = self._get_raw_place_from_id_data(gramps_id)
return Place.create(data)
return from_dict(data)

def get_repository_from_gramps_id(self, gramps_id):
data = self._get_raw_repository_from_id_data(gramps_id)
return Repository.create(data)
return from_dict(data)

def get_note_from_gramps_id(self, gramps_id):
data = self._get_raw_note_from_id_data(gramps_id)
return Note.create(data)
return from_dict(data)

################################################################
#
Expand Down Expand Up @@ -1629,7 +1630,7 @@ def _iter_objects(self, class_):
"""
cursor = self._get_table_func(class_.__name__, "cursor_func")
for data in cursor():
yield class_.create(data[1])
yield from_dict(data[1])

def iter_people(self):
return self._iter_objects(Person)
Expand Down
82 changes: 42 additions & 40 deletions gramps/gen/display/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,25 @@
# Constants
#
# -------------------------------------------------------------------------
_FIRSTNAME = 4
_SURNAME_LIST = 5
_SUFFIX = 6
_TITLE = 7
_TYPE = 8
_GROUP = 9
_SORT = 10
_DISPLAY = 11
_CALL = 12
_NICK = 13
_FAMNICK = 14
_SURNAME_IN_LIST = 0
_PREFIX_IN_LIST = 1
_PRIMARY_IN_LIST = 2
_TYPE_IN_LIST = 3
_CONNECTOR_IN_LIST = 4
_ORIGINPATRO = NameOriginType.PATRONYMIC
_ORIGINMATRO = NameOriginType.MATRONYMIC
_FIRSTNAME = "first_name"
_SURNAME_LIST = "surname_list"
_SUFFIX = "suffix"
_TITLE = "title"
_TYPE = "type"
_GROUP = "group_as"
_SORT = "sort_as"
_DISPLAY = "display_as"
_CALL = "call"
_NICK = "nick"
_FAMNICK = "famnick"
_SURNAME_IN_LIST = "surname"
_PREFIX_IN_LIST = "prefix"
_PRIMARY_IN_LIST = "primary"
_TYPE_IN_LIST = "origintype"
_CONNECTOR_IN_LIST = "connector"
# FIXME: question: are these translated? Hope not!
_ORIGINPATRO = "Patronymic" # NameOriginType.PATRONYMIC
_ORIGINMATRO = "Matronymic" # NameOriginType.MATRONYMIC

_ACT = True
_INA = False
Expand Down Expand Up @@ -131,7 +132,6 @@
def _make_cmp_key(a):
return (len(a[1]), a[1]) # set reverse to True!!


# -------------------------------------------------------------------------
#
# NameDisplayError class
Expand Down Expand Up @@ -179,8 +179,8 @@ def _raw_primary_surname(raw_surn_data_list):
not PAT_AS_SURN
and nrsur == 1
and (
raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINMATRO
raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINMATRO
)
):
return ""
Expand All @@ -199,8 +199,8 @@ def _raw_primary_surname_only(raw_surn_data_list):
not PAT_AS_SURN
and nrsur == 1
and (
raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINMATRO
raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINMATRO
)
):
return ""
Expand All @@ -219,8 +219,8 @@ def _raw_primary_prefix_only(raw_surn_data_list):
not PAT_AS_SURN
and nrsur == 1
and (
raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINMATRO
raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINMATRO
)
):
return ""
Expand All @@ -239,8 +239,8 @@ def _raw_primary_conn_only(raw_surn_data_list):
not PAT_AS_SURN
and nrsur == 1
and (
raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINMATRO
raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINMATRO
)
):
return ""
Expand All @@ -253,8 +253,8 @@ def _raw_patro_surname(raw_surn_data_list):
"""method for the 'y' symbol: patronymic surname"""
for raw_surn_data in raw_surn_data_list:
if (
raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINMATRO
raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINMATRO
):
return __format_raw_surname(raw_surn_data).strip()
return ""
Expand All @@ -264,8 +264,8 @@ def _raw_patro_surname_only(raw_surn_data_list):
"""method for the '1y' symbol: patronymic surname only"""
for raw_surn_data in raw_surn_data_list:
if (
raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINMATRO
raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINMATRO
):
result = "%s" % (raw_surn_data[_SURNAME_IN_LIST])
return " ".join(result.split())
Expand All @@ -276,8 +276,8 @@ def _raw_patro_prefix_only(raw_surn_data_list):
"""method for the '0y' symbol: patronymic prefix only"""
for raw_surn_data in raw_surn_data_list:
if (
raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINMATRO
raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINMATRO
):
result = "%s" % (raw_surn_data[_PREFIX_IN_LIST])
return " ".join(result.split())
Expand All @@ -288,8 +288,8 @@ def _raw_patro_conn_only(raw_surn_data_list):
"""method for the '2y' symbol: patronymic conn only"""
for raw_surn_data in raw_surn_data_list:
if (
raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST][0] == _ORIGINMATRO
raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINPATRO
or raw_surn_data[_TYPE_IN_LIST]["string"] == _ORIGINMATRO
):
result = "%s" % (raw_surn_data[_CONNECTOR_IN_LIST])
return " ".join(result.split())
Expand All @@ -304,8 +304,8 @@ def _raw_nonpatro_surname(raw_surn_data_list):
for raw_surn_data in raw_surn_data_list:
if (
(not raw_surn_data[_PRIMARY_IN_LIST])
and raw_surn_data[_TYPE_IN_LIST][0] != _ORIGINPATRO
and raw_surn_data[_TYPE_IN_LIST][0] != _ORIGINMATRO
and raw_surn_data[_TYPE_IN_LIST]["string"] != _ORIGINPATRO
and raw_surn_data[_TYPE_IN_LIST]["string"] != _ORIGINMATRO
):
result += __format_raw_surname(raw_surn_data)
return result.strip()
Expand Down Expand Up @@ -859,6 +859,8 @@ def fn(first, raw_surname_list, suffix, title, call,):
return self._make_fn(format_str, d, args)

def format_str(self, name, format_str):
# FIXME: edit the raw format functions
return "XXX"
return self._format_str_base(
name.first_name,
name.surname_list,
Expand Down Expand Up @@ -1151,12 +1153,12 @@ def name_grouping_data(self, db, pn):
if not name:
# if we have no primary surname, perhaps we have a
# patronymic/matronynic name ?
srnme = pn[_ORIGINPATRO]
srnme = pn["surname_list"]
surname = []
for _surname in srnme:
if (
_surname[_TYPE_IN_LIST][0] == _ORIGINPATRO
or _surname[_TYPE_IN_LIST][0] == _ORIGINMATRO
_surname[_TYPE_IN_LIST]["string"] == _ORIGINPATRO
or _surname[_TYPE_IN_LIST]["string"] == _ORIGINMATRO
):
# Yes, we have one.
surname = [_surname]
Expand Down
Loading

0 comments on commit 43ea2b2

Please sign in to comment.