From 61e08dd7239b1985d9a868e0bbaf30d949368a44 Mon Sep 17 00:00:00 2001 From: SNoiraud Date: Thu, 14 Jan 2016 09:40:12 +0100 Subject: [PATCH] 8950 : Narrative web : html elements emitted in different order --- gramps/plugins/webreport/narrativeweb.py | 45 ++++++++++++++++-------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/gramps/plugins/webreport/narrativeweb.py b/gramps/plugins/webreport/narrativeweb.py index 52c9b6e80..8625ed3f9 100644 --- a/gramps/plugins/webreport/narrativeweb.py +++ b/gramps/plugins/webreport/narrativeweb.py @@ -645,7 +645,7 @@ class BasePage(object): @param: place_lat_long -- for use in Family Map Pages. This will be None if called from Family pages, which do not create a Family Map """ - family_list = individual.get_family_handle_list() + family_list = sorted(individual.get_family_handle_list()) if not family_list: return None @@ -1597,16 +1597,17 @@ class BasePage(object): user_footer += note msg = _('Generated by %(gramps_home_html_start)s' - 'Gramps%(html_end)s %(version)s on %(date)s' + 'Gramps%(html_end)s %(version)s' ) % {'gramps_home_html_start' : '' , 'html_end' : '' , - 'version' : VERSION , - 'date' : _dd.display(Today()) } + 'version' : VERSION } if date is not None: msg += "
" last_modif = datetime.datetime.fromtimestamp(date).strftime('%Y-%m-%d %H:%M:%S') msg += _('Last change was the %(date)s') % { 'date' : last_modif } + else: + msg += _(' on %(date)s') % { 'date' : _dd.display(Today()) } # optional "link-home" feature; see bug report #2736 if self.report.options['linkhome']: @@ -2068,7 +2069,11 @@ class BasePage(object): """ # return media rectangles to its callers - return _region_items + # bug 8950 : it seems it's better to sort on name + coords of the rectangle. + def sort_by_name_and_rectangle(obj): + return(obj[0], obj[1], obj[2], obj[3], obj[4]) + + return sorted(_region_items, key=lambda x:sort_by_name_and_rectangle(x)) def media_ref_region_to_object(self, media_handle, obj): """ @@ -2822,8 +2827,12 @@ class BasePage(object): if depth > len(list_style): return "" # Sort by the name of the object at the bkref_class, bkref_handle + # bug 8950 : it seems it's better to sort on name + gid. + def sort_by_name_and_gid(obj): + return (obj[1], obj[2]) + for (bkref_class, bkref_handle) in sorted( - bkref_list, key=lambda x:self.report.obj_dict[x[0]][x[1]][1]): + bkref_list, key=lambda x:sort_by_name_and_gid(self.report.obj_dict[x[0]][x[1]])): list = Html("li") path = self.report.obj_dict[bkref_class][bkref_handle][0] name = self.report.obj_dict[bkref_class][bkref_handle][1] @@ -3161,10 +3170,10 @@ class FamilyPages(BasePage): letter =' ' # get person from sorted database list - for person_handle in handle_list: + for person_handle in sorted(handle_list): person = self.dbase_.get_person_from_handle(person_handle) if person: - family_list = pers_fam_dict[person_handle] + family_list = sorted(pers_fam_dict[person_handle], key=lambda x:x.get_gramps_id()) first_family = True for family in family_list: trow = Html("tr") @@ -3426,7 +3435,7 @@ class PlacePages(BasePage): tbody = Html("tbody") table += tbody - for place_handle_key in handle_list: + for place_handle_key in sorted(handle_list): event = self.report.obj_dict[Place][place_handle_key][3] place = self.dbase_.get_place_from_handle(place_handle_key) if place: @@ -4434,9 +4443,12 @@ class MediaPages(BasePage): with self.report.user.progress(_("Narrated Web Site Report"), _("Creating media pages"), len(self.report.obj_dict[MediaObject]) + 1) as step: + # bug 8950 : it seems it's better to sort on desc + gid. + def sort_by_desc_and_gid(obj): + return (obj.desc, obj.gramps_id) sorted_media_handles = sorted(self.report.obj_dict[MediaObject].keys(), - key=lambda x: SORT_KEY(self.report.database.get_object_from_handle(x).desc)) + key=lambda x: sort_by_desc_and_gid(self.report.database.get_object_from_handle(x))) self.MediaListPage(self.report, title, sorted_media_handles) prev = None @@ -4838,9 +4850,12 @@ class ThumbnailPreviewPage(BasePage): self.dbase_ = report.database BasePage.__init__(self, report, title) self.create_thumbs_only = report.options['create_thumbs_only'] + # bug 8950 : it seems it's better to sort on desc + gid. + def sort_by_desc_and_gid(obj): + return (obj.desc, obj.gramps_id) self.photo_keys = sorted(self.report.obj_dict[MediaObject], - key=lambda x: SORT_KEY(self.dbase_.get_object_from_handle(x).desc)) + key=lambda x: sort_by_desc_and_gid(self.dbase_.get_object_from_handle(x))) media_list = [] for person_handle in self.photo_keys: @@ -4886,7 +4901,7 @@ class ThumbnailPreviewPage(BasePage): trow = Html("tr") thead += trow - ltrs = ["G", "r", "a", "m", "p", "s", "3.4.0"] + ltrs = ["G", "r", "a", "m", "p", "s", str(VERSION)] for ltr in ltrs: trow += Html("th", ltr, class_ ="weekend", inline =True) @@ -5232,7 +5247,7 @@ class PersonPages(BasePage): len(self.report.obj_dict[Person]) + 1) as step: self.IndividualListPage(self.report, title, self.report.obj_dict[Person].keys()) - for person_handle in self.report.obj_dict[Person]: + for person_handle in sorted(self.report.obj_dict[Person]): step() person = self.report.database.get_person_from_handle(person_handle) self.IndividualPage(self.report, title, person) @@ -5313,7 +5328,7 @@ class PersonPages(BasePage): surname = _ABSENT first_surname = True - for person_handle in handle_list: + for person_handle in sorted(handle_list): person = self.dbase_.get_person_from_handle(person_handle) if person.get_change_time() > date: date = person.get_change_time() @@ -7724,7 +7739,7 @@ class NavWebReport(Report): "surnames_count") for (surname, handle_list) in local_list: - SurnamePage(self, self.title, surname, handle_list) + SurnamePage(self, self.title, surname, sorted(handle_list)) step() def thumbnail_preview_page(self):