Fix processing of contractions, and changes to ensure code (after initial lines) for narrativeweb is the same for trunk and gramps34

svn: r21293
This commit is contained in:
Tim G L Lyons 2013-02-04 18:23:57 +00:00
parent 859293f74b
commit 94a16c85c2

View File

@ -67,7 +67,6 @@ Classes for producing the web pages:
# python modules
#------------------------------------------------
from __future__ import print_function, division
from functools import partial
import gc
import os
@ -80,14 +79,13 @@ except ImportError:
from md5 import md5
import time, datetime
import shutil
import io
import codecs
import tarfile
import tempfile
if sys.version_info[0] < 3:
from cStringIO import StringIO
else:
from io import StringIO, BytesIO, TextIOWrapper, BufferedWriter
from io import StringIO, BytesIO, TextIOWrapper
from textwrap import TextWrapper
from unicodedata import normalize
from collections import defaultdict
@ -125,6 +123,7 @@ from gramps.gen.plug.report import MenuReportOptions
from gramps.gen.utils.config import get_researcher
from gramps.gen.utils.string import confidence
from gramps.gen.utils.file import media_path_full
from gramps.gen.utils.alive import probably_alive
from gramps.gen.utils.db import get_source_and_citation_referents
from gramps.gen.constfunc import win, cuni, conv_to_unicode, UNITYPE
from gramps.gui.thumbnails import get_thumbnail_path, run_thumbnailer
@ -142,11 +141,22 @@ from gramps.plugins.lib.libhtml import Html, xml_lang
from gramps.plugins.lib.libhtmlbackend import HtmlBackend, process_spaces
from gramps.plugins.lib.libgedcom import make_gedcom_date
from gramps.gen.utils.alive import probably_alive
from gramps.gen.utils.place import conv_lat_lon
from gramps.gui.pluginmanager import GuiPluginManager
from gramps.gen.relationship import get_relationship_calculator
# FIXME: This could be glocale.get_translation().language(), except that at the
# moment, (1) that gives an empty string when LANG is set to something like
# "sk_SK.UTF-8", and (2) it should be a language specific to collation, not just
# the language for translation.
import locale
COLLATE_LANG = locale.getlocale()[0]
SORT_KEY = glocale.sort_key
#------------------------------------------------
# Everything below this point is identical for gramps34 (post 3.4.2), gramps40 and trunk
#------------------------------------------------
#------------------------------------------------
# constants
#------------------------------------------------
@ -333,8 +343,8 @@ osm_markers = """
var wms = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://maps.opengeo.org/geowebcache/service/wms",
{'layers':"openstreetmap", 'format': "image/png"});
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{'layers':'basic'});
map.addLayer(wms);
map.setCenter(new OpenLayers.LonLat(%s, %s), %d);
@ -2413,7 +2423,7 @@ class BasePage(object):
ordered = Html("ol")
section += ordered
sortlist = sorted(handlelist, key=lambda x:glocale.sort_key(x[1]))
sortlist = sorted(handlelist, key=lambda x:SORT_KEY(x[1]))
for (path, name, gid) in sortlist:
list = Html("li")
@ -2478,7 +2488,6 @@ class BasePage(object):
person=partner)
return trow
def display_child_link(self, chandle):
"""
display child link ...
@ -3306,9 +3315,12 @@ class PlacePages(BasePage):
self.place_dict = defaultdict(set)
def display_pages(self, title):
# FIXME: Most of the parameters should be removed. report is passed to
# __init__, title appears not to be used and place_list, source_list and
# db_place_handles violate modularity and should be removed.
"""
Generate and output the pages under the Place tab, namely the place
index and the individual place pages.
@param: title -- the web site title
"""
log.debug("obj_dict[Place]")
for item in self.report.obj_dict[Place].items():
log.debug(" %s" % str(item))
@ -3964,7 +3976,7 @@ class SurnameListPage(BasePage):
temp_list[index_val] = (surname, data_list)
ppl_handle_list = (temp_list[key]
for key in sorted(temp_list, key = glocale.sort_key))
for key in sorted(temp_list, key = SORT_KEY))
last_letter = ''
last_surname = ''
@ -4127,21 +4139,20 @@ class SourcePages(BasePage):
Generate and output the pages under the Sources tab, namely the sources
index and the individual sources pages.
@param: report -- the instance of the main report class for this report
@param: title -- the web site title
"""
# FIXME: Perhaps report and title should just be passed in to the class
log.debug("obj_dict[Source]")
for item in self.report.obj_dict[Source].items():
log.debug(" %s" % str(item))
self.report.user.begin_progress(_("Narrated Web Site Report"),
_("Creating source pages"),
len(self.source_dict) + 1)
self.SourceListPage(self.report, title, self.report.obj_dict[Source].keys())
len(self.report.obj_dict[Source]) + 1)
self.SourceListPage(self.report, title,
self.report.obj_dict[Source].keys())
for item in self.report.obj_dict[Source].items():
for source_handle in self.report.obj_dict[Source]:
self.report.user.step_progress()
self.SourcePage(self.report, title, item[0])
self.SourcePage(self.report, title, source_handle)
self.report.user.end_progress()
@ -4173,7 +4184,7 @@ class SourcePages(BasePage):
key = source.get_title() + str(source.get_gramps_id())
source_dict[key] = (source, handle)
keys = sorted(source_dict, key=glocale.sort_key)
keys = sorted(source_dict, key=SORT_KEY)
msg = _("This page contains an index of all the sources in the "
"database, sorted by their title. Clicking on a source&#8217;s "
@ -4343,7 +4354,6 @@ class MediaPages(BasePage):
Generate and output the pages under the Media tab, namely the media
index and the individual media pages.
@param: report -- the instance of the main report class for this report
@param: title -- the web site title
"""
log.debug("obj_dict[Media]")
@ -6521,7 +6531,7 @@ class RepositoryPages(BasePage):
key = repository.get_name() + str(repository.get_gramps_id())
repos_dict[key] = (repository, repository_handle)
keys = sorted(repos_dict, key = glocale.sort_key)
keys = sorted(repos_dict, key = SORT_KEY)
# RepositoryListPage Class
self.RepositoryListPage(self.report, title, repos_dict, keys)
@ -7519,20 +7529,6 @@ class NavWebReport(Report):
fname = CSS["DropDown-Menus"]["filename"]
self.copy_file(fname, "narrative-menus.css", "css")
# copy Animated Citations Drop Down Layout if being used, copy its style sheet
# and its associated javascript file?
if (self.css == _("Basic-Blue") or self.css == _("Visually Impaired")):
if self.citationreferents == "DropDown":
fname = CSS["Animated DropDown"]["javascript"]
self.copy_file(fname, "jquery-1.7.1.min.js", "scripts")
if self.citationreferents == "DropDown":
fname = CSS["Animated DropDown"]["filename"]
else:
fname = CSS["Outline"]["filename"]
self.copy_file(fname, "narrative-citations.css", "css")
# copy narrative-maps Style Sheet if Place or Family Map pages are being created?
if (self.placemappages or self.familymappages):
fname = CSS["NarrativeMaps"]["filename"]
@ -8480,14 +8476,12 @@ def sort_people(dbase, handle_list):
sorted_lists = []
# According to the comment in flatbasemodel: This list is sorted
# ascending, via localized string sort. glocale.sort_key which
# uses strxfrm, which is apparently broken in Win ?? --> they should fix
# base lib, we need strxfrm, fix it in the Utils module.
temp_list = sorted(sname_sub, key=glocale.sort_key)
# ascending, via localized string sort. SORT_KEY
temp_list = sorted(sname_sub, key=SORT_KEY)
for name in temp_list:
slist = sorted(((sortnames[x], x) for x in sname_sub[name]),
key=lambda x:glocale.sort_key(x[0]))
key=lambda x:SORT_KEY(x[0]))
entries = [x[1] for x in slist]
sorted_lists.append((name, entries))
@ -8514,7 +8508,7 @@ def sort_event_types(dbase, event_types, event_handle_list):
sort_value = event.get_date_object().get_sort_value()
event_dict[event_type].append((sort_value, event_handle))
for tup_list in list(event_dict.values()):
for tup_list in event_dict.values():
tup_list.sort()
# return a list of sorted tuples, one per event
@ -8551,20 +8545,19 @@ def first_letter(string):
else:
letter = cuni(' ')
# See : http://www.gramps-project.org/bugs/view.php?id = 2933
lang_country = glocale.get_translation().language()
if lang_country == "sv" and (letter == cuni('W') or letter == cuni('V')):
letter = 'V,W'
if COLLATE_LANG == "sv_SE" and (letter == cuni('W') or letter == cuni('V')):
letter = cuni('V,W')
# See : http://www.gramps-project.org/bugs/view.php?id = 4423
elif (lang_country == "cs" or lang_country == "sk") and letter == cuni('C') and len(string) > 1:
second_letter = normalize('NFKC', str(string))[1].upper()
elif (COLLATE_LANG == "cs_CZ" or COLLATE_LANG == "sk_SK") and letter == cuni('C') and len(string) > 1:
second_letter = normalize('NFKC', cuni(string))[1].upper()
if second_letter == cuni('H'):
letter += cuni('h')
elif lang_country == "sk" and letter == cuni('D') and len(string) > 1:
elif COLLATE_LANG == "sk_SK" and letter == cuni('D') and len(string) > 1:
second_letter = normalize('NFKC', cuni(string))[1].upper()
if second_letter == cuni('Z'):
letter += cuni('z')
elif second_letter == cuni('≈Ω'):
letter += cuni('ž')
elif second_letter == cuni('Ž'):
letter += cuni('ž')
return letter
def get_first_letters(dbase, menu_set, key):
@ -8614,13 +8607,12 @@ def alphabet_navigation(menu_set):
#
# See : http://www.gramps-project.org/bugs/view.php?id = 2933
#
lang_country = glocale.get_translation().language()
for menu_item in menu_set:
sorted_set[menu_item] += 1
# remove the number of each occurance of each letter
sorted_alpha_index = sorted(sorted_set, key = glocale.sort_key)
sorted_alpha_index = sorted(sorted_set, key = SORT_KEY)
# if no letters, return None to its callers
if not sorted_alpha_index:
@ -8641,7 +8633,7 @@ def alphabet_navigation(menu_set):
while (cols <= num_of_cols and index < num_ltrs):
menu_item = sorted_alpha_index[index]
if lang_country == "sv" and menu_item == cuni('V'):
if COLLATE_LANG == "sv_SE" and menu_item == cuni('V'):
hyper = Html("a", "V,W", href = "#V,W", title = "V,W")
else:
# adding title to hyperlink menu for screen readers and braille writers