""" returns a sorted list of definitions (optionally only beginning with a particular letter) """ # Copyright © 2004 Saugus.net, Inc. # All Rights Reserved. # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. from string import lower from ZTUtils import LazyFilter letter=lower(letter) definitions=[] definitionsBySubject={} for subject in context.filter: if subject: definitionsBySubject[subject]=[] sortableDefinitions=[] for definition in LazyFilter(context.objectValues('Portal File'),skip=''): if definition.Type()=='Definition': if (subjectStr=='' or subjectStr in definition.Subject()): term=lower(definition.terms[0]) if (letter=='' or term[0]==letter): if term.startswith('the '): sortableTerm=term[4:] elif term.startswith('an '): sortableTerm=term[3:] elif term.startswith('a '): sortableTerm=term[2:] else: sortableTerm=term sortableDefinitions.append((definition.rank,sortableTerm,definition)) if sortableDefinitions: sortableDefinitions.sort() for definitionTuple in sortableDefinitions: for subject in context.filter: if subject in definitionTuple[2].Subject(): definitionsBySubject[subject].append(definitionTuple[2]) break else: if definitionsBySubject.has_key('Miscellaneous'): definitionsBySubject['Miscellaneous'].append(definitionTuple[2]) else: definitionsBySubject['Miscellaneous']=[definitionTuple[2]] for subject in list(context.filter)+['Miscellaneous']: if definitionsBySubject.has_key(subject): definitions.append((subject,definitionsBySubject[subject])) return definitions