1 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
2 | ## This program is free software; you can redistribute it and/or modify |
---|
3 | ## it under the terms of the GNU General Public License as published by |
---|
4 | ## the Free Software Foundation; either version 2 of the License, or |
---|
5 | ## (at your option) any later version. |
---|
6 | ## |
---|
7 | ## This program is distributed in the hope that it will be useful, |
---|
8 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
9 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
10 | ## GNU General Public License for more details. |
---|
11 | ## |
---|
12 | ## You should have received a copy of the GNU General Public License |
---|
13 | ## along with this program; if not, write to the Free Software |
---|
14 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
15 | ## |
---|
16 | """UI components for students and related components. |
---|
17 | """ |
---|
18 | import sys |
---|
19 | import grok |
---|
20 | |
---|
21 | from datetime import datetime |
---|
22 | from zope.formlib.widget import CustomWidgetFactory |
---|
23 | from zope.formlib.form import setUpEditWidgets |
---|
24 | from zope.securitypolicy.interfaces import IPrincipalRoleManager |
---|
25 | from zope.traversing.browser import absoluteURL |
---|
26 | from zope.component import ( |
---|
27 | createObject,) |
---|
28 | |
---|
29 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
30 | from reportlab.pdfgen import canvas |
---|
31 | from reportlab.lib.units import cm |
---|
32 | from reportlab.lib.pagesizes import A4 |
---|
33 | from reportlab.lib.styles import getSampleStyleSheet |
---|
34 | from reportlab.platypus import (Frame, Paragraph, Image, |
---|
35 | Table, Spacer) |
---|
36 | from reportlab.platypus.tables import TableStyle |
---|
37 | |
---|
38 | from waeup.sirp.accesscodes import invalidate_accesscode, get_access_code |
---|
39 | from waeup.sirp.accesscodes.workflow import USED |
---|
40 | from waeup.sirp.browser import ( |
---|
41 | WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, WAeUPDisplayFormPage) |
---|
42 | from waeup.sirp.browser.breadcrumbs import Breadcrumb |
---|
43 | from waeup.sirp.browser.layout import NullValidator |
---|
44 | from waeup.sirp.browser.pages import add_local_role, del_local_roles |
---|
45 | from waeup.sirp.browser.resources import datepicker, tabs, datatable |
---|
46 | from waeup.sirp.browser.viewlets import ( |
---|
47 | ManageActionButton, PrimaryNavTab, LeftSidebarLink, |
---|
48 | AddActionButton, ActionButton, |
---|
49 | ) |
---|
50 | from waeup.sirp.image.browser.widget import ( |
---|
51 | ThumbnailWidget, EncodingImageFileWidget, |
---|
52 | ) |
---|
53 | from waeup.sirp.image.image import createWAeUPImageFile |
---|
54 | from waeup.sirp.interfaces import IWAeUPObject, ILocalRolesAssignable |
---|
55 | from waeup.sirp.permissions import get_users_with_local_roles |
---|
56 | from waeup.sirp.university.interfaces import ICertificate |
---|
57 | from waeup.sirp.widgets.datewidget import ( |
---|
58 | FriendlyDateWidget, FriendlyDateDisplayWidget) |
---|
59 | from waeup.sirp.widgets.restwidget import ReSTDisplayWidget |
---|
60 | from waeup.sirp.widgets.objectwidget import ( |
---|
61 | WAeUPObjectWidget, WAeUPObjectDisplayWidget) |
---|
62 | from waeup.sirp.widgets.multilistwidget import ( |
---|
63 | MultiListWidget, MultiListDisplayWidget) |
---|
64 | from waeup.sirp.students.interfaces import ( |
---|
65 | IStudentsContainer, IStudent, IStudentClearance, |
---|
66 | IStudentPersonal, IStudentBase |
---|
67 | ) |
---|
68 | from waeup.sirp.students.student import ( |
---|
69 | Student, |
---|
70 | ) |
---|
71 | from waeup.sirp.students.catalog import search |
---|
72 | |
---|
73 | class StudentsTab(PrimaryNavTab): |
---|
74 | """Students tab in primary navigation. |
---|
75 | """ |
---|
76 | |
---|
77 | grok.context(IWAeUPObject) |
---|
78 | grok.order(3) |
---|
79 | grok.require('waeup.viewStudents') |
---|
80 | grok.template('primarynavtab') |
---|
81 | |
---|
82 | pnav = 4 |
---|
83 | tab_title = u'Students' |
---|
84 | |
---|
85 | @property |
---|
86 | def link_target(self): |
---|
87 | return self.view.application_url('students') |
---|
88 | |
---|
89 | class StudentsBreadcrumb(Breadcrumb): |
---|
90 | """A breadcrumb for the students container. |
---|
91 | """ |
---|
92 | grok.context(IStudentsContainer) |
---|
93 | title = u'Students' |
---|
94 | |
---|
95 | class StudentsContainerPage(WAeUPPage): |
---|
96 | """The standard view for student containers. |
---|
97 | """ |
---|
98 | grok.context(IStudentsContainer) |
---|
99 | grok.name('index') |
---|
100 | grok.require('waeup.viewStudents') |
---|
101 | grok.template('studentscontainerpage') |
---|
102 | |
---|
103 | @property |
---|
104 | def title(self): |
---|
105 | return "Students" |
---|
106 | |
---|
107 | @property |
---|
108 | def label(self): |
---|
109 | return self.title |
---|
110 | |
---|
111 | def update(self, *args, **kw): |
---|
112 | datatable.need() |
---|
113 | form = self.request.form |
---|
114 | self.hitlist = [] |
---|
115 | if 'searchterm' in form and form['searchterm']: |
---|
116 | self.searchterm = form['searchterm'] |
---|
117 | self.searchtype = form['searchtype'] |
---|
118 | elif 'old_searchterm' in form: |
---|
119 | self.searchterm = form['old_searchterm'] |
---|
120 | self.searchtype = form['old_searchtype'] |
---|
121 | else: |
---|
122 | if 'search' in form: |
---|
123 | self.flash('Empty search string.') |
---|
124 | return |
---|
125 | self.hitlist = search(query=self.searchterm, |
---|
126 | searchtype=self.searchtype, view=self) |
---|
127 | if not self.hitlist: |
---|
128 | self.flash('No student found.') |
---|
129 | return |
---|
130 | |
---|
131 | class StudentsContainerManageActionButton(ManageActionButton): |
---|
132 | grok.order(1) |
---|
133 | grok.context(IStudentsContainer) |
---|
134 | grok.view(StudentsContainerPage) |
---|
135 | grok.require('waeup.manageStudents') |
---|
136 | text = 'Manage students' |
---|
137 | |
---|
138 | |
---|
139 | class StudentsContainerManagePage(WAeUPPage): |
---|
140 | """The manage page for student containers. |
---|
141 | """ |
---|
142 | grok.context(IStudentsContainer) |
---|
143 | grok.name('manage') |
---|
144 | grok.require('waeup.manageStudents') |
---|
145 | grok.template('studentscontainermanagepage') |
---|
146 | |
---|
147 | @property |
---|
148 | def title(self): |
---|
149 | return "Students" |
---|
150 | |
---|
151 | @property |
---|
152 | def label(self): |
---|
153 | return self.title |
---|
154 | |
---|
155 | def update(self, *args, **kw): |
---|
156 | datatable.need() |
---|
157 | form = self.request.form |
---|
158 | self.hitlist = [] |
---|
159 | if 'searchterm' in form and form['searchterm']: |
---|
160 | self.searchterm = form['searchterm'] |
---|
161 | self.searchtype = form['searchtype'] |
---|
162 | elif 'old_searchterm' in form: |
---|
163 | self.searchterm = form['old_searchterm'] |
---|
164 | self.searchtype = form['old_searchtype'] |
---|
165 | else: |
---|
166 | if 'search' in form: |
---|
167 | self.flash('Empty search string.') |
---|
168 | return |
---|
169 | #import pdb; pdb.set_trace() |
---|
170 | if not 'entries' in form: |
---|
171 | self.hitlist = search(query=self.searchterm, |
---|
172 | searchtype=self.searchtype, view=self) |
---|
173 | if not self.hitlist: |
---|
174 | self.flash('No student found.') |
---|
175 | return |
---|
176 | entries = form['entries'] |
---|
177 | if isinstance(entries, basestring): |
---|
178 | entries = [entries] |
---|
179 | deleted = [] |
---|
180 | for entry in entries: |
---|
181 | if 'remove' in form: |
---|
182 | del self.context[entry] |
---|
183 | deleted.append(entry) |
---|
184 | self.hitlist = search(query=self.searchterm, |
---|
185 | searchtype=self.searchtype, view=self) |
---|
186 | if len(deleted): |
---|
187 | self.flash('Successfully removed: %s' % ', '.join(deleted)) |
---|
188 | return |
---|
189 | |
---|
190 | class StudentsContainerAddActionButton(AddActionButton): |
---|
191 | grok.order(1) |
---|
192 | grok.context(IStudentsContainer) |
---|
193 | grok.view(StudentsContainerManagePage) |
---|
194 | grok.require('waeup.manageStudents') |
---|
195 | text = 'Add student' |
---|
196 | target = 'addstudent' |
---|
197 | |
---|
198 | class StudentAddFormPage(WAeUPAddFormPage): |
---|
199 | """Add-form to add a student. |
---|
200 | """ |
---|
201 | grok.context(IStudentsContainer) |
---|
202 | grok.require('waeup.manageStudents') |
---|
203 | grok.name('addstudent') |
---|
204 | grok.template('studentaddpage') |
---|
205 | form_fields = grok.AutoFields(IStudent) |
---|
206 | title = 'Students' |
---|
207 | label = 'Add student' |
---|
208 | |
---|
209 | @grok.action('Create student record') |
---|
210 | def addStudent(self, **data): |
---|
211 | student_id = self.request.form.get('form.student_id') |
---|
212 | student = createObject(u'waeup.Student') |
---|
213 | student.student_id = student_id |
---|
214 | self.applyData(student, **data) |
---|
215 | #import pdb; pdb.set_trace() |
---|
216 | try: |
---|
217 | self.context.addStudent(student) |
---|
218 | except KeyError: |
---|
219 | self.flash('The student id chosen already exists.') |
---|
220 | return |
---|
221 | self.flash('Student record created.') |
---|
222 | self.redirect(self.url(self.context[student_id], 'index')) |
---|
223 | return |
---|
224 | |
---|
225 | class StudentBaseDisplayFormPage(WAeUPDisplayFormPage): |
---|
226 | """ Page to display student base data |
---|
227 | """ |
---|
228 | grok.context(IStudent) |
---|
229 | grok.name('index') |
---|
230 | grok.require('waeup.viewStudents') |
---|
231 | form_fields = grok.AutoFields(IStudentBase) |
---|
232 | |
---|
233 | @property |
---|
234 | def title(self): |
---|
235 | return 'Student: %s' % self.context.name |
---|
236 | |
---|
237 | @property |
---|
238 | def label(self): |
---|
239 | return '%s: Base Data' % self.context.name |
---|
240 | |
---|
241 | class StudentBaseManageActionButton(ManageActionButton): |
---|
242 | grok.order(1) |
---|
243 | grok.context(IStudent) |
---|
244 | grok.view(StudentBaseDisplayFormPage) |
---|
245 | grok.require('waeup.manageStudents') |
---|
246 | text = 'Edit base data' |
---|
247 | target = 'edit_base' |
---|
248 | |
---|
249 | class StudentClearanceViewActionButton(ActionButton): |
---|
250 | grok.order(2) |
---|
251 | icon = 'actionicon_view.png' |
---|
252 | grok.context(IStudent) |
---|
253 | grok.view(StudentBaseDisplayFormPage) |
---|
254 | grok.require('waeup.viewStudents') |
---|
255 | text = 'View clearance data' |
---|
256 | target = 'view_clearance' |
---|
257 | |
---|
258 | class StudentPersonalViewActionButton(ActionButton): |
---|
259 | grok.order(3) |
---|
260 | icon = 'actionicon_view.png' |
---|
261 | grok.context(IStudent) |
---|
262 | grok.view(StudentBaseDisplayFormPage) |
---|
263 | grok.require('waeup.viewStudents') |
---|
264 | text = 'View personal data' |
---|
265 | target = 'view_personal' |
---|
266 | |
---|
267 | class StudentBaseManageFormPage(WAeUPEditFormPage): |
---|
268 | """ View to edit student base data |
---|
269 | """ |
---|
270 | grok.context(IStudent) |
---|
271 | grok.name('edit_base') |
---|
272 | grok.require('waeup.manageStudents') |
---|
273 | form_fields = grok.AutoFields(IStudentBase).omit('student_id') |
---|
274 | #grok.template('editstudentbase') |
---|
275 | label = 'Edit base data' |
---|
276 | |
---|
277 | @property |
---|
278 | def title(self): |
---|
279 | return 'Student: %s' % self.context.name |
---|
280 | |
---|
281 | class StudentClearanceDisplayFormPage(WAeUPDisplayFormPage): |
---|
282 | """ Page to display student clearance data |
---|
283 | """ |
---|
284 | grok.context(IStudent) |
---|
285 | grok.name('view_clearance') |
---|
286 | grok.require('waeup.viewStudents') |
---|
287 | form_fields = grok.AutoFields(IStudentClearance) |
---|
288 | |
---|
289 | @property |
---|
290 | def title(self): |
---|
291 | return 'Student: %s' % self.context.name |
---|
292 | |
---|
293 | @property |
---|
294 | def label(self): |
---|
295 | return '%s: Clearance Data' % self.context.name |
---|
296 | |
---|
297 | class StudentClearanceManageActionButton(ManageActionButton): |
---|
298 | grok.order(1) |
---|
299 | grok.context(IStudent) |
---|
300 | grok.view(StudentClearanceDisplayFormPage) |
---|
301 | grok.require('waeup.manageStudents') |
---|
302 | text = 'Edit clearance data' |
---|
303 | target = 'edit_clearance' |
---|
304 | |
---|
305 | class StudentClearanceManageFormPage(WAeUPEditFormPage): |
---|
306 | """ Page to edit student clearance data |
---|
307 | """ |
---|
308 | grok.context(IStudent) |
---|
309 | grok.name('edit_clearance') |
---|
310 | grok.require('waeup.viewStudents') |
---|
311 | form_fields = grok.AutoFields(IStudentClearance) |
---|
312 | label = 'Edit clearance data' |
---|
313 | |
---|
314 | @property |
---|
315 | def title(self): |
---|
316 | return 'Student: %s' % self.context.name |
---|
317 | |
---|
318 | class StudentPersonalDisplayFormPage(WAeUPDisplayFormPage): |
---|
319 | """ Page to display student personal data |
---|
320 | """ |
---|
321 | grok.context(IStudent) |
---|
322 | grok.name('view_personal') |
---|
323 | grok.require('waeup.viewStudents') |
---|
324 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
325 | |
---|
326 | @property |
---|
327 | def title(self): |
---|
328 | return 'Student: %s' % self.context.name |
---|
329 | |
---|
330 | @property |
---|
331 | def label(self): |
---|
332 | return '%s: Personal Data' % self.context.name |
---|
333 | |
---|
334 | class StudentPersonalManageActionButton(ManageActionButton): |
---|
335 | grok.order(1) |
---|
336 | grok.context(IStudent) |
---|
337 | grok.view(StudentPersonalDisplayFormPage) |
---|
338 | grok.require('waeup.manageStudents') |
---|
339 | text = 'Edit personal data' |
---|
340 | target = 'edit_personal' |
---|
341 | |
---|
342 | class StudentPersonalManageFormPage(WAeUPEditFormPage): |
---|
343 | """ Page to edit student clearance data |
---|
344 | """ |
---|
345 | grok.context(IStudent) |
---|
346 | grok.name('edit_personal') |
---|
347 | grok.require('waeup.viewStudents') |
---|
348 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
349 | label = 'Edit personal data' |
---|
350 | |
---|
351 | @property |
---|
352 | def title(self): |
---|
353 | return 'Student: %s' % self.context.name |
---|