Skip to content

Commit 1ddb7f3

Browse files
authored
Format and return alternate_place_names (#608)
* Format and return alternate_place_names * Add test
1 parent 56e4545 commit 1ddb7f3

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

gramps_webapi/api/resources/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@ def get_place_profile_for_object(
386386
"alternate_names": [
387387
place_name.value for place_name in place.get_alternative_names()
388388
],
389+
"alternate_place_names": [
390+
{
391+
"value": place_name.value,
392+
"date_str": locale.date_displayer.display(place_name.date),
393+
}
394+
for place_name in place.get_alternative_names()
395+
],
389396
"lat": float(latitude) if (latitude and longitude) else None,
390397
"long": float(longitude) if (latitude and longitude) else None,
391398
}

tests/test_endpoints/test_places.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,15 @@ def test_get_places_handle_parameter_profile(self):
504504
rv["profile"],
505505
{
506506
"alternate_names": [],
507+
"alternate_place_names": [],
507508
"gramps_id": "P0860",
508509
"lat": 33.6259414,
509510
"long": -97.1333453,
510511
"name": "Gainesville",
511512
"parent_places": [
512513
{
513514
"alternate_names": [],
515+
"alternate_place_names": [],
514516
"gramps_id": "P0194",
515517
"lat": 0,
516518
"long": 0,
@@ -519,6 +521,7 @@ def test_get_places_handle_parameter_profile(self):
519521
},
520522
{
521523
"alternate_names": [],
524+
"alternate_place_names": [],
522525
"gramps_id": "P0010",
523526
"lat": 0,
524527
"long": 0,
@@ -527,6 +530,7 @@ def test_get_places_handle_parameter_profile(self):
527530
},
528531
{
529532
"alternate_names": [],
533+
"alternate_place_names": [],
530534
"gramps_id": "P0957",
531535
"lat": 0,
532536
"long": 0,
@@ -538,6 +542,43 @@ def test_get_places_handle_parameter_profile(self):
538542
},
539543
)
540544

545+
def test_get_places_handle_parameter_profile_alternative_names(self):
546+
"""Test place profile."""
547+
rv = check_success(
548+
self, TEST_URL + "fce62795df51c5d8ae432e3942c?profile=all&locale=en"
549+
)
550+
self.maxDiff = None
551+
self.assertEqual(
552+
rv["profile"],
553+
{
554+
"alternate_names": ["Leningrad", "Petrograd"],
555+
"alternate_place_names": [
556+
{
557+
"date_str": "between 1924-01-26 and 1991-09-06",
558+
"value": "Leningrad",
559+
},
560+
{"date_str": "between 1914 and 1924", "value": "Petrograd"},
561+
],
562+
"gramps_id": "P0443",
563+
"lat": 0,
564+
"long": 0,
565+
"name": "Saint Petersburg",
566+
"parent_places": [
567+
{
568+
"alternate_names": [],
569+
"alternate_place_names": [],
570+
"gramps_id": "P0442",
571+
"lat": 0,
572+
"long": 0,
573+
"name": "Russia",
574+
"type": "Country",
575+
},
576+
],
577+
"references": {},
578+
"type": "City",
579+
},
580+
)
581+
541582
def test_get_places_handle_parameter_backlinks_validate_semantics(self):
542583
"""Test invalid backlinks parameter and values."""
543584
check_invalid_semantics(

0 commit comments

Comments
 (0)