Changeset 3940 for waeup/branches/ulif-rewrite
- Timestamp:
- 9 Feb 2009, 21:39:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/hostel/hostelcontainer.py
r3937 r3940 1 1 import grok 2 2 3 from waeup.interfaces import IHostelContainer 4 from waeup.viewlets import MainArea, Index 3 from waeup.interfaces import IHostelContainer, IHostel 4 from waeup.viewlets import MainArea, Index, Add, FormWrapMixin 5 5 from hostel import Hostel 6 6 … … 13 13 next_id = 0L 14 14 15 def addHostel(self, hostel): 16 if not IHostel.providedBy(hostel): 17 raise TypeError('HostelContainers contain only IHostel instances') 18 id = str(self.next_id) 19 self[id] = hostel 20 while self.next_id in self.keys(): 21 # Look for next unused int... 22 self.next_id += 1 23 return id 24 25 15 26 # We register HostelContainer as a utility. This way we can 16 27 # call getUtility(IHostelContainer) from anywhere in the code and … … 18 29 grok.global_utility(HostelContainer, provides=IHostelContainer) 19 30 31 class AddHostelForm(grok.AddForm): 32 grok.context(IHostelContainer) 33 form_fields = grok.AutoFields(IHostel) 34 label = 'Add a hostel' 35 36 @grok.action('Add hostel') 37 def addHostel(self, **data): 38 hostel = getUtility(IHostel) 39 self.applyData(hostel, **data) 40 try: 41 self.context.addHostel(hostel) 42 except DuplicationError: 43 self.status = Invalid('The name chosen already exists ' 44 'in the database') 45 return 46 self.redirect(self.url(self.context)) 47 48 class AddHostel(FormWrapMixin, grok.Viewlet): 49 """A viewlet that wraps the `AddHostelForm`. 50 """ 51 grok.viewletmanager(MainArea) 52 grok.context(IHostelContainer) 53 grok.view(Add) 54 grok.require('waeup.manageUniversity') 55 56 formview_name = 'addhostelform' # The name of the formview we want 57 # to be rendered in this viewlet. 58
Note: See TracChangeset for help on using the changeset viewer.