1 | ## $Id: viewlets.py 13129 2015-07-01 20:22:03Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | import grok |
---|
19 | from zope.component import getUtility |
---|
20 | from zope.interface import Interface |
---|
21 | from zope.i18n import translate |
---|
22 | from waeup.kofa.interfaces import IExtFileStore, IKofaObject |
---|
23 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
24 | from waeup.kofa.browser.viewlets import ( |
---|
25 | PrimaryNavTab, ManageActionButton, AddActionButton) |
---|
26 | from waeup.kofa.browser.layout import default_primary_nav_template |
---|
27 | from waeup.kofa.students.workflow import ( |
---|
28 | ADMITTED, PAID, REQUESTED, RETURNING, CLEARED, REGISTERED, |
---|
29 | VALIDATED, GRADUATED, TRANSCRIPT) |
---|
30 | from waeup.kofa.students.browser import ( |
---|
31 | StudentsContainerPage, |
---|
32 | StudentsContainerManagePage, StudentBaseDisplayFormPage, |
---|
33 | StudentClearanceDisplayFormPage, StudentPersonalDisplayFormPage, |
---|
34 | StudyCourseDisplayFormPage, StudyLevelDisplayFormPage, |
---|
35 | CourseTicketDisplayFormPage, OnlinePaymentDisplayFormPage, |
---|
36 | AccommodationManageFormPage, BedTicketDisplayFormPage, |
---|
37 | StudentClearanceEditFormPage, StudentPersonalEditFormPage, |
---|
38 | PaymentsManageFormPage, StudyCourseTranscriptPage) |
---|
39 | from waeup.kofa.students.interfaces import ( |
---|
40 | IStudentsContainer, IStudent, IStudentStudyCourse, IStudentAccommodation, |
---|
41 | IStudentStudyLevel, ICourseTicket, IStudentOnlinePayment, IBedTicket, |
---|
42 | IStudentPaymentsContainer, IStudentsUtils |
---|
43 | ) |
---|
44 | |
---|
45 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
46 | grok.templatedir('browser_templates') |
---|
47 | |
---|
48 | |
---|
49 | class StudentManageSidebar(grok.ViewletManager): |
---|
50 | grok.name('left_studentmanage') |
---|
51 | |
---|
52 | class StudentManageLink(grok.Viewlet): |
---|
53 | """A link displayed in the student box which shows up for StudentNavigation |
---|
54 | objects. |
---|
55 | |
---|
56 | """ |
---|
57 | grok.baseclass() |
---|
58 | grok.viewletmanager(StudentManageSidebar) |
---|
59 | grok.context(IKofaObject) |
---|
60 | grok.view(Interface) |
---|
61 | grok.order(5) |
---|
62 | grok.require('waeup.viewStudent') |
---|
63 | |
---|
64 | link = 'index' |
---|
65 | text = _(u'Base Data') |
---|
66 | |
---|
67 | def render(self): |
---|
68 | url = self.view.url(self.context.student, self.link) |
---|
69 | # Here we know that the cookie has been set |
---|
70 | lang = self.request.cookies.get('kofa.language') |
---|
71 | text = translate(self.text, 'waeup.kofa', |
---|
72 | target_language=lang) |
---|
73 | if not self.link: |
---|
74 | return '' |
---|
75 | return u'<li><a href="%s">%s</a></li>' % ( |
---|
76 | url, text) |
---|
77 | |
---|
78 | class StudentManageApplicationLink(StudentManageLink): |
---|
79 | grok.order(1) |
---|
80 | link = 'application_slip' |
---|
81 | text = _(u'Application Slip') |
---|
82 | |
---|
83 | def render(self): |
---|
84 | slip = getUtility(IExtFileStore).getFileByContext( |
---|
85 | self.context.student, attr=self.link) |
---|
86 | if slip: |
---|
87 | lang = self.request.cookies.get('kofa.language') |
---|
88 | text = translate(self.text, 'waeup.kofa', |
---|
89 | target_language=lang) |
---|
90 | url = self.view.url(self.context.student,self.link) |
---|
91 | return u'<li><a href="%s">%s</a></li>' % ( |
---|
92 | url, text) |
---|
93 | return '' |
---|
94 | |
---|
95 | class StudentManageBaseLink(StudentManageLink): |
---|
96 | grok.order(2) |
---|
97 | link = 'index' |
---|
98 | text = _(u'Base Data') |
---|
99 | |
---|
100 | class StudentManageClearanceLink(StudentManageLink): |
---|
101 | grok.order(3) |
---|
102 | grok.name('studentmanageclearancelink') |
---|
103 | link = 'view_clearance' |
---|
104 | text = _(u'Clearance Data') |
---|
105 | |
---|
106 | class StudentManagePersonalLink(StudentManageLink): |
---|
107 | grok.order(4) |
---|
108 | grok.name('studentmanagepersonallink') |
---|
109 | link = 'view_personal' |
---|
110 | text = _(u'Personal Data') |
---|
111 | |
---|
112 | class StudentManageStudyCourseLink(StudentManageLink): |
---|
113 | grok.order(5) |
---|
114 | link = 'studycourse' |
---|
115 | text = _(u'Study Course') |
---|
116 | |
---|
117 | class StudentManagePaymentsLink(StudentManageLink): |
---|
118 | grok.order(6) |
---|
119 | grok.require('waeup.viewStudent') |
---|
120 | link = 'payments' |
---|
121 | text = _(u'Payments') |
---|
122 | |
---|
123 | class StudentManageAccommodationLink(StudentManageLink): |
---|
124 | grok.order(7) |
---|
125 | grok.name('studentmanageaccommodationlink') |
---|
126 | grok.require('waeup.handleAccommodation') |
---|
127 | link = 'accommodation' |
---|
128 | text = _(u'Accommodation') |
---|
129 | |
---|
130 | class StudentManageHistoryLink(StudentManageLink): |
---|
131 | grok.order(8) |
---|
132 | link = 'history' |
---|
133 | text = _(u'History') |
---|
134 | |
---|
135 | |
---|
136 | class StudentsContainerManageActionButton(ManageActionButton): |
---|
137 | grok.order(1) |
---|
138 | grok.context(IStudentsContainer) |
---|
139 | grok.view(StudentsContainerPage) |
---|
140 | grok.require('waeup.manageStudent') |
---|
141 | text = _('Manage students section') |
---|
142 | |
---|
143 | class StudentsContainerAddActionButton(AddActionButton): |
---|
144 | grok.order(1) |
---|
145 | grok.context(IStudentsContainer) |
---|
146 | grok.view(StudentsContainerManagePage) |
---|
147 | grok.require('waeup.manageStudent') |
---|
148 | text = _('Add student') |
---|
149 | target = 'addstudent' |
---|
150 | |
---|
151 | class ContactActionButton(ManageActionButton): |
---|
152 | grok.order(5) |
---|
153 | grok.context(IStudent) |
---|
154 | grok.view(StudentBaseDisplayFormPage) |
---|
155 | grok.require('waeup.manageStudent') |
---|
156 | icon = 'actionicon_mail.png' |
---|
157 | text = _('Send email') |
---|
158 | target = 'contactstudent' |
---|
159 | |
---|
160 | class StudentBaseManageActionButton(ManageActionButton): |
---|
161 | grok.order(1) |
---|
162 | grok.context(IStudent) |
---|
163 | grok.view(StudentBaseDisplayFormPage) |
---|
164 | grok.require('waeup.manageStudent') |
---|
165 | text = _('Manage') |
---|
166 | target = 'manage_base' |
---|
167 | |
---|
168 | class StudentTrigTransActionButton(ManageActionButton): |
---|
169 | grok.order(2) |
---|
170 | grok.context(IStudent) |
---|
171 | grok.view(StudentBaseDisplayFormPage) |
---|
172 | grok.require('waeup.triggerTransition') |
---|
173 | icon = 'actionicon_trigtrans.png' |
---|
174 | text = _(u'Trigger transition') |
---|
175 | target = 'trigtrans' |
---|
176 | |
---|
177 | class StudentLoginAsActionButton(ManageActionButton): |
---|
178 | grok.order(3) |
---|
179 | grok.context(IStudent) |
---|
180 | grok.view(StudentBaseDisplayFormPage) |
---|
181 | grok.require('waeup.loginAsStudent') |
---|
182 | icon = 'actionicon_mask.png' |
---|
183 | text = _(u'Login as student') |
---|
184 | target = 'loginasstep1' |
---|
185 | |
---|
186 | class AdmissionSlipActionButton(ManageActionButton): |
---|
187 | grok.order(4) |
---|
188 | grok.context(IStudent) |
---|
189 | grok.view(StudentBaseDisplayFormPage) |
---|
190 | grok.require('waeup.viewStudent') |
---|
191 | icon = 'actionicon_pdf.png' |
---|
192 | text = _('Download admission letter') |
---|
193 | target = 'admission_slip.pdf' |
---|
194 | |
---|
195 | class StudentTransferButton(ManageActionButton): |
---|
196 | grok.order(6) |
---|
197 | grok.context(IStudent) |
---|
198 | grok.view(StudentBaseDisplayFormPage) |
---|
199 | grok.require('waeup.manageStudent') |
---|
200 | text = _('Transfer student') |
---|
201 | target = 'transfer' |
---|
202 | icon = 'actionicon_redo.png' |
---|
203 | |
---|
204 | class StudentDeactivateActionButton(ManageActionButton): |
---|
205 | grok.order(7) |
---|
206 | grok.context(IStudent) |
---|
207 | grok.view(StudentBaseDisplayFormPage) |
---|
208 | grok.require('waeup.manageStudent') |
---|
209 | text = _('Deactivate account') |
---|
210 | target = 'deactivate' |
---|
211 | icon = 'actionicon_traffic_lights_red.png' |
---|
212 | |
---|
213 | @property |
---|
214 | def target_url(self): |
---|
215 | if self.context.suspended: |
---|
216 | return '' |
---|
217 | return self.view.url(self.view.context, self.target) |
---|
218 | |
---|
219 | @property |
---|
220 | def onclick(self): |
---|
221 | return "return window.confirm(%s);" % _( |
---|
222 | "'A history message will be added. Are you sure?'") |
---|
223 | |
---|
224 | class StudentActivateActionButton(ManageActionButton): |
---|
225 | grok.order(7) |
---|
226 | grok.context(IStudent) |
---|
227 | grok.view(StudentBaseDisplayFormPage) |
---|
228 | grok.require('waeup.manageStudent') |
---|
229 | text = _('Activate account') |
---|
230 | target = 'activate' |
---|
231 | icon = 'actionicon_traffic_lights_green.png' |
---|
232 | |
---|
233 | @property |
---|
234 | def target_url(self): |
---|
235 | if not self.context.suspended: |
---|
236 | return '' |
---|
237 | return self.view.url(self.view.context, self.target) |
---|
238 | |
---|
239 | @property |
---|
240 | def onclick(self): |
---|
241 | return "return window.confirm(%s);" % _( |
---|
242 | "'A history message will be added. Are you sure?'") |
---|
243 | |
---|
244 | class StudentClearanceManageActionButton(ManageActionButton): |
---|
245 | grok.order(1) |
---|
246 | grok.context(IStudent) |
---|
247 | grok.view(StudentClearanceDisplayFormPage) |
---|
248 | grok.require('waeup.manageStudent') |
---|
249 | text = _('Manage') |
---|
250 | target = 'manage_clearance' |
---|
251 | |
---|
252 | class StudentClearActionButton(ManageActionButton): |
---|
253 | grok.order(2) |
---|
254 | grok.context(IStudent) |
---|
255 | grok.view(StudentClearanceDisplayFormPage) |
---|
256 | grok.require('waeup.clearStudent') |
---|
257 | text = _('Clear student') |
---|
258 | target = 'clear' |
---|
259 | icon = 'actionicon_accept.png' |
---|
260 | |
---|
261 | @property |
---|
262 | def target_url(self): |
---|
263 | cdm = getUtility(IStudentsUtils).clearance_disabled_message(self.context) |
---|
264 | if cdm: |
---|
265 | return '' |
---|
266 | if self.context.state != REQUESTED: |
---|
267 | return '' |
---|
268 | return self.view.url(self.view.context, self.target) |
---|
269 | |
---|
270 | class StudentRejectClearanceActionButton(ManageActionButton): |
---|
271 | grok.order(3) |
---|
272 | grok.context(IStudent) |
---|
273 | grok.view(StudentClearanceDisplayFormPage) |
---|
274 | grok.require('waeup.clearStudent') |
---|
275 | text = _('Reject clearance') |
---|
276 | target = 'reject_clearance' |
---|
277 | icon = 'actionicon_reject.png' |
---|
278 | |
---|
279 | @property |
---|
280 | def target_url(self): |
---|
281 | cdm = getUtility(IStudentsUtils).clearance_disabled_message(self.context) |
---|
282 | if cdm: |
---|
283 | return '' |
---|
284 | if self.context.state not in (REQUESTED, CLEARED): |
---|
285 | return '' |
---|
286 | return self.view.url(self.view.context, self.target) |
---|
287 | |
---|
288 | class ClearanceSlipActionButton(ManageActionButton): |
---|
289 | grok.order(4) |
---|
290 | grok.context(IStudent) |
---|
291 | grok.view(StudentClearanceDisplayFormPage) |
---|
292 | grok.require('waeup.viewStudent') |
---|
293 | icon = 'actionicon_pdf.png' |
---|
294 | text = _('Download clearance slip') |
---|
295 | target = 'clearance_slip.pdf' |
---|
296 | |
---|
297 | class ClearanceViewActionButton(ManageActionButton): |
---|
298 | grok.order(1) |
---|
299 | grok.context(IStudent) |
---|
300 | grok.view(StudentClearanceEditFormPage) |
---|
301 | grok.require('waeup.viewStudent') |
---|
302 | icon = 'actionicon_view.png' |
---|
303 | text = _('View') |
---|
304 | target = 'view_clearance' |
---|
305 | |
---|
306 | class PersonalViewActionButton(ManageActionButton): |
---|
307 | grok.order(1) |
---|
308 | grok.context(IStudent) |
---|
309 | grok.view(StudentPersonalEditFormPage) |
---|
310 | grok.require('waeup.viewStudent') |
---|
311 | icon = 'actionicon_view.png' |
---|
312 | text = _('View') |
---|
313 | target = 'view_personal' |
---|
314 | |
---|
315 | class StudentPersonalManageActionButton(ManageActionButton): |
---|
316 | grok.order(1) |
---|
317 | grok.context(IStudent) |
---|
318 | grok.view(StudentPersonalDisplayFormPage) |
---|
319 | grok.require('waeup.manageStudent') |
---|
320 | text = _('Manage') |
---|
321 | target = 'manage_personal' |
---|
322 | |
---|
323 | class StudentPersonalEditActionButton(ManageActionButton): |
---|
324 | grok.order(2) |
---|
325 | grok.context(IStudent) |
---|
326 | grok.view(StudentPersonalDisplayFormPage) |
---|
327 | grok.require('waeup.handleStudent') |
---|
328 | text = _('Edit') |
---|
329 | target = 'edit_personal' |
---|
330 | |
---|
331 | class StudyCourseManageActionButton(ManageActionButton): |
---|
332 | grok.order(1) |
---|
333 | grok.context(IStudentStudyCourse) |
---|
334 | grok.view(StudyCourseDisplayFormPage) |
---|
335 | grok.require('waeup.manageStudent') |
---|
336 | text = _('Manage') |
---|
337 | target = 'manage' |
---|
338 | |
---|
339 | @property |
---|
340 | def target_url(self): |
---|
341 | if self.context.is_current: |
---|
342 | return self.view.url(self.view.context, self.target) |
---|
343 | return False |
---|
344 | |
---|
345 | class StudyCourseTranscriptActionButton(ManageActionButton): |
---|
346 | grok.order(2) |
---|
347 | grok.context(IStudentStudyCourse) |
---|
348 | grok.view(StudyCourseDisplayFormPage) |
---|
349 | grok.require('waeup.viewTranscript') |
---|
350 | text = _('Transcript') |
---|
351 | target = 'transcript' |
---|
352 | icon = 'actionicon_transcript.png' |
---|
353 | |
---|
354 | @property |
---|
355 | def target_url(self): |
---|
356 | if self.context.student.transcript_enabled: |
---|
357 | return self.view.url(self.view.context, self.target) |
---|
358 | return False |
---|
359 | |
---|
360 | class TranscriptSlipActionButton(ManageActionButton): |
---|
361 | grok.order(1) |
---|
362 | grok.context(IStudentStudyCourse) |
---|
363 | grok.view(StudyCourseTranscriptPage) |
---|
364 | grok.require('waeup.viewTranscript') |
---|
365 | text = _('Academic Transcript') |
---|
366 | target = 'transcript.pdf' |
---|
367 | icon = 'actionicon_pdf.png' |
---|
368 | |
---|
369 | @property |
---|
370 | def target_url(self): |
---|
371 | if self.context.student.transcript_enabled: |
---|
372 | return self.view.url(self.view.context, self.target) |
---|
373 | return False |
---|
374 | |
---|
375 | class RevertTransferActionButton(ManageActionButton): |
---|
376 | grok.order(1) |
---|
377 | grok.context(IStudentStudyCourse) |
---|
378 | grok.view(StudyCourseDisplayFormPage) |
---|
379 | grok.require('waeup.manageStudent') |
---|
380 | icon = 'actionicon_undo.png' |
---|
381 | text = _('Reactivate this study course (revert previous transfer)') |
---|
382 | target = 'revert_transfer' |
---|
383 | |
---|
384 | @property |
---|
385 | def target_url(self): |
---|
386 | if self.context.is_previous: |
---|
387 | return self.view.url(self.view.context.__parent__, self.target) |
---|
388 | return False |
---|
389 | |
---|
390 | class StudyLevelManageActionButton(ManageActionButton): |
---|
391 | grok.order(1) |
---|
392 | grok.context(IStudentStudyLevel) |
---|
393 | grok.view(StudyLevelDisplayFormPage) |
---|
394 | grok.require('waeup.manageStudent') |
---|
395 | text = _('Manage') |
---|
396 | target = 'manage' |
---|
397 | |
---|
398 | @property |
---|
399 | def target_url(self): |
---|
400 | is_current = self.context.__parent__.is_current |
---|
401 | if not is_current: |
---|
402 | return '' |
---|
403 | return self.view.url(self.view.context, self.target) |
---|
404 | |
---|
405 | class StudentValidateCoursesActionButton(ManageActionButton): |
---|
406 | grok.order(3) |
---|
407 | grok.context(IStudentStudyLevel) |
---|
408 | grok.view(StudyLevelDisplayFormPage) |
---|
409 | grok.require('waeup.validateStudent') |
---|
410 | text = _('Validate courses') |
---|
411 | target = 'validate_courses' |
---|
412 | icon = 'actionicon_accept.png' |
---|
413 | |
---|
414 | @property |
---|
415 | def target_url(self): |
---|
416 | is_current = self.context.__parent__.is_current |
---|
417 | if self.context.student.state != REGISTERED or \ |
---|
418 | str(self.context.__parent__.current_level) != self.context.__name__ or\ |
---|
419 | not is_current: |
---|
420 | return '' |
---|
421 | return self.view.url(self.view.context, self.target) |
---|
422 | |
---|
423 | class StudentRejectCoursesActionButton(ManageActionButton): |
---|
424 | grok.order(4) |
---|
425 | grok.context(IStudentStudyLevel) |
---|
426 | grok.view(StudyLevelDisplayFormPage) |
---|
427 | grok.require('waeup.validateStudent') |
---|
428 | text = _('Reject courses') |
---|
429 | target = 'reject_courses' |
---|
430 | icon = 'actionicon_reject.png' |
---|
431 | |
---|
432 | @property |
---|
433 | def target_url(self): |
---|
434 | is_current = self.context.__parent__.is_current |
---|
435 | if self.context.student.state not in (VALIDATED, REGISTERED) or \ |
---|
436 | str(self.context.__parent__.current_level) != self.context.__name__ or\ |
---|
437 | not is_current: |
---|
438 | return '' |
---|
439 | return self.view.url(self.view.context, self.target) |
---|
440 | |
---|
441 | class CourseRegistrationSlipActionButton(ManageActionButton): |
---|
442 | grok.order(5) |
---|
443 | grok.context(IStudentStudyLevel) |
---|
444 | grok.view(StudyLevelDisplayFormPage) |
---|
445 | grok.require('waeup.viewStudent') |
---|
446 | icon = 'actionicon_pdf.png' |
---|
447 | text = _('Download course registration slip') |
---|
448 | target = 'course_registration_slip.pdf' |
---|
449 | |
---|
450 | @property |
---|
451 | def target_url(self): |
---|
452 | is_current = self.context.__parent__.is_current |
---|
453 | if not is_current: |
---|
454 | return '' |
---|
455 | return self.view.url(self.view.context, self.target) |
---|
456 | |
---|
457 | class CourseTicketManageActionButton(ManageActionButton): |
---|
458 | grok.order(1) |
---|
459 | grok.context(ICourseTicket) |
---|
460 | grok.view(CourseTicketDisplayFormPage) |
---|
461 | grok.require('waeup.manageStudent') |
---|
462 | text = _('Manage') |
---|
463 | target = 'manage' |
---|
464 | |
---|
465 | #class OnlinePaymentManageActionButton(ManageActionButton): |
---|
466 | # grok.order(1) |
---|
467 | # grok.context(IStudentPaymentsContainer) |
---|
468 | # grok.view(PaymentsDisplayFormPage) |
---|
469 | # grok.require('waeup.manageStudent') |
---|
470 | # text = 'Manage payments' |
---|
471 | # target = 'manage' |
---|
472 | |
---|
473 | class PaymentReceiptActionButton(ManageActionButton): |
---|
474 | grok.order(9) # This button should always be the last one. |
---|
475 | grok.context(IStudentOnlinePayment) |
---|
476 | grok.view(OnlinePaymentDisplayFormPage) |
---|
477 | grok.require('waeup.viewStudent') |
---|
478 | icon = 'actionicon_pdf.png' |
---|
479 | text = _('Download payment slip') |
---|
480 | target = 'payment_slip.pdf' |
---|
481 | |
---|
482 | @property |
---|
483 | def target_url(self): |
---|
484 | #if self.context.p_state != 'paid': |
---|
485 | # return '' |
---|
486 | return self.view.url(self.view.context, self.target) |
---|
487 | |
---|
488 | class ApprovePaymentActionButton(ManageActionButton): |
---|
489 | grok.order(8) |
---|
490 | grok.context(IStudentOnlinePayment) |
---|
491 | grok.view(OnlinePaymentDisplayFormPage) |
---|
492 | grok.require('waeup.managePortal') |
---|
493 | icon = 'actionicon_accept.png' |
---|
494 | text = _('Approve payment') |
---|
495 | target = 'approve' |
---|
496 | |
---|
497 | @property |
---|
498 | def target_url(self): |
---|
499 | if self.context.p_state == 'paid': |
---|
500 | return '' |
---|
501 | return self.view.url(self.view.context, self.target) |
---|
502 | |
---|
503 | class AddBedTicketActionButton(ManageActionButton): |
---|
504 | grok.order(1) |
---|
505 | grok.context(IStudentAccommodation) |
---|
506 | grok.view(AccommodationManageFormPage) |
---|
507 | grok.require('waeup.handleAccommodation') |
---|
508 | icon = 'actionicon_home.png' |
---|
509 | text = _('Book accommodation') |
---|
510 | target = 'add' |
---|
511 | |
---|
512 | class BedTicketSlipActionButton(ManageActionButton): |
---|
513 | grok.order(1) |
---|
514 | grok.context(IBedTicket) |
---|
515 | grok.view(BedTicketDisplayFormPage) |
---|
516 | grok.require('waeup.handleAccommodation') |
---|
517 | icon = 'actionicon_pdf.png' |
---|
518 | text = _('Download bed allocation slip') |
---|
519 | target = 'bed_allocation_slip.pdf' |
---|
520 | |
---|
521 | class RelocateStudentActionButton(ManageActionButton): |
---|
522 | grok.order(2) |
---|
523 | grok.context(IBedTicket) |
---|
524 | grok.view(BedTicketDisplayFormPage) |
---|
525 | grok.require('waeup.manageHostels') |
---|
526 | icon = 'actionicon_reload.png' |
---|
527 | text = _('Relocate student') |
---|
528 | target = 'relocate' |
---|
529 | |
---|
530 | class StudentBaseActionButton(ManageActionButton): |
---|
531 | grok.order(1) |
---|
532 | grok.context(IStudent) |
---|
533 | grok.view(StudentBaseDisplayFormPage) |
---|
534 | grok.require('waeup.handleStudent') |
---|
535 | text = _('Edit') |
---|
536 | target = 'edit_base' |
---|
537 | |
---|
538 | class StudentPasswordActionButton(ManageActionButton): |
---|
539 | grok.order(2) |
---|
540 | grok.context(IStudent) |
---|
541 | grok.view(StudentBaseDisplayFormPage) |
---|
542 | grok.require('waeup.handleStudent') |
---|
543 | icon = 'actionicon_key.png' |
---|
544 | text = _('Change password') |
---|
545 | target = 'change_password' |
---|
546 | |
---|
547 | class StudentPassportActionButton(ManageActionButton): |
---|
548 | grok.order(3) |
---|
549 | grok.context(IStudent) |
---|
550 | grok.view(StudentBaseDisplayFormPage) |
---|
551 | grok.require('waeup.handleStudent') |
---|
552 | icon = 'actionicon_portrait.png' |
---|
553 | text = _('Change portrait') |
---|
554 | target = 'change_portrait' |
---|
555 | |
---|
556 | @property |
---|
557 | def target_url(self): |
---|
558 | PORTRAIT_CHANGE_STATES = getUtility(IStudentsUtils).PORTRAIT_CHANGE_STATES |
---|
559 | if self.context.state not in PORTRAIT_CHANGE_STATES: |
---|
560 | return '' |
---|
561 | return self.view.url(self.view.context, self.target) |
---|
562 | |
---|
563 | class StudentClearanceStartActionButton(ManageActionButton): |
---|
564 | grok.order(1) |
---|
565 | grok.context(IStudent) |
---|
566 | grok.view(StudentClearanceDisplayFormPage) |
---|
567 | grok.require('waeup.handleStudent') |
---|
568 | icon = 'actionicon_start.gif' |
---|
569 | text = _('Start clearance') |
---|
570 | target = 'start_clearance' |
---|
571 | |
---|
572 | @property |
---|
573 | def target_url(self): |
---|
574 | if self.context.state != ADMITTED: |
---|
575 | return '' |
---|
576 | return self.view.url(self.view.context, self.target) |
---|
577 | |
---|
578 | class StudentClearanceEditActionButton(ManageActionButton): |
---|
579 | grok.order(1) |
---|
580 | grok.context(IStudent) |
---|
581 | grok.view(StudentClearanceDisplayFormPage) |
---|
582 | grok.require('waeup.handleStudent') |
---|
583 | text = _('Edit') |
---|
584 | target = 'cedit' |
---|
585 | |
---|
586 | @property |
---|
587 | def target_url(self): |
---|
588 | if self.context.clearance_locked: |
---|
589 | return '' |
---|
590 | return self.view.url(self.view.context, self.target) |
---|
591 | |
---|
592 | class StartSessionActionButton(ManageActionButton): |
---|
593 | grok.order(1) |
---|
594 | grok.context(IStudentStudyCourse) |
---|
595 | grok.view(StudyCourseDisplayFormPage) |
---|
596 | grok.require('waeup.handleStudent') |
---|
597 | icon = 'actionicon_start.gif' |
---|
598 | text = _('Start new session') |
---|
599 | target = 'start_session' |
---|
600 | |
---|
601 | @property |
---|
602 | def target_url(self): |
---|
603 | if self.context.next_session_allowed and self.context.is_current: |
---|
604 | return self.view.url(self.view.context, self.target) |
---|
605 | return False |
---|
606 | |
---|
607 | class AddStudyLevelActionButton(AddActionButton): |
---|
608 | grok.order(1) |
---|
609 | grok.context(IStudentStudyCourse) |
---|
610 | grok.view(StudyCourseDisplayFormPage) |
---|
611 | grok.require('waeup.handleStudent') |
---|
612 | text = _('Add course list') |
---|
613 | target = 'add' |
---|
614 | |
---|
615 | @property |
---|
616 | def target_url(self): |
---|
617 | student = self.view.context.student |
---|
618 | condition1 = student.state != PAID |
---|
619 | condition2 = str(student['studycourse'].current_level) in \ |
---|
620 | self.view.context.keys() |
---|
621 | condition3 = not self.context.is_current |
---|
622 | if condition1 or condition2 or condition3: |
---|
623 | return '' |
---|
624 | return self.view.url(self.view.context, self.target) |
---|
625 | |
---|
626 | class StudyLevelEditActionButton(ManageActionButton): |
---|
627 | grok.order(2) |
---|
628 | grok.context(IStudentStudyLevel) |
---|
629 | grok.view(StudyLevelDisplayFormPage) |
---|
630 | grok.require('waeup.editStudyLevel') |
---|
631 | text = _('Edit course list') |
---|
632 | target = 'edit' |
---|
633 | |
---|
634 | @property |
---|
635 | def target_url(self): |
---|
636 | student = self.view.context.student |
---|
637 | condition1 = student.state == PAID |
---|
638 | condition2 = self.view.context.is_current_level |
---|
639 | is_current = self.context.__parent__.is_current |
---|
640 | if condition1 and condition2 and is_current: |
---|
641 | return self.view.url(self.view.context, self.target) |
---|
642 | return '' |
---|
643 | |
---|
644 | class AddPaymentActionButton(AddActionButton): |
---|
645 | grok.order(1) |
---|
646 | grok.context(IStudentPaymentsContainer) |
---|
647 | grok.view(PaymentsManageFormPage) |
---|
648 | grok.require('waeup.payStudent') |
---|
649 | text = _('Add current session payment ticket') |
---|
650 | target = 'addop' |
---|
651 | |
---|
652 | class AddPreviousPaymentActionButton(AddActionButton): |
---|
653 | grok.order(2) |
---|
654 | grok.context(IStudentPaymentsContainer) |
---|
655 | grok.view(PaymentsManageFormPage) |
---|
656 | grok.require('waeup.payStudent') |
---|
657 | grok.name('addpreviouspaymentactionbutton') |
---|
658 | text = _('Add previous session payment ticket') |
---|
659 | target = 'addpp' |
---|
660 | |
---|
661 | @property |
---|
662 | def target_url(self): |
---|
663 | student = self.view.context.student |
---|
664 | if student.before_payment or not self.target: |
---|
665 | return '' |
---|
666 | return self.view.url(self.view.context, self.target) |
---|
667 | |
---|
668 | class AddBalancePaymentActionButton(AddActionButton): |
---|
669 | grok.order(3) |
---|
670 | grok.context(IStudentPaymentsContainer) |
---|
671 | grok.view(PaymentsManageFormPage) |
---|
672 | grok.require('waeup.manageStudent') |
---|
673 | grok.name('addbalancepaymentactionbutton') |
---|
674 | text = _('Add balance payment ticket') |
---|
675 | target = 'addbp' |
---|
676 | |
---|
677 | @property |
---|
678 | def target_url(self): |
---|
679 | if not self.target: |
---|
680 | return '' |
---|
681 | return self.view.url(self.view.context, self.target) |
---|
682 | |
---|
683 | class RequestTranscriptActionButton(ManageActionButton): |
---|
684 | grok.order(8) |
---|
685 | grok.context(IStudent) |
---|
686 | grok.view(StudentBaseDisplayFormPage) |
---|
687 | grok.require('waeup.handleStudent') |
---|
688 | text = _('Request transcript') |
---|
689 | target = 'request_transcript' |
---|
690 | icon = 'actionicon_transcript.png' |
---|
691 | |
---|
692 | @property |
---|
693 | def target_url(self): |
---|
694 | if self.context.state != GRADUATED: |
---|
695 | return '' |
---|
696 | return self.view.url(self.view.context, self.target) |
---|
697 | |
---|
698 | class ProcessTranscriptRequestActionButton(ManageActionButton): |
---|
699 | grok.order(9) |
---|
700 | grok.context(IStudent) |
---|
701 | grok.view(StudentBaseDisplayFormPage) |
---|
702 | grok.require('waeup.viewTranscript') |
---|
703 | text = _('Manage transcript request') |
---|
704 | target = 'process_transcript_request' |
---|
705 | icon = 'actionicon_transcript.png' |
---|
706 | |
---|
707 | @property |
---|
708 | def target_url(self): |
---|
709 | if self.context.state != TRANSCRIPT: |
---|
710 | return '' |
---|
711 | return self.view.url(self.view.context, self.target) |
---|
712 | |
---|
713 | class StudentsTab(PrimaryNavTab): |
---|
714 | """Students tab in primary navigation. |
---|
715 | """ |
---|
716 | |
---|
717 | grok.context(IKofaObject) |
---|
718 | grok.order(4) |
---|
719 | grok.require('waeup.viewStudentsContainer') |
---|
720 | grok.name('studentstab') |
---|
721 | |
---|
722 | pnav = 4 |
---|
723 | tab_title = _(u'Students') |
---|
724 | |
---|
725 | @property |
---|
726 | def link_target(self): |
---|
727 | return self.view.application_url('students') |
---|
728 | |
---|
729 | class PrimaryStudentNavManager(grok.ViewletManager): |
---|
730 | """Viewlet manager for the primary navigation tab. |
---|
731 | """ |
---|
732 | grok.name('primary_nav_student') |
---|
733 | |
---|
734 | class PrimaryStudentNavTab(grok.Viewlet): |
---|
735 | """Base for primary student nav tabs. |
---|
736 | """ |
---|
737 | grok.baseclass() |
---|
738 | grok.context(IKofaObject) |
---|
739 | grok.viewletmanager(PrimaryStudentNavManager) |
---|
740 | template = default_primary_nav_template |
---|
741 | grok.order(1) |
---|
742 | grok.require('waeup.Authenticated') |
---|
743 | pnav = 0 |
---|
744 | tab_title = u'Some Text' |
---|
745 | |
---|
746 | @property |
---|
747 | def link_target(self): |
---|
748 | return self.view.application_url() |
---|
749 | |
---|
750 | @property |
---|
751 | def active(self): |
---|
752 | view_pnav = getattr(self.view, 'pnav', 0) |
---|
753 | if view_pnav == self.pnav: |
---|
754 | return 'active' |
---|
755 | return '' |
---|
756 | |
---|
757 | class MyStudentDataTab(PrimaryStudentNavTab): |
---|
758 | """MyData dropdown tab in primary navigation. |
---|
759 | """ |
---|
760 | grok.order(3) |
---|
761 | grok.require('waeup.viewMyStudentDataTab') |
---|
762 | grok.template('mydatadropdowntabs') |
---|
763 | grok.name('mystudentdatatab') |
---|
764 | pnav = 4 |
---|
765 | tab_title = _(u'My Data') |
---|
766 | |
---|
767 | @property |
---|
768 | def active(self): |
---|
769 | view_pnav = getattr(self.view, 'pnav', 0) |
---|
770 | if view_pnav == self.pnav: |
---|
771 | return 'active dropdown' |
---|
772 | return 'dropdown' |
---|
773 | |
---|
774 | @property |
---|
775 | def targets(self): |
---|
776 | student = grok.getSite()['students'][self.request.principal.id] |
---|
777 | student_url = self.view.url(student) |
---|
778 | app_slip = getUtility(IExtFileStore).getFileByContext( |
---|
779 | student, 'application_slip') |
---|
780 | targets = [] |
---|
781 | if app_slip: |
---|
782 | targets = [{'url':student_url + '/application_slip', |
---|
783 | 'title':_('Application Slip')},] |
---|
784 | targets += [ |
---|
785 | {'url':student_url, 'title':'Base Data'}, |
---|
786 | {'url':student_url + '/view_clearance', |
---|
787 | 'title':_('Clearance Data')}, |
---|
788 | {'url':student_url + '/view_personal', 'title':_('Personal Data')}, |
---|
789 | {'url':student_url + '/studycourse', 'title':_('Study Course')}, |
---|
790 | {'url':student_url + '/payments', 'title':_('Payments')}, |
---|
791 | {'url':student_url + '/accommodation', |
---|
792 | 'title':_('Accommodation Data')}, |
---|
793 | {'url':student_url + '/history', 'title':_('History')}, |
---|
794 | ] |
---|
795 | return targets |
---|