Mercurial > hg > MPIWGWeb
comparison MPIWGFolder.py @ 10:c711fe75d0ac
order by weight form for MPIWGFolder. more cleanup.
author | casties |
---|---|
date | Tue, 26 Feb 2013 20:39:34 +0100 |
parents | bca61e893fcc |
children | ee79f6ba8d01 |
comparison
equal
deleted
inserted
replaced
9:5db416602e85 | 10:c711fe75d0ac |
---|---|
6 | 6 |
7 | 7 |
8 class MPIWGFolder(Folder): | 8 class MPIWGFolder(Folder): |
9 """special Folder object for MPIWG website """ | 9 """special Folder object for MPIWG website """ |
10 | 10 |
11 meta_type="MPIWGFolder" | 11 meta_type = "MPIWGFolder" |
12 | 12 |
13 manage_options=Folder.manage_options+( | 13 manage_options = Folder.manage_options + ( |
14 {'label':'Change Weight','action':'changeWeightForm'}, | 14 {'label':'Change Weight', 'action':'changeWeightForm'}, |
15 {'label':'Main Config','action':'changeForm'}, | 15 {'label':'Rearrange Weights', 'action':'changeWeightsForm'}, |
16 {'label':'Configure', 'action':'changeForm'}, | |
16 ) | 17 ) |
17 | 18 |
18 changeWeightForm = PageTemplateFile('zpt/MPIWGFolderChangeWeight', globals()) | 19 changeWeightForm = PageTemplateFile('zpt/MPIWGFolderChangeWeight', globals()) |
19 changeForm = PageTemplateFile('zpt/MPIWGFolderConfig', globals()) | 20 changeForm = PageTemplateFile('zpt/MPIWGFolderConfig', globals()) |
21 changeWeightsForm = PageTemplateFile('zpt/folder/manage_change_weights', globals()) | |
20 | 22 |
21 def __init__(self, id, title=None, weight=0, canonicalName=None): | 23 def __init__(self, id, title=None, weight=0, canonicalName=None): |
22 self.id = str(id) | 24 self.id = str(id) |
23 self.weight = weight | 25 self.weight = weight |
24 if title is None: | 26 if title is None: |
29 if canonicalName is None: | 31 if canonicalName is None: |
30 self.canonicalName = self.id | 32 self.canonicalName = self.id |
31 else: | 33 else: |
32 self.canonicalName = canonicalName | 34 self.canonicalName = canonicalName |
33 | 35 |
34 def changeWeight(self,weight,RESPONSE=None): | 36 def getNavItems(self): |
37 """returns sorted list of sub-items""" | |
38 # get all nav-type items | |
39 items = self.objectItems(self.nav_meta_types) | |
40 # unpack into simple list and omit empty titles | |
41 items = [s[1] for s in items if s[1].title != ""] | |
42 # sort by weight | |
43 items.sort(key=lambda x:int(x.weight)) | |
44 return items | |
45 | |
46 def changeWeight(self, weight, RESPONSE=None): | |
35 """change weight""" | 47 """change weight""" |
36 self.weight=weight | 48 self.weight = weight |
37 if RESPONSE is not None: | 49 if RESPONSE is not None: |
38 RESPONSE.redirect('manage_main') | 50 RESPONSE.redirect('manage_main') |
39 | 51 |
40 def deleteObject(self,id): | 52 def changeWeightsInFolder(self, REQUEST=None): |
41 """ delete an object inside the MPIWGFolder """ | 53 """change all weights of a collection""" |
42 if self.hasObject(id): | 54 ret = "" |
43 self._delObject(id) | 55 form = REQUEST.form |
56 resources = self.getNavItems() | |
57 for resource in resources: | |
58 try: | |
59 id = resource.getId() | |
60 ret += id + " " + form[id] + "\n" | |
61 resource.changeWeight(form[id]) | |
62 except Exception, e: | |
63 ret += "ERROR: %s\n"%e | |
64 return ret | |
44 | 65 |
45 def changeMPIWGFolder(self, title=None, weight=None, canonicalName=None, RESPONSE=None): | 66 def changeMPIWGFolder(self, title=None, weight=None, canonicalName=None, RESPONSE=None): |
46 """change everything""" | 67 """change everything""" |
47 if title is not None: | 68 if title is not None: |
48 self.title = title | 69 self.title = title |
60 getSubSection = getSubSection | 81 getSubSection = getSubSection |
61 | 82 |
62 | 83 |
63 def manage_addMPIWGFolderForm(self): | 84 def manage_addMPIWGFolderForm(self): |
64 """Form for adding""" | 85 """Form for adding""" |
65 pt=PageTemplateFile('zpt/AddMPIWGFolder', globals()).__of__(self) | 86 pt = PageTemplateFile('zpt/AddMPIWGFolder', globals()).__of__(self) |
66 return pt() | 87 return pt() |
67 | 88 |
68 def manage_addMPIWGFolder(self, id, title=None,weight=0,RESPONSE=None): | 89 def manage_addMPIWGFolder(self, id, title=None, weight=0, RESPONSE=None): |
69 "Add a MPIWG Folder." | 90 "Add a MPIWG Folder." |
70 newObj=MPIWGFolder(id,title,weight) | 91 newObj = MPIWGFolder(id, title, weight) |
71 self.Destination()._setObject(id,newObj) | 92 self.Destination()._setObject(id, newObj) |
72 if RESPONSE is not None: | 93 if RESPONSE is not None: |
73 RESPONSE.redirect('manage_main') | 94 RESPONSE.redirect('manage_main') |
74 | 95 |