Changeset 4714 for waeup/branches/ulif-layout/src
- Timestamp:
- 7 Jan 2010, 23:12:02 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-layout/src/waeup/university/faculty.py
r4465 r4714 1 """Faculty components. 2 """ 3 1 4 import grok 2 from zope.component.interfaces import Invalid, IFactory 3 from zope.component import createObject 4 from zope.exceptions import DuplicationError 5 from zope.component.interfaces import IFactory 5 6 from zope.interface import implementedBy 6 7 from waeup.interfaces import IFaculty, IDepartment 7 from waeup.viewlets import (MainArea, LeftSidebar, Index, FormWrapMixin,8 Manage, Add)9 from waeup.widgets.interfaces import ITableProvider10 8 11 9 class Faculty(grok.Container): 10 """A university faculty. 11 """ 12 12 grok.implements(IFaculty) 13 13 … … 22 22 23 23 def addDepartment(self, department): 24 """Add a department to the faculty. 25 """ 24 26 if not IDepartment.providedBy(department): 25 27 raise TypeError('Faculties contain only IDepartment instances') … … 27 29 28 30 def clear(self): 31 """Remove all departments from faculty. 32 """ 29 33 keys = self.keys() 30 34 for key in keys: … … 32 36 33 37 def getName(self, key): 38 """Get complete faculty name. 39 """ 34 40 if key in self.keys(): 35 41 dept = self[key] … … 52 58 def getInterfaces(self): 53 59 return implementedBy(Faculty) 54 55 class DisplayForm(grok.DisplayForm):56 grok.context(IFaculty)57 form_fields = grok.AutoFields(IFaculty)58 59 class Content(FormWrapMixin, grok.Viewlet):60 """A viewlet that wraps the `AddFacultyForm`.61 """62 grok.viewletmanager(MainArea)63 grok.context(IFaculty)64 grok.view(Index)65 grok.order(2)66 formview_name = 'displayform' # The name of the formview we want67 # to be rendered in this viewlet.68 69 class DepartmentList(grok.Viewlet):70 grok.viewletmanager(MainArea)71 grok.context(IFaculty)72 grok.view(Index)73 grok.order(3)74 75 def update(self):76 self.table = ITableProvider(self.context).getTables(view=self.view)[0]77 self.table.need()78 79 class ManageForm(grok.EditForm):80 """Manage the basic properties of a `Faculty` instance.81 """82 83 form_fields = grok.AutoFields(IFaculty)84 85 @property86 def label(self):87 # Set faculty name as form label88 return self.form_fields['title'].field.get(self.context)89 90 @grok.action('Save')91 def save(self, **data):92 self.applyData(self.context, **data)93 return94 95 @grok.action('Save and return')96 def saveAndReturn(self, **data):97 self.applyData(self.context, **data)98 self.redirect(self.url(self.context))99 return100 101 @grok.action('Cancel')102 def cancel(self, **data):103 self.redirect(self.url(self.context))104 return105 106 class ManageFaculty(FormWrapMixin, grok.Viewlet):107 """A viewlet that renders the `ManageForm`.108 """109 grok.viewletmanager(MainArea)110 grok.context(IFaculty)111 grok.view(Manage)112 grok.require('waeup.manageUniversity')113 114 formview_name = 'manageform' # The name of the formview we want to115 # be rendered in this viewlet.116 117 class ManageLink(grok.Viewlet):118 grok.viewletmanager(LeftSidebar)119 grok.context(IFaculty)120 grok.view(Index)121 grok.order(5)122 # This link is only displayed, if the user is allowed to use it!123 grok.require('waeup.manageUniversity')124 125 def render(self):126 return u'<div class="portlet"><a href="manage">Settings</a></div>'127 128 class AddDepartmentForm(grok.AddForm):129 grok.context(IFaculty)130 form_fields = grok.AutoFields(IDepartment)131 label = 'Add a department'132 133 @grok.action('Add department')134 def addDepartment(self, **data):135 department = createObject(u'waeup.Department')136 self.applyData(department, **data)137 try:138 self.context.addDepartment(department)139 except DuplicationError:140 self.status = Invalid('The name chosen already exists '141 'in the database')142 return143 self.redirect(self.url(self.context))144 145 146 class AddDepartment(FormWrapMixin, grok.Viewlet):147 """A viewlet that wraps the `AddDepartmentForm`.148 """149 grok.viewletmanager(MainArea)150 grok.context(IFaculty)151 grok.view(Add)152 grok.require('waeup.manageUniversity')153 154 formview_name = 'adddepartmentform' # The name of the formview we155 # want to be rendered in this156 # viewlet.157 158 class AddDepartmentLink(grok.Viewlet):159 """A link in the left sidebar displaying 'Add department'160 """161 grok.viewletmanager(LeftSidebar)162 grok.context(IFaculty)163 grok.view(Index)164 grok.order(5)165 # This is so cool! This link is only displayed, when the user is166 # allowed to use it!167 grok.require('waeup.manageUniversity')168 169 def render(self):170 return u'<div class="portlet"><a href="add">Add department</a></div>'
Note: See TracChangeset for help on using the changeset viewer.