Changeset 4228
- Timestamp:
- 8 Jun 2009, 17:06:58 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/university/department.py
r3526 r4228 1 import grok 2 from zope.component.interfaces import IFactory 3 from waeup.interfaces import IDepartment 4 from waeup.viewlets import MainArea, LeftSidebar, Index, FormWrapMixin, Manage 5 6 class Department(grok.Container): 7 grok.implements(IDepartment) 8 9 # A simple counter for ids. 10 next_id = 0L 11 12 def __init__(self, 13 title=u'Unnamed Department', 14 title_prefix=u'department', 15 code=None, **kw): 16 super(Department, self).__init__(**kw) 17 self.title = title 18 self.title_prefix = title_prefix 19 self.code = code 20 21 class DepartmentFactory(grok.GlobalUtility): 22 """A factory for department containers. 23 """ 24 grok.implements(IFactory) 25 grok.name(u'waeup.Department') 26 title = u"Create a new department.", 27 description = u"This factory instantiates new department instances." 28 29 def __call__(self): 30 return Department() 31 32 def getInterfaces(self): 33 return implementedBy(Department) 34 35 36 class DisplayForm(grok.DisplayForm): 37 grok.context(IDepartment) 38 form_fields = grok.AutoFields(IDepartment) 39 40 class Content(FormWrapMixin, grok.Viewlet): 41 """A viewlet that wraps the `AddDepartmentForm`. 42 """ 43 grok.viewletmanager(MainArea) 44 grok.context(IDepartment) 45 grok.view(Index) 46 grok.require('waeup.manageUniversity') 47 48 formview_name = 'displayform' # The name of the formview we want 49 # to be rendered in this viewlet. 50 51 52 class ManageForm(grok.EditForm): 53 """Manage the basic properties of a `Department` instance. 54 """ 55 56 form_fields = grok.AutoFields(IDepartment) 57 58 @property 59 def label(self): 60 # Set department name as form label 61 return self.form_fields['title'].field.get(self.context) 62 63 @grok.action('Save') 64 def save(self, **data): 65 self.applyData(self.context, **data) 66 return 67 68 @grok.action('Save and return') 69 def saveAndReturn(self, **data): 70 self.applyData(self.context, **data) 71 self.redirect(self.url(self.context)) 72 return 73 74 @grok.action('Cancel') 75 def cancel(self, **data): 76 self.redirect(self.url(self.context)) 77 return 78 79 class ManageDepartment(FormWrapMixin, grok.Viewlet): 80 """A viewlet that renders the `ManageForm`. 81 """ 82 grok.viewletmanager(MainArea) 83 grok.context(IDepartment) 84 grok.view(Manage) 85 grok.require('waeup.manageUniversity') 86 87 formview_name = 'manageform' # The name of the formview we want to 88 # be rendered in this viewlet. 89 90 class ManageLink(grok.Viewlet): 91 grok.viewletmanager(LeftSidebar) 92 grok.context(IDepartment) 93 grok.view(Index) 94 grok.order(5) 95 # This link is only displayed, if the user is allowed to use it! 96 grok.require('waeup.manageUniversity') 97 98 def render(self): 99 return u'<div class="portlet"><a href="manage">Settings</a></div>'
Note: See TracChangeset for help on using the changeset viewer.