Narweb: incorrect place index if alternate names (#1037)

* Narweb: incorrect place index if alternate names

The places page index doesn't show the alternate names used.

In the narrative web, the first phase is to select all places.
For each object, if we have a place, we memorize that depending on date.
When we create the place pages, we start from these information in the place
table. At this moment, we have no date.
So the sort by primary names gives an incorrect index list and the alternate
place names are missing.

Fixes #11645

* some cleanup
This commit is contained in:
Serge Noiraud 2020-05-05 23:27:11 +02:00 committed by GitHub
parent 0f88753a72
commit 6d3505af62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 35 deletions

View File

@ -2631,9 +2631,6 @@ class BasePage: # pylint: disable=C1001
@param: place -- Place object from the database @param: place -- Place object from the database
@param: table -- Table from Placedetail @param: table -- Table from Placedetail
""" """
if place in self.report.visited:
return None
self.report.visited.append(place)
# add table body # add table body
tbody = Html("tbody") tbody = Html("tbody")
table += tbody table += tbody
@ -3101,7 +3098,7 @@ class BasePage: # pylint: disable=C1001
@param: output_file -- Open file that is being written to @param: output_file -- Open file that is being written to
@param: htmlinstance -- Web page created with libhtml @param: htmlinstance -- Web page created with libhtml
src/plugins/lib/libhtml.py gramps/plugins/lib/libhtml.py
""" """
htmlinstance.write(partial(print, file=output_file)) htmlinstance.write(partial(print, file=output_file))

View File

@ -423,16 +423,19 @@ def sort_people(dbase, handle_list, rlocale=glocale):
def sort_places(dbase, handle_list, rlocale=glocale): def sort_places(dbase, handle_list, rlocale=glocale):
""" """
will sort the database place will sort the database places
""" """
pname_sub = defaultdict(list) pname_sub = defaultdict(list)
sortnames = {}
for place_handle in handle_list: for place_name in handle_list.keys():
place = dbase.get_place_from_handle(place_handle) (hdle, pname, dummy_id, event) = handle_list[place_name]
place = dbase.get_place_from_handle(hdle)
pname = _pd.display(dbase, place) pname = _pd.display(dbase, place)
sortnames[place_handle] = pname apname = _pd.display_event(dbase, event)
pname_sub[pname].append(place_handle)
pname_sub[pname].append(hdle)
if pname != apname:
pname_sub[apname].append(hdle)
sorted_lists = [] sorted_lists = []
temp_list = sorted(pname_sub, key=rlocale.sort_key) temp_list = sorted(pname_sub, key=rlocale.sort_key)
@ -440,10 +443,7 @@ def sort_places(dbase, handle_list, rlocale=glocale):
for name in temp_list: for name in temp_list:
if isinstance(name, bytes): if isinstance(name, bytes):
name = name.decode('utf-8') name = name.decode('utf-8')
slist = sorted(((sortnames[x], x) for x in pname_sub[name]), sorted_lists.append((name, pname_sub[name][0]))
key=lambda x: rlocale.sort_key(x[0]))
for entry in slist:
sorted_lists.append(entry)
return sorted_lists return sorted_lists

View File

@ -63,7 +63,7 @@ from decimal import getcontext
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.lib import (EventType, Name, from gramps.gen.lib import (EventType, Name,
Person, Person,
Family, Event, Place, Source, Family, Event, Place, PlaceName, Source,
Citation, Media, Repository, Note, Tag) Citation, Media, Repository, Note, Tag)
from gramps.gen.plug.menu import (PersonOption, NumberOption, StringOption, from gramps.gen.plug.menu import (PersonOption, NumberOption, StringOption,
BooleanOption, EnumeratedListOption, BooleanOption, EnumeratedListOption,
@ -524,7 +524,7 @@ class NavWebReport(Report):
and the handle for the object that refers to the 'key' object. and the handle for the object that refers to the 'key' object.
""" """
_obj_class_list = (Person, Family, Event, Place, Source, Citation, _obj_class_list = (Person, Family, Event, Place, Source, Citation,
Media, Repository, Note, Tag) Media, Repository, Note, Tag, PlaceName)
# setup a dictionary of the required structure # setup a dictionary of the required structure
self.obj_dict = defaultdict(lambda: defaultdict(set)) self.obj_dict = defaultdict(lambda: defaultdict(set))
@ -881,8 +881,10 @@ class NavWebReport(Report):
name = "" name = ""
if config.get('preferences.place-auto'): if config.get('preferences.place-auto'):
place_name = _pd.display_event(self._db, event) place_name = _pd.display_event(self._db, event)
pplace_name = _pd.display(self._db, place)
else: else:
place_name = place.get_title() place_name = place.get_title()
pplace_name = place_name
if event: if event:
if self.reference_sort: if self.reference_sort:
role_or_date = name role_or_date = name
@ -899,6 +901,11 @@ class NavWebReport(Report):
False) + self.ext False) + self.ext
self.obj_dict[Place][place_handle] = (place_fname, place_name, self.obj_dict[Place][place_handle] = (place_fname, place_name,
place.gramps_id, event) 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,
place.gramps_id, event)
self.bkref_dict[Place][place_handle].add((bkref_class, bkref_handle, self.bkref_dict[Place][place_handle].add((bkref_class, bkref_handle,
role_or_date role_or_date
)) ))

View File

@ -49,19 +49,20 @@ import logging
# Gramps module # Gramps module
#------------------------------------------------ #------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.lib import (PlaceType, Place) from gramps.gen.lib import (PlaceType, Place, PlaceName)
from gramps.gen.plug.report import Bibliography from gramps.gen.plug.report import Bibliography
from gramps.plugins.lib.libhtml import Html from gramps.plugins.lib.libhtml import Html
from gramps.gen.utils.place import conv_lat_lon from gramps.gen.utils.place import conv_lat_lon
from gramps.gen.utils.location import get_main_location from gramps.gen.utils.location import get_main_location
from gramps.gen.display.place import displayer as _pd
#------------------------------------------------ #------------------------------------------------
# specific narrative web import # specific narrative web import
#------------------------------------------------ #------------------------------------------------
from gramps.plugins.webreport.basepage import BasePage from gramps.plugins.webreport.basepage import BasePage
from gramps.plugins.webreport.common import (get_first_letters, first_letter, from gramps.plugins.webreport.common import (first_letter,
alphabet_navigation, GOOGLE_MAPS, alphabet_navigation, GOOGLE_MAPS,
primary_difference, _KEYPLACE, primary_difference,
get_index_letter, FULLCLEAR, get_index_letter, FULLCLEAR,
MARKER_PATH, OPENLAYER, MARKER_PATH, OPENLAYER,
OSM_MARKERS, STAMEN_MARKERS, OSM_MARKERS, STAMEN_MARKERS,
@ -121,22 +122,21 @@ class PlacePages(BasePage):
len(self.report.obj_dict[Place]) + 1 len(self.report.obj_dict[Place]) + 1
) as step: ) as step:
index = 1 index = 1
for place_handle in self.report.obj_dict[Place]: for place_name in self.report.obj_dict[PlaceName].keys():
step() step()
p_handle = self.report.obj_dict[PlaceName][place_name]
index += 1 index += 1
self.placepage(self.report, title, place_handle) self.placepage(self.report, title, p_handle[0], place_name)
step() step()
self.placelistpage(self.report, title, self.placelistpage(self.report, title)
self.report.obj_dict[Place].keys())
def placelistpage(self, report, title, place_handles): def placelistpage(self, report, title):
""" """
Create a place index Create a place index
@param: report -- The instance of the main report class for @param: report -- The instance of the main report class for
this report this report
@param: title -- Is the title of the web page @param: title -- Is the title of the web page
@param: place_handles -- The handle for the place to add
""" """
BasePage.__init__(self, report, title) BasePage.__init__(self, report, title)
@ -158,8 +158,8 @@ class PlacePages(BasePage):
placelist += Html("p", msg, id="description") placelist += Html("p", msg, id="description")
# begin alphabet navigation # begin alphabet navigation
index_list = get_first_letters(self.r_db, place_handles, pkeys = self.report.obj_dict[PlaceName].keys()
_KEYPLACE, rlocale=self.rlocale) index_list = get_first_letters(pkeys, rlocale=self.rlocale)
alpha_nav = alphabet_navigation(index_list, self.rlocale) alpha_nav = alphabet_navigation(index_list, self.rlocale)
if alpha_nav is not None: if alpha_nav is not None:
placelist += alpha_nav placelist += alpha_nav
@ -199,7 +199,8 @@ class PlacePages(BasePage):
] ]
) )
handle_list = sort_places(self.r_db, place_handles, handle_list = sort_places(self.r_db,
self.report.obj_dict[PlaceName],
self.rlocale) self.rlocale)
first = True first = True
@ -207,12 +208,12 @@ class PlacePages(BasePage):
tbody = Html("tbody") tbody = Html("tbody")
table += tbody table += tbody
for (dummy_pname, place_handle) in handle_list: for (pname, place_handle) in handle_list:
place = self.r_db.get_place_from_handle(place_handle) place = self.r_db.get_place_from_handle(place_handle)
if place: if place:
if place.get_change_time() > ldatec: if place.get_change_time() > ldatec:
ldatec = place.get_change_time() ldatec = place.get_change_time()
plc_title = self.report.obj_dict[Place][place_handle][1] plc_title = pname
main_location = get_main_location(self.r_db, place) main_location = get_main_location(self.r_db, place)
if plc_title and plc_title != " ": if plc_title and plc_title != " ":
@ -282,7 +283,7 @@ class PlacePages(BasePage):
# and close the file # and close the file
self.xhtml_writer(placelistpage, output_file, sio, ldatec) self.xhtml_writer(placelistpage, output_file, sio, ldatec)
def placepage(self, report, title, place_handle): def placepage(self, report, title, place_handle, place_name):
""" """
Create a place page Create a place page
@ -293,13 +294,14 @@ class PlacePages(BasePage):
""" """
place = report.database.get_place_from_handle(place_handle) place = report.database.get_place_from_handle(place_handle)
if not place: if not place:
return return None
BasePage.__init__(self, report, title, place.get_gramps_id()) BasePage.__init__(self, report, title, place.get_gramps_id())
self.bibli = Bibliography() self.bibli = Bibliography()
place_name = self.report.obj_dict[Place][place_handle][1]
ldatec = place.get_change_time() ldatec = place.get_change_time()
apname = _pd.display(self.r_db, place)
output_file, sio = self.report.create_file(place_handle, "plc") if place_name == apname: # store only the primary named page
output_file, sio = self.report.create_file(place_handle, "plc")
self.uplink = True self.uplink = True
self.page_title = place_name self.page_title = place_name
(placepage, head, dummy_body, (placepage, head, dummy_body,
@ -482,4 +484,36 @@ class PlacePages(BasePage):
# send page out for processing # send page out for processing
# and close the file # and close the file
self.xhtml_writer(placepage, output_file, sio, ldatec) if place_name == apname: # store only the primary named page
if place in self.report.visited: # only the first time
self.report.close_file(output_file, sio, None)
return None
self.report.visited.append(place)
self.xhtml_writer(placepage, output_file, sio, ldatec)
def get_first_letters(place_list, rlocale=glocale):
"""
get the first letters of the place name list
@param: handle_list -- The place name list
The first letter (or letters if there is a contraction) are extracted from
"""
index_list = []
for place in place_list:
ltr = first_letter(place)
index_list.append(ltr)
# Now remove letters where there is not a primary difference
index_list.sort(key=rlocale.sort_key)
first = True
prev_index = None
for nkey in index_list[:]: #iterate over a slice copy of the list
if first or primary_difference(prev_index, nkey, rlocale):
first = False
prev_index = nkey
else:
index_list.remove(nkey)
# return menu set letters for alphabet_navigation
return index_list