Changeset 4721 for waeup/branches/ulif-layout
- Timestamp:
- 8 Jan 2010, 01:11:48 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-layout/src/waeup/university/department.py
r4511 r4721 1 1 """University departments. 2 2 """ 3 import copy4 3 import grok 5 4 from zope.component import createObject 6 from zope.component.interfaces import IFactory, Invalid 7 from zope.exceptions import DuplicationError 5 from zope.component.interfaces import IFactory 8 6 from zope.interface import implementedBy 9 from waeup.interfaces import IDepartment, ICourse, ICertificate 10 from waeup.utils.helpers import getName 11 from waeup.widgets.interfaces import ITableProvider 12 from waeup.viewlets import (MainArea, LeftSidebar, Index, FormWrapMixin, 13 Manage, AddCourse, AddCertificate) 7 from waeup.interfaces import IDepartment 14 8 15 9 class Department(grok.Container): 10 """A university department. 11 """ 16 12 grok.implements(IDepartment) 17 13 … … 35 31 36 32 def traverse(self, name): 33 """Deliver appropriate containers, if someone wants to go to courses 34 or departments. 35 """ 37 36 if name == 'courses': 38 37 return self.courses … … 54 53 55 54 def getInterfaces(self): 55 """Get interfaces of objects provided by this factory. 56 """ 56 57 return implementedBy(Department) 57 58 59 class Content(grok.Viewlet):60 """A viewlet that wraps the `AddDepartmentForm`.61 """62 grok.viewletmanager(MainArea)63 grok.context(IDepartment)64 grok.view(Index)65 grok.require('waeup.manageUniversity')66 67 def getName(self):68 return getName(self.context)69 70 def getParentName(self):71 return getName(self.context.__parent__)72 73 class CourseList(grok.Viewlet):74 grok.viewletmanager(MainArea)75 grok.context(IDepartment)76 grok.view(Index)77 grok.order(3)78 79 def update(self):80 if 'delcourse' in self.request.form:81 code = self.request.form['code']82 del self.context.courses[code]83 if 'delcert' in self.request.form:84 code = self.request.form['code']85 del self.context.certificates[code]86 self.tables = ITableProvider(self.context).getTables(view=self.view)87 self.coursetable = self.tables[0]88 self.certificatetable = self.tables[1]89 self.coursetable.need()90 91 92 class ManageForm(grok.EditForm):93 """Manage the basic properties of a `Department` instance.94 """95 96 form_fields = grok.AutoFields(IDepartment)97 98 @property99 def label(self):100 # Set department name as form label101 return self.form_fields['title'].field.get(self.context)102 103 @grok.action('Save')104 def save(self, **data):105 self.applyData(self.context, **data)106 return107 108 @grok.action('Save and return')109 def saveAndReturn(self, **data):110 self.applyData(self.context, **data)111 self.redirect(self.url(self.context))112 return113 114 @grok.action('Cancel')115 def cancel(self, **data):116 self.redirect(self.url(self.context))117 return118 119 class ManageDepartment(FormWrapMixin, grok.Viewlet):120 """A viewlet that renders the `ManageForm`.121 """122 grok.viewletmanager(MainArea)123 grok.context(IDepartment)124 grok.view(Manage)125 grok.require('waeup.manageUniversity')126 127 formview_name = 'manageform' # The name of the formview we want to128 # be rendered in this viewlet.129 130 class ManageLink(grok.Viewlet):131 grok.viewletmanager(LeftSidebar)132 grok.context(IDepartment)133 grok.view(Index)134 grok.order(5)135 # This link is only displayed, if the user is allowed to use it!136 grok.require('waeup.manageUniversity')137 138 def render(self):139 return u'<div class="portlet"><a href="manage">Settings</a></div>'140 141 class AddCourseForm(grok.AddForm):142 grok.context(IDepartment)143 # We need a deepcopy here, because otherwise also all other144 # ICourse forms would be affected.145 form_fields = copy.deepcopy(grok.AutoFields(ICourse))146 form_fields.get('code').field.readonly = False147 label = 'Add a course'148 149 @grok.action('Add course')150 def addCourse(self, **data):151 course = createObject(u'waeup.Course')152 self.applyData(course, **data)153 try:154 self.context.courses.addCourse(course)155 except DuplicationError:156 self.status = Invalid('The code chosen already exists '157 'in the database')158 return159 self.redirect(self.url(self.context))160 161 @grok.action('Cancel')162 def cancel(self, **data):163 self.redirect(self.url(self.context))164 return165 166 167 class AddCourse(FormWrapMixin, grok.Viewlet):168 """A viewlet that wraps the `AddFacultyForm`.169 """170 grok.viewletmanager(MainArea)171 grok.context(IDepartment)172 grok.view(AddCourse)173 grok.require('waeup.manageUniversity')174 175 formview_name = 'addcourseform' # The name of the formview we176 # want to be rendered in this177 # viewlet.178 179 class AddCertificateForm(grok.AddForm):180 grok.context(IDepartment)181 # We need a deepcopy here, because otherwise also all other182 # ICertificate forms would be affected.183 form_fields = copy.deepcopy(grok.AutoFields(ICertificate))184 form_fields.get('code').field.readonly = False185 label = 'Add a certificate'186 187 @grok.action('Add certificate')188 def addCertificate(self, **data):189 certificate = createObject(u'waeup.Certificate')190 self.applyData(certificate, **data)191 try:192 self.context.certificates.addCertificate(certificate)193 except DuplicationError:194 self.status = Invalid('The name chosen already exists '195 'in the database')196 return197 self.redirect(self.url(self.context))198 199 @grok.action('Cancel')200 def cancel(self, **data):201 self.redirect(self.url(self.context))202 return203 204 205 class AddCertificate(FormWrapMixin, grok.Viewlet):206 """A viewlet that wraps the `AddFacultyForm`.207 """208 grok.viewletmanager(MainArea)209 grok.context(IDepartment)210 grok.view(AddCertificate)211 grok.require('waeup.manageUniversity')212 213 formview_name = 'addcertificateform' # The name of the formview we214 # want to be rendered in this215 # viewlet.
Note: See TracChangeset for help on using the changeset viewer.