Skip to content

Commit fdb0d4b

Browse files
A straightforward implementation of #673 : added webarg "name_format"… (#674)
* A straightforward implementation of #673 : added webarg "name_format", a "name_display" field to the person profile, and initialization code using gramps.gen.display.name displayer * #673 corrected type hint for the name_format argument * #673 roll back from using default displayer - created a new instance of NameDisplay with locale that comes from request + some code cleanup * #673 used another style for type hint * #673 - updated test cases related to profile * #673 Added name_format webarg to GrampsObject_resource * #673 added simple test for name_format argument present in the query * #673 now passing the name_format argument starting from the HTTP GET handlers to all the get_%s_profile_for_object and get_%s_profile_for_handle for %s in "person", "family", "event" and "timeline". Added couple of tests for correct name_display and updated apispec.yaml * #673 typos corrected * #673 added name_format argument to some function calls --------- Co-authored-by: David Straub <[email protected]>
1 parent 6739fa3 commit fdb0d4b

File tree

11 files changed

+405
-31
lines changed

11 files changed

+405
-31
lines changed

gramps_webapi/api/resources/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ def full_object(self, obj: T, args: dict, locale: GrampsLocale = glocale) -> T:
9898
# create profile if doesn't exist
9999
obj.profile = {}
100100
obj.profile["references"] = get_reference_profile_for_object(
101-
self.db_handle, obj, locale=locale
101+
self.db_handle,
102+
obj,
103+
locale=locale,
104+
name_format=args.get("name_format"),
102105
)
103106
return obj
104107

@@ -207,6 +210,7 @@ class GrampsObjectResource(GrampsObjectResourceHelper, Resource):
207210
"locale": fields.Str(
208211
load_default=None, validate=validate.Length(min=1, max=5)
209212
),
213+
"name_format": fields.Str(validate=validate.Length(min=1)),
210214
"profile": fields.DelimitedList(
211215
fields.Str(validate=validate.Length(min=1)),
212216
validate=validate.ContainsOnly(
@@ -373,6 +377,7 @@ class GrampsObjectsResource(GrampsObjectResourceHelper, Resource):
373377
"soundex": fields.Boolean(load_default=False),
374378
"strip": fields.Boolean(load_default=False),
375379
"filemissing": fields.Boolean(load_default=False),
380+
"name_format": fields.Str(validate=validate.Length(min=1)),
376381
},
377382
location="query",
378383
)

