From 83d81654dedd1aa70c7bceb74808f2c2626d307d Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Thu, 4 Oct 2007 03:56:41 +0000 Subject: [PATCH] 0001238: Web report: sort references for places and media (use remove case sensitive sort and use normalized strings for each section) svn: r9075 --- ChangeLog | 5 ++++ src/plugins/NarrativeWeb.py | 46 +++++++++++++++---------------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04098a5e8..8294927bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-10-03 Brian Matherly + * src/plugins/NarrativeWeb.py: 0001238: Web report: sort references for + places and media (use remove case sensitive sort and use normalized strings + for each section) + 2007-10-03 Benny Malengier * src/GrampsDb/_GrampsDbBase.py: copy bookmark list, don't reference * src/GrampsDbUtils/_ReadXML.py: only add bookmarks if not present already, #1187 diff --git a/src/plugins/NarrativeWeb.py b/src/plugins/NarrativeWeb.py index 1bcb418e2..40c51e297 100644 --- a/src/plugins/NarrativeWeb.py +++ b/src/plugins/NarrativeWeb.py @@ -42,6 +42,7 @@ import operator from gettext import gettext as _ from cStringIO import StringIO from textwrap import TextWrapper +from unicodedata import normalize #------------------------------------------------------------------------ # @@ -570,7 +571,7 @@ class BasePage: sortlist = sorted(handlelist, key = operator.itemgetter(1), - cmp = strcoll_case_sensitive) + cmp = locale.strcoll) index = 1 for (path,name,gid) in sortlist: @@ -966,20 +967,20 @@ class PlaceListPage(BasePage): if not n or len(n) == 0: continue - if n[0] != last_letter: - last_letter = n[0] + letter = normalize('NFD',n)[0].upper() + + if letter != last_letter: + last_letter = letter of.write(' \n') of.write('%s' % last_letter) of.write('') self.place_link(of,place.handle,n,place.gramps_id) of.write('') - last_surname = n - elif n != last_surname: + else: of.write(' ') of.write('') self.place_link(of,place.handle,n,place.gramps_id) of.write('') - last_surname = n of.write('\n\n') self.display_footer(of,db) @@ -1289,8 +1290,12 @@ class SurnameListPage(BasePage): if len(surname) == 0: continue - if surname[0] != last_letter: - last_letter = surname[0] + # Get a capital normalized version of the first letter of + # the surname + letter = normalize('NFD',surname)[0].upper() + + if letter != last_letter: + last_letter = letter of.write('%s' % last_letter) of.write('') self.surname_link(of,surname) @@ -1431,7 +1436,7 @@ class SourcesPage(BasePage): key = source.get_title() + str(source.get_gramps_id()) source_dict[key] = (source, handle) keys = source_dict.keys() - keys.sort(strcoll_case_sensitive) + keys.sort(locale.strcoll) msg = _("This page contains an index of all the sources in the " "database, sorted by their title. Clicking on a source's " @@ -2841,8 +2846,8 @@ class WebReportOptions(ReportOptions): data = cursor.next() cursor.close() - media_list.sort(lambda x, y: strcoll_case_sensitive(x[0], y[0])) - html_list.sort(lambda x, y: strcoll_case_sensitive(x[0], y[0])) + media_list.sort(lambda x, y: locale.strcoll(x[0], y[0])) + html_list.sort(lambda x, y: locale.strcoll(x[0], y[0])) self.home_note = mk_combobox(media_list,self.options_dict['NWEBhomenote']) self.intro_note = mk_combobox(media_list,self.options_dict['NWEBintronote']) @@ -3077,29 +3082,14 @@ def sort_people(db,handle_list): sorted_lists = [] temp_list = sname_sub.keys() - temp_list.sort(strcoll_case_sensitive) + temp_list.sort(locale.strcoll) for name in temp_list: slist = map(lambda x: (sortnames[x],x),sname_sub[name]) - slist.sort(lambda x,y: strcoll_case_sensitive(x[0],y[0])) + slist.sort(lambda x,y: locale.strcoll(x[0],y[0])) entries = map(lambda x: x[1], slist) sorted_lists.append((name,entries)) return sorted_lists -def strcoll_case_sensitive(string1,string2): - """ This function was written because string comparisons - seem to be case insensitive if the string is longer than - one character. """ - if len(string1) > 0 and len(string2) > 0: - diff = locale.strcoll(string1[0],string2[0]) - else: - diff = 0 - - if diff == 0: - # If the first character is the same, compare the rest - diff = locale.strcoll(string1,string2) - return diff - - #------------------------------------------------------------------------ # #