Skip to content

Commit d6dbafc

Browse files
authored
Add place_name key to event profile (#658)
1 parent 1dd2450 commit d6dbafc

File tree

6 files changed

+84
-1
lines changed

6 files changed

+84
-1
lines changed

gramps_webapi/api/resources/util.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def get_event_profile_for_object(
247247
"type": locale.translation.sgettext(event.type.xml_str()),
248248
"date": locale.date_displayer.display(event.date),
249249
"place": pd.display_event(db_handle, event),
250+
"place_name": get_place_name_for_event(db_handle, event),
250251
"summary": get_event_summary_from_object(db_handle, event, locale=locale),
251252
}
252253
if role is not None:
@@ -268,6 +269,23 @@ def get_event_profile_for_object(
268269
return result
269270

270271

272+
def get_place_name_for_event(db_handle: DbReadBase, event: Event) -> str:
273+
"""Get place name for an event."""
274+
place_handle = event.get_place_handle()
275+
if not place_handle:
276+
return ""
277+
try:
278+
place: Place = db_handle.get_place_from_handle(place_handle)
279+
except HandleError:
280+
return ""
281+
if not place:
282+
return ""
283+
place_name = place.get_name()
284+
if not place_name:
285+
return ""
286+
return place_name.value
287+
288+
271289
def get_event_profile_for_handle(
272290
db_handle: DbReadBase,
273291
handle: Handle,

gramps_webapi/data/apispec.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8449,6 +8449,10 @@ definitions:
84498449
description: "Place of the event."
84508450
type: string
84518451
example: "Great Falls, MT, USA"
8452+
place_name:
8453+
description: "Name of the event's place."
8454+
type: string
8455+
example: "Great Falls"
84528456
type:
84538457
description: "Type of the event."
84548458
type: string

tests/test_endpoints/test_events.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def test_get_events_parameter_profile_expected_result(self):
379379
"confidence": 0,
380380
"date": "1987-08-29",
381381
"place": "Gainesville, Llano, TX, USA",
382+
"place_name": "Gainesville",
382383
"type": "Birth",
383384
"summary": "Birth - Warner, Sarah Suzanne",
384385
"participants": {
@@ -389,6 +390,7 @@ def test_get_events_parameter_profile_expected_result(self):
389390
"birth": {
390391
"date": "1987-08-29",
391392
"place": "Gainesville, Llano, TX, USA",
393+
"place_name": "Gainesville",
392394
"type": "Birth",
393395
"summary": "Birth - Warner, Sarah Suzanne",
394396
},
@@ -410,6 +412,7 @@ def test_get_events_parameter_profile_expected_result(self):
410412
"birth": {
411413
"date": "1987-08-29",
412414
"place": "Gainesville, Llano, TX, USA",
415+
"place_name": "Gainesville",
413416
"type": "Birth",
414417
"summary": "Birth - Warner, Sarah Suzanne",
415418
},
@@ -635,6 +638,7 @@ def test_get_events_handle_parameter_profile_expected_result(self):
635638
"confidence": 0,
636639
"date": "1250",
637640
"place": "Atchison, Atchison, KS, USA",
641+
"place_name": "Atchison",
638642
"type": "Birth",
639643
"summary": "Birth - Knudsen, Ralph",
640644
"participants": {
@@ -645,12 +649,14 @@ def test_get_events_handle_parameter_profile_expected_result(self):
645649
"birth": {
646650
"date": "1250",
647651
"place": "Atchison, Atchison, KS, USA",
652+
"place_name": "Atchison",
648653
"type": "Birth",
649654
"summary": "Birth - Knudsen, Ralph",
650655
},
651656
"death": {
652657
"date": "1316",
653658
"place": "",
659+
"place_name": "",
654660
"type": "Death",
655661
"summary": "Death - Knudsen, Ralph",
656662
},
@@ -671,12 +677,14 @@ def test_get_events_handle_parameter_profile_expected_result(self):
671677
"birth": {
672678
"date": "1250",
673679
"place": "Atchison, Atchison, KS, USA",
680+
"place_name": "Atchison",
674681
"type": "Birth",
675682
"summary": "Birth - Knudsen, Ralph",
676683
},
677684
"death": {
678685
"date": "1316",
679686
"place": "",
687+
"place_name": "",
680688
"type": "Death",
681689
"summary": "Death - Knudsen, Ralph",
682690
},
@@ -686,7 +694,7 @@ def test_get_events_handle_parameter_profile_expected_result(self):
686694
"name_surname": "Knudsen",
687695
"name_suffix": "",
688696
"sex": "M",
689-
},
697+
}
690698
],
691699
},
692700
},
@@ -702,6 +710,7 @@ def test_get_events_handle_parameter_profile_expected_result_with_locale(self):
702710
"confidence": 0,
703711
"date": "1250",
704712
"place": "Atchison, Atchison, KS, USA",
713+
"place_name": "Atchison",
705714
"type": "Geburt",
706715
"summary": "Geburt - Knudsen, Ralph",
707716
"participants": {
@@ -712,12 +721,14 @@ def test_get_events_handle_parameter_profile_expected_result_with_locale(self):
712721
"birth": {
713722
"date": "1250",
714723
"place": "Atchison, Atchison, KS, USA",
724+
"place_name": "Atchison",
715725
"type": "Geburt",
716726
"summary": "Geburt - Knudsen, Ralph",
717727
},
718728
"death": {
719729
"date": "1316",
720730
"place": "",
731+
"place_name": "",
721732
"type": "Tod",
722733
"summary": "Tod - Knudsen, Ralph",
723734
},
@@ -738,12 +749,14 @@ def test_get_events_handle_parameter_profile_expected_result_with_locale(self):
738749
"birth": {
739750
"date": "1250",
740751
"place": "Atchison, Atchison, KS, USA",
752+
"place_name": "Atchison",
741753
"type": "Geburt",
742754
"summary": "Geburt - Knudsen, Ralph",
743755
},
744756
"death": {
745757
"date": "1316",
746758
"place": "",
759+
"place_name": "",
747760
"type": "Tod",
748761
"summary": "Tod - Knudsen, Ralph",
749762
},

tests/test_endpoints/test_families.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ def test_get_families_parameter_profile_expected_result(self):
423423
"confidence": 0,
424424
"date": "203 (Islamic)",
425425
"place": "",
426+
"place_name": "",
426427
"type": "Birth",
427428
"summary": "Birth - , صالح",
428429
},
@@ -445,6 +446,7 @@ def test_get_families_parameter_profile_expected_result(self):
445446
"confidence": 0,
446447
"date": "164-03 (Islamic)",
447448
"place": "",
449+
"place_name": "",
448450
"type": "Birth",
449451
"summary": "Birth - , أحمد",
450452
},
@@ -454,6 +456,7 @@ def test_get_families_parameter_profile_expected_result(self):
454456
"confidence": 0,
455457
"date": "241-03-12 (Islamic)",
456458
"place": "",
459+
"place_name": "",
457460
"type": "Death",
458461
"summary": "Death - , أحمد",
459462
},
@@ -474,6 +477,7 @@ def test_get_families_parameter_profile_expected_result(self):
474477
"confidence": 0,
475478
"date": "234 (Islamic)",
476479
"place": "",
480+
"place_name": "",
477481
"type": "Death",
478482
"summary": "Death - الفضل, العباسة",
479483
},
@@ -490,12 +494,14 @@ def test_get_families_parameter_profile_expected_result(self):
490494
"birth": {
491495
"date": "164-03 (Islamic)",
492496
"place": "",
497+
"place_name": "",
493498
"type": "Birth",
494499
"summary": "Birth - , أحمد",
495500
},
496501
"death": {
497502
"date": "241-03-12 (Islamic)",
498503
"place": "",
504+
"place_name": "",
499505
"type": "Death",
500506
"summary": "Death - , أحمد",
501507
},
@@ -511,6 +517,7 @@ def test_get_families_parameter_profile_expected_result(self):
511517
"death": {
512518
"date": "234 (Islamic)",
513519
"place": "",
520+
"place_name": "",
514521
"type": "Death",
515522
"summary": "Death - الفضل, العباسة",
516523
},
@@ -525,6 +532,7 @@ def test_get_families_parameter_profile_expected_result(self):
525532
"birth": {
526533
"date": "203 (Islamic)",
527534
"place": "",
535+
"place_name": "",
528536
"type": "Birth",
529537
"summary": "Birth - , صالح",
530538
},
@@ -781,6 +789,7 @@ def test_get_families_handle_parameter_profile_expected_result(self):
781789
"confidence": 0,
782790
"date": "1983-10-05",
783791
"place": "Ottawa, La Salle, IL, USA",
792+
"place_name": "Ottawa",
784793
"type": "Birth",
785794
"summary": "Birth - Garner, Stephen Gerard",
786795
},
@@ -799,6 +808,7 @@ def test_get_families_handle_parameter_profile_expected_result(self):
799808
"confidence": 0,
800809
"date": "1985-02-11",
801810
"place": "Ottawa, La Salle, IL, USA",
811+
"place_name": "Ottawa",
802812
"type": "Birth",
803813
"summary": "Birth - Garner, Daniel Patrick",
804814
},
@@ -818,6 +828,7 @@ def test_get_families_handle_parameter_profile_expected_result(self):
818828
"confidence": 0,
819829
"date": "1979-01-06",
820830
"place": "Farmington, MO, USA",
831+
"place_name": "Farmington",
821832
"span": "0 days",
822833
"type": "Marriage",
823834
"summary": "Marriage - Garner, Gerard Stephen and George, Elizabeth",
@@ -831,6 +842,7 @@ def test_get_families_handle_parameter_profile_expected_result(self):
831842
"confidence": 0,
832843
"date": "1955-07-31",
833844
"place": "Ottawa, La Salle, IL, USA",
845+
"place_name": "Ottawa",
834846
"type": "Birth",
835847
"summary": "Birth - Garner, Gerard Stephen",
836848
},
@@ -849,6 +861,7 @@ def test_get_families_handle_parameter_profile_expected_result(self):
849861
"confidence": 0,
850862
"date": "1979-01-06",
851863
"place": "Farmington, MO, USA",
864+
"place_name": "Farmington",
852865
"span": "0 days",
853866
"type": "Marriage",
854867
"summary": "Marriage - Garner, Gerard Stephen and George, Elizabeth",
@@ -860,6 +873,7 @@ def test_get_families_handle_parameter_profile_expected_result(self):
860873
"confidence": 0,
861874
"date": "1957-01-31",
862875
"place": "",
876+
"place_name": "",
863877
"type": "Birth",
864878
"summary": "Birth - George, Elizabeth",
865879
},
@@ -877,6 +891,7 @@ def test_get_families_handle_parameter_profile_expected_result(self):
877891
"birth": {
878892
"date": "1983-10-05",
879893
"place": "Ottawa, La Salle, IL, USA",
894+
"place_name": "Ottawa",
880895
"type": "Birth",
881896
"summary": "Birth - Garner, Stephen Gerard",
882897
},
@@ -892,6 +907,7 @@ def test_get_families_handle_parameter_profile_expected_result(self):
892907
"birth": {
893908
"date": "1985-02-11",
894909
"place": "Ottawa, La Salle, IL, USA",
910+
"place_name": "Ottawa",
895911
"type": "Birth",
896912
"summary": "Birth - Garner, Daniel Patrick",
897913
},
@@ -907,6 +923,7 @@ def test_get_families_handle_parameter_profile_expected_result(self):
907923
"birth": {
908924
"date": "1957-01-31",
909925
"place": "",
926+
"place_name": "",
910927
"type": "Birth",
911928
"summary": "Birth - George, Elizabeth",
912929
},
@@ -922,6 +939,7 @@ def test_get_families_handle_parameter_profile_expected_result(self):
922939
"birth": {
923940
"date": "1955-07-31",
924941
"place": "Ottawa, La Salle, IL, USA",
942+
"place_name": "Ottawa",
925943
"type": "Birth",
926944
"summary": "Birth - Garner, Gerard Stephen",
927945
},

0 commit comments

Comments
 (0)