gramps_webapi/api/resources/events.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ def object_extend(
6464
if "families" in args["profile"] or "events" in args["profile"]:
6565
abort_with_message(422, "profile contains invalid keys")
6666
obj.profile = get_event_profile_for_object(
67-
db_handle, obj, args["profile"], locale=locale
67+
db_handle,
68+
obj,
69+
args["profile"],
70+
locale=locale,
71+
name_format=args.get("name_format"),
6872
)
6973
return obj
7074

gramps_webapi/api/resources/families.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def object_extend(
5454
db_handle = self.db_handle
5555
if "profile" in args:
5656
obj.profile = get_family_profile_for_object(
57-
db_handle, obj, args["profile"], locale=locale
57+
db_handle,
58+
obj,
59+
args["profile"],
60+
locale=locale,
61+
name_format=args.get("name_format"),
5862
)
5963
if "extend" in args:
6064
obj.extended = get_extended_attributes(db_handle, obj, args)

gramps_webapi/api/resources/people.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ def object_extend(
5050
db_handle = self.db_handle
5151
if "profile" in args:
5252
obj.profile = get_person_profile_for_object(
53-
db_handle, obj, args["profile"], locale=locale
53+
db_handle,
54+
obj,
55+
args["profile"],
56+
locale=locale,
57+
name_format=args.get("name_format"),
5458
)
5559
if "extend" in args:
5660
obj.extended = get_extended_attributes(db_handle, obj, args)

gramps_webapi/api/resources/search.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,27 @@ def get_object_from_handle(
8787
if "profile" in args:
8888
if class_name == "person":
8989
obj.profile = get_person_profile_for_object(
90-
self.db_handle, obj, args["profile"], locale=locale
90+
self.db_handle,
91+
obj,
92+
args["profile"],
93+
locale=locale,
94+
name_format=args.get("name_format"),
9195
)
9296
elif class_name == "family":
9397
obj.profile = get_family_profile_for_object(
94-
self.db_handle, obj, args["profile"], locale=locale
98+
self.db_handle,
99+
obj,
100+
args["profile"],
101+
locale=locale,
102+
name_format=args.get("name_format"),
95103
)
96104
elif class_name == "event":
97105
obj.profile = get_event_profile_for_object(
98-
self.db_handle, obj, args["profile"], locale=locale
106+
self.db_handle,
107+
obj,
108+
args["profile"],
109+
locale=locale,
110+
name_format=args.get("name_format"),
99111
)
100112
elif class_name == "citation":
101113
obj.profile = get_citation_profile_for_object(

gramps_webapi/api/resources/timeline.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __init__(
109109
omit_anchor: bool = True,
110110
precision: int = 1,
111111
locale: GrampsLocale = glocale,
112+
name_format: Optional[str] = None,
112113
):
113114
"""Initialize timeline."""
114115
self.db_handle = db_handle
@@ -131,6 +132,7 @@ def __init__(
131132
self.set_event_filters(self.event_filters)
132133
self.set_relative_event_filters(self.relative_event_filters)
133134
self.birth_dates: Dict[str, Date] = {}
135+
self.name_format = name_format
134136

135137
if dates and "-" in dates:
136138
start, end = dates.split("-")
@@ -465,7 +467,11 @@ def profile(self, page=0, pagesize=20):
465467
get_person = False
466468
if get_person:
467469
person = get_person_profile_for_object(
468-
self.db_handle, person_object, {}, locale=self.locale
470+
self.db_handle,
471+
person_object,
472+
[],
473+
locale=self.locale,
474+
name_format=self.name_format,
469475
)
470476
if not person_age and person_object.handle in self.birth_dates:
471477
person_age = self.get_age(
@@ -534,6 +540,7 @@ class PersonTimelineResource(ProtectedResource, GrampsJSONEncoder):
534540
"keys": fields.DelimitedList(fields.Str(validate=validate.Length(min=1))),
535541
"last": fields.Boolean(load_default=True),
536542
"locale": fields.Str(load_default=None),
543+
"name_format": fields.Str(validate=validate.Length(min=1)),
537544
"offspring": fields.Integer(
538545
load_default=1, validate=validate.Range(min=1, max=5)
539546
),
@@ -626,12 +633,14 @@ class FamilyTimelineResource(ProtectedResource, GrampsJSONEncoder):
626633
"events": fields.DelimitedList(fields.Str(validate=validate.Length(min=1))),
627634
"keys": fields.DelimitedList(fields.Str(validate=validate.Length(min=1))),
628635
"locale": fields.Str(load_default=None),
636+
"name_format": fields.Str(validate=validate.Length(min=1)),
629637
"page": fields.Integer(load_default=0, validate=validate.Range(min=1)),
630638
"pagesize": fields.Integer(load_default=20, validate=validate.Range(min=1)),
631639
"ratings": fields.Boolean(load_default=False),
632640
"skipkeys": fields.DelimitedList(
633641
fields.Str(validate=validate.Length(min=1))
634642
),
643+
"keys": fields.DelimitedList(fields.Str(validate=validate.Length(min=1))),
635644
"strip": fields.Boolean(load_default=False),
636645
},
637646
location="query",
@@ -648,6 +657,7 @@ def get(self, args: Dict, handle: str):
648657
ratings=args["ratings"],
649658
discard_empty=args["discard_empty"],
650659
locale=locale,
660+
name_format=args.get("name_format"),
651661
)
652662
timeline.add_family(Handle(handle))
653663
except ValueError:
@@ -720,6 +730,7 @@ def get(self, args: Dict):
720730
omit_anchor=args["omit_anchor"],
721731
precision=args["precision"],
722732
locale=locale,
733+
name_format=args.get("name_format"),
723734
)
724735
if "anchor" in args:
725736
timeline.add_person(
@@ -801,6 +812,7 @@ def get(self, args: Dict):
801812
ratings=args["ratings"],
802813
discard_empty=args["discard_empty"],
803814
locale=locale,
815+
name_format=args.get("name_format"),
804816
)
805817
except ValueError:
806818
abort(422)

0 commit comments

Comments
 (0)