Narrative web: Solves some problems

Force place name to be "Full" names.
Force the country field to be the last field of the place name
Force the State/province to be the penultimate field of the place name

We use place names that stop in the country, but iff we have place names
such as: city, province, country, continent, planet with the continent and
planet as the custom place type, the State/Province field will be
the name of the place continent... (should never happen, but...)

Fixes #12821
This commit is contained in:
SNoiraud 2023-02-19 14:07:50 +01:00 committed by Nick Hall
parent 09fd85ef09
commit 35f20a8893
6 changed files with 67 additions and 27 deletions

View File

@ -881,7 +881,7 @@ class BasePage:
found = any(data[3] == place_handle and data[4] == event_date
for data in place_lat_long)
if not found:
placetitle = _pd.display(self.r_db, place)
placetitle = _pd.display(self.r_db, place, fmt=0)
latitude = place.get_latitude()
longitude = place.get_longitude()
if latitude and longitude:
@ -1012,7 +1012,8 @@ class BasePage:
place_hyper = None
if place:
place_name = _pd.display(self.r_db, place, evt.get_date_object())
place_name = _pd.display(self.r_db, place,
evt.get_date_object(), fmt=0)
place_hyper = self.place_link(place_handle, place_name,
uplink=uplink)
@ -1076,7 +1077,7 @@ class BasePage:
if place_handle:
place = self.r_db.get_place_from_handle(place_handle)
if place:
place_title = _pd.display(self.r_db, place)
place_title = _pd.display(self.r_db, place, fmt=0)
place_hyper = self.place_link(
place_handle, place_title,
place.get_gramps_id(), uplink=True)
@ -2165,7 +2166,7 @@ class BasePage:
"evt", True)
elif classname == "Place":
_obj = self.r_db.get_place_from_handle(newhandle)
_name = _pd.display(self.r_db, _obj)
_name = _pd.display(self.r_db, _obj, fmt=0)
if not _name:
_name = self._("Unknown")
_linkurl = self.report.build_url_fname_html(newhandle,

View File

@ -513,14 +513,18 @@ def sort_places(dbase, handle_list, rlocale=glocale):
pname_sub = defaultdict(list)
for place_name in handle_list.keys():
cname = sname = None
if len(handle_list[place_name]) == 4:
(hdle, pname, dummy_id, event) = handle_list[place_name]
else:
(hdle, pname, cname,
sname, dummy_id, event) = handle_list[place_name]
place = dbase.get_place_from_handle(hdle)
pname = _pd.display(dbase, place)
apname = _pd.display_event(dbase, event)
pname = _pd.display(dbase, place, fmt=0)
apname = _pd.display_event(dbase, event, fmt=0)
pname_sub[pname].append(hdle)
if pname != apname:
pname_sub[apname].append(hdle)
pname_sub[apname].append((hdle, pname, cname, sname))
sorted_lists = []
temp_list = sorted(pname_sub, key=rlocale.sort_key)

View File

@ -441,6 +441,7 @@ class FamilyPages(BasePage):
relationshipdetail += families
# display additional images as gallery
if self.create_media:
addgallery = self.disp_add_img_as_gallery(media_list, family)
if addgallery:
relationshipdetail += addgallery

View File

@ -939,11 +939,20 @@ class NavWebReport(Report):
else:
name = ""
if config.get('preferences.place-auto'):
place_name = _pd.display_event(self._db, event)
pplace_name = _pd.display(self._db, place)
place_name = _pd.display_event(self._db, event, fmt=0)
if event:
cplace_name = place_name.split()[-1]
if len(place_name.split()) > 1:
splace_name = place_name.split()[-2]
else:
splace_name = cplace_name
else:
cplace_name = None
splace_name = None
else:
place_name = place.get_title()
pplace_name = place_name
cplace_name = place_name
splace_name = place_name
if event:
if self.reference_sort:
role_or_date = name
@ -961,9 +970,7 @@ class NavWebReport(Report):
self.obj_dict[Place][place_handle] = (place_fname, place_name,
place.gramps_id, event)
self.obj_dict[PlaceName][place_name] = (place_handle, place_name,
place.gramps_id, event)
if place_name != pplace_name:
self.obj_dict[PlaceName][pplace_name] = (place_handle, pplace_name,
splace_name, cplace_name,
place.gramps_id, event)
self.bkref_dict[Place][place_handle].add((bkref_class, bkref_handle,
role_or_date

View File

@ -1703,14 +1703,14 @@ class PersonPages(BasePage):
birth = self.r_db.get_event_from_handle(birth_ref.ref)
if birth:
birth_date = birth.get_date_object()
p_birth = _pd.display_event(self.r_db, birth)
p_birth = _pd.display_event(self.r_db, birth, fmt=0)
death_ref = self.person.get_death_ref()
p_death = ""
if death_ref:
death = self.r_db.get_event_from_handle(death_ref.ref)
if death:
p_death = _pd.display_event(self.r_db, death)
p_death = _pd.display_event(self.r_db, death, fmt=0)
death_date = _find_death_date(self.r_db, self.person)
if birth_date and birth_date is not Date.EMPTY:

View File

@ -144,7 +144,7 @@ class PlacePages(BasePage):
plc_dict = (p_fname, place_name,
place.gramps_id, None)
self.report.obj_dict[Place][place_ref] = plc_dict
p_name = _pd.display(self.r_db, place)
p_name = _pd.display(self.r_db, place, fmt=0)
plc_dict = (place_ref, p_name,
place.gramps_id, None)
self.report.obj_dict[PlaceName][p_name] = plc_dict
@ -163,13 +163,22 @@ class PlacePages(BasePage):
self.placelistpage(self.report, the_lang, the_title)
def __output_place(self, ldatec, tbody,
first_place, pname, place_handle, letter, bucket_link):
def __output_place(self, ldatec, tbody, first_place,
pname, sname, cname, place_handle, letter, bucket_link):
place = self.r_db.get_place_from_handle(place_handle)
if place:
if place.get_change_time() > ldatec:
ldatec = place.get_change_time()
nbrs = len(pname.split(','))
plc_title = pname
if nbrs == 3:
plc_title = ", ".join(pname.split(',')[:1])
elif nbrs == 4:
plc_title = ", ".join(pname.split(',')[:2])
elif nbrs == 5:
plc_title = ", ".join(pname.split(',')[:3])
elif nbrs == 6:
plc_title = ", ".join(pname.split(',')[:4])
main_location = get_main_location(self.r_db, place)
if not plc_title or plc_title == " ":
letter = " "
@ -195,10 +204,13 @@ class PlacePages(BasePage):
trow.extend(Html("td", data or " ", class_=colclass,
inline=True) for
(colclass, data) in [
["ColumnState",
main_location.get(PlaceType.STATE, '')],
["ColumnCountry",
main_location.get(PlaceType.COUNTRY, '')]])
# Use the two last field of a place
# We could have strange values if we
# have a placename like:
# city, province, country, mainland, planet...
# mainland and planet are custom types
["ColumnState", sname],
["ColumnCountry", cname]])
if self.display_coordinates:
tcell1 = Html("td", class_="ColumnLatitude", inline=True)
tcell2 = Html("td", class_="ColumnLongitude", inline=True)
@ -323,10 +335,25 @@ class PlacePages(BasePage):
self.rlocale)
first_place = True
for (pname, place_handle) in handle_list:
if not pname:
continue
val = self.report.obj_dict[PlaceName][pname]
nbelem = len(val)
if nbelem == 4:
place = self.r_db.get_place_from_handle(
place_handle)
main_location = get_main_location(self.r_db,
place)
sname = main_location.get(PlaceType.STATE, '')
cname = main_location.get(PlaceType.COUNTRY, '')
else:
cname = val[3]
sname = val[2]
(ldatec, first_place) \
= self.__output_place(ldatec,
trow, first_place, pname,
place_handle, bucket_letter,
trow, first_place,
pname, sname, cname,
val[0], bucket_letter,
bucket_link)
# add clearline for proper styling
@ -356,7 +383,7 @@ class PlacePages(BasePage):
place.get_gramps_id())
self.bibli = Bibliography()
ldatec = place.get_change_time()
apname = _pd.display(self.r_db, place)
apname = _pd.display(self.r_db, place, fmt=0)
if place_name == apname: # store only the primary named page
output_file, sio = self.report.create_file(place_handle, "plc")