""" returns a sorted list of tables """ # 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 sortableTables=[] for table in LazyFilter(context.objectValues('Portal File'),skip=''): if table.Type()=='Table' and table.isEntryAllowedByFilter(subjectStr): if len(table.Subject())>0: sub=table.Subject()[0] else: sub='' if sub=='President': category=1 elif sub=='Senator in Congress': category=2 elif sub=='Governor': category=3 elif sub=='Lieutenant Governor': category=4 elif sub=='Attorney General': category=5 elif sub=='Secretary of State': category=6 elif sub=='Treasurer': category=7 elif sub=='Auditor': category=8 elif sub=='Representative in Congress': category=9 elif sub.startswith('Councillor '): category=10 elif sub.startswith('Senator in General Court'): category=11 elif sub.startswith('Representative in General Court'): category=12 elif sub=='District Attorney': category=13 elif sub=='Register of Probate': category=14 elif sub.startswith('State Representative'): category=15 elif sub.startswith('State Committee'): category=16 elif sub=='Sheriff': category=25 elif sub=='County Commissioner': category=26 elif sub=='Selectmen': category=30 elif sub=='School Committee': category=31 elif sub=='Housing Authority': category=32 elif sub=='Town Meeting': precinct=table.title.strip().lower() if precinct.startswith('town meeting'): precinct=precinct[12:].strip() if precinct.startswith('precinct'): precinct=precinct[8:].strip() if precinct.startswith('#'): precinct=precinct[1:].strip() category=32+int(precinct) elif sub=='Town Committee': category=50 elif sub=='Voke': category=51 elif sub=='Question': category=75 elif sub=='Tiny': category=71 else: category=70 sortableTables.append((category,table.rank,table.title,table)) if len(sortableTables)>0: tables=[] sortableTables.sort() odd=1 for tableTuple in sortableTables: if tableTuple[0]==49 or (tableTuple[0]>32 and tableTuple[0]<43): # Town Meeting or other small table, two across if odd: tables.append([tableTuple[3]]) odd=0 else: tables[-1].append(tableTuple[3]) odd=1 else: tables.append([tableTuple[3]]) return tables else: return None