""" returns a sorted list of links """ # 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 ZTUtils import LazyFilter parent=context.restrictedTraverse('..') entries=[] entriesBySubject={} if hasattr(context,'filter'): for subject in context.filter: if subject: entriesBySubject[subject]=[] sortableEntries=[] for entry in LazyFilter(parent.objectValues(['Skinned Folder','OODocument','Portal External File']),skip=''): if entry.id!=context.id and context.portal_membership.checkPermission('View',entry): entryLowerCaseTitle=entry.title_or_id().lower() if entryLowerCaseTitle.startswith('the '): entryLowerCaseTitle=entryLowerCaseTitle[4:] elif entryLowerCaseTitle.startswith('an '): entryLowerCaseTitle=entryLowerCaseTitle[3:] elif entryLowerCaseTitle.startswith('a '): entryLowerCaseTitle=entryLowerCaseTitle[2:] elif entryLowerCaseTitle.startswith('"'): entryLowerCaseTitle=entryLowerCaseTitle[1:] if len(entry.subject)>0 and len(entry.subject[0])>0: subject=tuple(entry.subject) else: subject=() sortableEntries.append((subject,entry.rank,entryLowerCaseTitle,entry)) for entry in LazyFilter(context.objectValues(('Link','Favorite')),skip=''): category=entry.Type() if (category=='Remote URI' or category=='Local URI') \ and entry.isEntryAllowedByFilter(subjectStr): entryLowerCaseTitle=entry.title_or_id().lower() if entryLowerCaseTitle.startswith('the '): entryLowerCaseTitle=entryLowerCaseTitle[4:] elif entryLowerCaseTitle.startswith('an '): entryLowerCaseTitle=entryLowerCaseTitle[3:] elif entryLowerCaseTitle.startswith('a '): entryLowerCaseTitle=entryLowerCaseTitle[2:] elif entryLowerCaseTitle.startswith('"'): entryLowerCaseTitle=entryLowerCaseTitle[1:] subject=entry.Subject() sortableEntries.append((subject,entry.rank,entryLowerCaseTitle,entry)) if sortableEntries: sortableEntries.sort() for entryTuple in sortableEntries: for subject in context.filter: if subject and subject in entryTuple[0]: entriesBySubject[subject].append(entryTuple[3]) break else: if entriesBySubject.has_key('Miscellaneous'): entriesBySubject['Miscellaneous'].append(entryTuple[3]) else: entriesBySubject['Miscellaneous']=[entryTuple[3]] if 'Miscellaneous' not in context.filter: subjects=list(context.filter)+['Miscellaneous'] else: subjects=context.filter for subject in subjects: if entriesBySubject.has_key(subject): entries.append((subject,entriesBySubject[subject])) return entries