[387] | 1 | from AccessControl import ClassSecurityInfo |
---|
| 2 | |
---|
[1673] | 3 | try: |
---|
| 4 | from App.class_init import InitializeClass |
---|
| 5 | except ImportError: |
---|
| 6 | from Globals import InitializeClass |
---|
| 7 | |
---|
[387] | 8 | def createMultiColumnList(self,slist, numCols, sort_on='title_or_id'): |
---|
| 9 | try: |
---|
| 10 | mcl = self.createMultiColumnList(slist, numCols, sort_on=sort_on) |
---|
| 11 | return mcl |
---|
| 12 | except AttributeError: |
---|
| 13 | return [slist] |
---|
| 14 | |
---|
| 15 | class SortedDict(dict): |
---|
[1509] | 16 | """ A sorted dictionary. |
---|
| 17 | """ |
---|
[387] | 18 | security = ClassSecurityInfo() |
---|
[1313] | 19 | |
---|
| 20 | security.declarePublic('items') |
---|
[387] | 21 | def items(self): |
---|
[1313] | 22 | primary_metatags = self.pmt |
---|
[387] | 23 | lst = [(name,self[name]) for name in primary_metatags \ |
---|
| 24 | if name in self.keys()] + \ |
---|
| 25 | [(name, self[name]) for name in self.keys() \ |
---|
| 26 | if name not in primary_metatags] |
---|
| 27 | return lst |
---|
| 28 | |
---|
[1313] | 29 | |
---|
| 30 | security.declarePublic('__init__') |
---|
| 31 | def __init__(self, *args, **kwargs): |
---|
| 32 | super(SortedDict,self).__init__(*args, **kwargs) |
---|
| 33 | self.pmt = [] |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | security.declarePublic('__setitem__') |
---|
| 37 | def __setitem__(self, i, y): |
---|
| 38 | super(SortedDict,self).__setitem__(i, y) |
---|
| 39 | if i not in self.pmt: |
---|
| 40 | self.pmt.append(i) |
---|
| 41 | |
---|
[1317] | 42 | security.declarePublic('pop') |
---|
| 43 | def pop(self, k, *args, **kwargs): |
---|
| 44 | super(SortedDict,self).pop(k, *args, **kwargs) |
---|
| 45 | if k in self.pmt: |
---|
| 46 | self.pmt.remove(k) |
---|
| 47 | |
---|
[387] | 48 | try: |
---|
| 49 | InitializeClass(SortedDict) |
---|
| 50 | except: |
---|
| 51 | pass |
---|