Modified alphabet_navigation to remove the necessity of key, modified class EventListPage to use alphabet_navigation just like the rest of the site.

svn: r15273
This commit is contained in:
Rob G. Healey 2010-04-23 00:39:24 +00:00
parent bb17e00abd
commit 85523a2226

View File

@ -37,7 +37,7 @@ Narrative Web Page generator.
# python modules # python modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from __future__ print_function from __future__ import print_function
from functools import partial from functools import partial
import gc import gc
import os import os
@ -1898,7 +1898,7 @@ class IndividualListPage(BasePage):
# add alphabet navigation # add alphabet navigation
menu_set = get_first_letters(db, person_handle_list, _KEYPERSON) menu_set = get_first_letters(db, person_handle_list, _KEYPERSON)
alpha_nav, menu_set = alphabet_navigation(menu_set, _KEYPERSON) alpha_nav, menu_set = alphabet_navigation(menu_set)
if alpha_nav is not None: if alpha_nav is not None:
individuallist += alpha_nav individuallist += alpha_nav
@ -2225,7 +2225,7 @@ class PlaceListPage(BasePage):
# begin alphabet navigation # begin alphabet navigation
menu_set = get_first_letters(db, place_handles, _KEYPLACE) menu_set = get_first_letters(db, place_handles, _KEYPLACE)
alpha_nav, menu_set = alphabet_navigation(menu_set, _KEYPLACE) alpha_nav, menu_set = alphabet_navigation(menu_set)
if alpha_nav is not None: if alpha_nav is not None:
placelist += alpha_nav placelist += alpha_nav
@ -2393,7 +2393,8 @@ class EventListPage(BasePage):
eventlist += Html("p", msg, id = "description") eventlist += Html("p", msg, id = "description")
# get alphabet navigation for class EventListPage # get alphabet navigation for class EventListPage
alpha_nav, event_types = alphabet_navigation(event_types, _ALPHAEVENT) menu_set = get_first_letters(db, event_types, _ALPHAEVENT)
alpha_nav, menu_set = alphabet_navigation(menu_set)
if alpha_nav is not None: if alpha_nav is not None:
eventlist += alpha_nav eventlist += alpha_nav
@ -2410,18 +2411,19 @@ class EventListPage(BasePage):
trow.extend( trow.extend(
Html("th", label, class_ = "Column" + colclass, inline = True) Html("th", label, class_ = "Column" + colclass, inline = True)
for (label, colclass) in [ for (label, colclass) in [
[THEAD, "Type"], [_("Letter"), "Letter"],
[DHEAD, "Date"], [THEAD, "Type"],
[GRAMPSID, "GRAMPSID"], [DHEAD, "Date"],
[_PERSON, "Person"] ] [GRAMPSID, "GRAMPSID"],
[_PERSON, "Person"] ]
) )
tbody = Html("tbody") tbody = Html("tbody")
table += tbody table += tbody
# separate events by their type and then thier event handles # separate events by their type and then thier event handles
for (evt_type, datalist) in sort_event_types(db, event_types, displayed = []
event_handle_list): for (evt_type, datalist) in sort_event_types(db, event_types, event_handle_list):
first_event = True first_event = True
for (date, gid, event_handle) in datalist: for (date, gid, event_handle) in datalist:
@ -2430,14 +2432,22 @@ class EventListPage(BasePage):
trow = Html("tr") trow = Html("tr")
tbody += trow tbody += trow
# set up hyperlinked letter for alphabet_navigation
tcell = Html("td", class_ = "ColumnLetter", inline = True)
trow += tcell
ltr = evt_type[0].capitalize()
if ltr in displayed:
tcell += " "
else:
trow.attr = 'class = "BeginLetter"'
tcell += Html("a", ltr, name = ltr,
title = _("Event types beginning with letter " + ltr), inline = True)
# display Event type if first in the list # display Event type if first in the list
tcell = Html("td", class_ = "ColumnType", inline = True) tcell = Html("td", class_ = "ColumnType", inline = True)
trow += tcell trow += tcell
if first_event: if first_event:
trow.attr = 'class = "BeginEvent"' tcell += evt_type
tcell += Html("a", evt_type, name = evt_type,
title = _("Event types beginning with %(eventtype)s") % {
'eventtype': evt_type}, inline = True)
else: else:
tcell += " " tcell += " "
@ -2504,6 +2514,7 @@ class EventListPage(BasePage):
else: else:
tcell += " " tcell += " "
first_event = False first_event = False
displayed.append(ltr)
# add clearline for proper styling # add clearline for proper styling
# add footer section # add footer section
@ -2964,7 +2975,7 @@ class SurnameListPage(BasePage):
# only if surname list not surname count # only if surname list not surname count
if order_by == self.ORDER_BY_NAME: if order_by == self.ORDER_BY_NAME:
menu_set = get_first_letters(db, person_handle_list, _KEYPERSON) menu_set = get_first_letters(db, person_handle_list, _KEYPERSON)
alpha_nav, menu_set = alphabet_navigation(menu_set, _KEYPERSON) alpha_nav, menu_set = alphabet_navigation(menu_set)
if alpha_nav is not None: if alpha_nav is not None:
surnamelist += alpha_nav surnamelist += alpha_nav
@ -6160,30 +6171,43 @@ def first_letter(string):
letter = u'V,W' letter = u'V,W'
return letter return letter
def get_first_letters(db, handle_list, key): def get_first_letters(db, menu_set, key):
""" key is _PLACE or _PERSON ....""" """
get the first letters of the menu_set
@param: db = report database
@param: menu_set = one of a handle list for either person or place handles
or an evt types list
@param: key = either a person, place, or event type
"""
first_letters = [] first_letters = []
for handle in handle_list: for menu_item in menu_set:
if key == _KEYPERSON: if key == _KEYPERSON:
keyname = __get_person_keyname(db, handle) keyname = __get_person_keyname(db, menu_item)
elif key == _KEYPLACE:
keyname = __get_place_keyname(db, menu_item)
else: else:
keyname = __get_place_keyname(db, handle) keyname = menu_item
ltr = first_letter(keyname) ltr = first_letter(keyname)
if ltr is not ",":
if ltr not in [",", " "]:
first_letters.append(ltr) first_letters.append(ltr)
# return menu set letters for alphabet_navigation
return first_letters return first_letters
def alphabet_navigation(menu_set, alphakey): def alphabet_navigation(menu_set):
""" """
Will create the alphabet navigation bar for classes IndividualListPage, Will create the alphabet navigation bar for classes IndividualListPage,
SurnameListPage, PlaceListPage, and EventList SurnameListPage, PlaceListPage, and EventList
@param: menu_set -- a dictionary of either letters or words @param: menu_set -- a dictionary of either letters or words
@param: alphakey -- either Person, Place, or AlphaEvent
""" """
sorted_set = defaultdict(int) sorted_set = defaultdict(int)
# The comment below from the glibc locale sv_SE in # The comment below from the glibc locale sv_SE in
@ -6199,7 +6223,6 @@ def alphabet_navigation(menu_set, alphakey):
# See : http://www.gramps-project.org/bugs/view.php?id = 2933 # See : http://www.gramps-project.org/bugs/view.php?id = 2933
# #
(lang_country, modifier ) = locale.getlocale() (lang_country, modifier ) = locale.getlocale()
ltr = get_first_letters
for menu_item in menu_set: for menu_item in menu_set:
sorted_set[menu_item] += 1 sorted_set[menu_item] += 1
@ -6207,20 +6230,12 @@ def alphabet_navigation(menu_set, alphakey):
# remove the number of each occurance of each letter # remove the number of each occurance of each letter
sorted_alpha_index = sorted(sorted_set, key = locale.strxfrm) sorted_alpha_index = sorted(sorted_set, key = locale.strxfrm)
# remove any commas from the letter set # if no letters, return None to its callers
sorted_alpha_index = [(menu_item) for menu_item in sorted_alpha_index if menu_item != ","]
# remove any single spaces from the letter set also
# Event Types can and do have spaces, so leave them alone for now...
if alphakey is not _ALPHAEVENT:
sorted_alpha_index = [(ltr) for ltr in sorted_alpha_index if ltr != " "]
# if no letters or words, return None to its callers
if not sorted_alpha_index: if not sorted_alpha_index:
return None, [] return None, []
num_ltrs = len(sorted_alpha_index) num_ltrs = len(sorted_alpha_index)
num_of_cols = 34 if alphakey is not _ALPHAEVENT else 10 num_of_cols = 32
num_of_rows = ((num_ltrs // num_of_cols) + 1) num_of_rows = ((num_ltrs // num_of_cols) + 1)
# begin alphabet navigation division # begin alphabet navigation division
@ -6244,8 +6259,8 @@ def alphabet_navigation(menu_set, alphakey):
if lang_country == "sv_SE" and menu_item == u'V': if lang_country == "sv_SE" and menu_item == u'V':
hyper = Html("a", "V,W", href = "#V,W", alt = "V,W") hyper = Html("a", "V,W", href = "#V,W", alt = "V,W")
else: else:
hyper = Html("a", menu_item, href = menu_item, alt = menu_item) hyper = Html("a", menu_item, href = "#%s" % menu_item, alt = menu_item)
hyper.attr += 'title="%s"' % title_str hyper.attr += ' title = "%s"' % title_str
list += hyper list += hyper
# increase letter/ word in sorted_alpha_index # increase letter/ word in sorted_alpha_index