source: main/waeup.kofa/trunk/src/waeup/kofa/students/viewlets.py @ 16609

Last change on this file since 16609 was 16609, checked in by Henrik Bettermann, 3 years ago

Enable students and officers to upload scanned signature in the same
way as passport pictures are handled. Some tabs and titles had to be
renamed. The placeholder file, which is still the portrait
placeholder, are no longer shown on base pages.

  • Property svn:keywords set to Id
File size: 29.4 KB
Line 
1## $Id: viewlets.py 16609 2021-09-08 07:15:07Z 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##
18import grok
19from zope.component import getUtility
20from zope.i18n import translate
21from zope.interface import Interface
22from waeup.kofa.browser.layout import default_primary_nav_template
23from waeup.kofa.browser.viewlets import (
24    PrimaryNavTab, ManageActionButton, AddActionButton)
25from waeup.kofa.interfaces import MessageFactory as _
26from waeup.kofa.interfaces import IExtFileStore, IKofaObject
27from waeup.kofa.students.browser import (
28    StudentsContainerPage, StudentsContainerManagePage,
29    StudentBaseDisplayFormPage, StudentClearanceDisplayFormPage,
30    StudentPersonalDisplayFormPage, StudyCourseDisplayFormPage,
31    StudyLevelDisplayFormPage, CourseTicketDisplayFormPage,
32    OnlinePaymentDisplayFormPage, BedTicketDisplayFormPage,
33    StudentClearanceEditFormPage, StudentPersonalEditFormPage,
34    PaymentsManageFormPage, StudyCourseTranscriptPage)
35from waeup.kofa.students.interfaces import (
36    IStudentsContainer, IStudent, IStudentStudyCourse, IStudentStudyLevel,
37    ICourseTicket, IStudentOnlinePayment, IBedTicket,
38    IStudentPaymentsContainer, IStudentsUtils,
39    )
40from waeup.kofa.students.workflow import (
41    ADMITTED, PAID, REQUESTED, CLEARED, REGISTERED, VALIDATED, GRADUATED,
42    TRANSREQ, TRANSVAL, TRANSREL)
43
44
45grok.context(IKofaObject)  # Make IKofaObject the default context
46grok.templatedir('browser_templates')
47
48
49class StudentManageSidebar(grok.ViewletManager):
50    grok.name('left_studentmanage')
51
52
53class StudentManageLink(grok.Viewlet):
54    """A link displayed in the student box which shows up for StudentNavigation
55    objects.
56
57    """
58    grok.baseclass()
59    grok.viewletmanager(StudentManageSidebar)
60    grok.context(IKofaObject)
61    grok.view(Interface)
62    grok.order(5)
63    grok.require('waeup.viewStudent')
64
65    link = 'index'
66    text = _(u'Base Data')
67
68    def render(self):
69        url = self.view.url(self.context.student, self.link)
70        # Here we know that the cookie has been set
71        lang = self.request.cookies.get('kofa.language')
72        text = translate(
73            self.text, 'waeup.kofa', target_language=lang)
74        if not self.link:
75            return ''
76        return u'<li><a href="%s">%s</a></li>' % (
77            url, text)
78
79
80class StudentManageApplicationLink(StudentManageLink):
81    grok.order(1)
82    link = 'application_slip'
83    text = _(u'Application Slip')
84
85    def render(self):
86        slip = getUtility(IExtFileStore).getFileByContext(
87            self.context.student, attr=self.link)
88        if slip:
89            lang = self.request.cookies.get('kofa.language')
90            text = translate(
91                self.text, 'waeup.kofa', target_language=lang)
92            url = self.view.url(self.context.student, self.link)
93            return u'<li><a href="%s">%s</a></li>' % (
94                url, text)
95        return ''
96
97class StudentManageBaseLink(StudentManageLink):
98    grok.order(2)
99    link = 'index'
100    text = _(u'Base Data')
101
102
103class StudentManageClearanceLink(StudentManageLink):
104    grok.order(3)
105    grok.name('studentmanageclearancelink')
106    link = 'view_clearance'
107    text = _(u'Clearance Data')
108
109
110class StudentManagePersonalLink(StudentManageLink):
111    grok.order(4)
112    grok.name('studentmanagepersonallink')
113    link = 'view_personal'
114    text = _(u'Personal Data')
115
116
117class StudentManageStudyCourseLink(StudentManageLink):
118    grok.order(5)
119    link = 'studycourse'
120    text = _(u'Study Course')
121
122
123class StudentManagePaymentsLink(StudentManageLink):
124    grok.order(6)
125    grok.require('waeup.viewStudent')
126    link = 'payments'
127    text = _(u'Payments')
128
129
130class StudentManageAccommodationLink(StudentManageLink):
131    grok.order(7)
132    grok.name('studentmanageaccommodationlink')
133    grok.require('waeup.viewStudent')
134    link = 'accommodation'
135    text = _(u'Accommodation')
136
137
138class StudentManageHistoryLink(StudentManageLink):
139    grok.order(8)
140    link = 'history'
141    text = _(u'History')
142
143
144class StudentManageTranscriptLink(StudentManageLink):
145    grok.order(9)
146    link = 'final_transcript'
147    text = _(u'Final Transcript')
148
149    def render(self):
150        slip = getUtility(IExtFileStore).getFileByContext(
151            self.context.student, attr=self.link)
152        if slip:
153            lang = self.request.cookies.get('kofa.language')
154            text = translate(
155                self.text, 'waeup.kofa', target_language=lang)
156            url = self.view.url(self.context.student, self.link)
157            return u'<li><a href="%s">%s</a></li>' % (
158                url, text)
159        return ''
160
161
162class StudentsContainerManageActionButton(ManageActionButton):
163    grok.order(1)
164    grok.context(IStudentsContainer)
165    grok.view(StudentsContainerPage)
166    grok.require('waeup.manageStudent')
167    text = _('Manage students section')
168
169
170class StudentsContainerAddActionButton(AddActionButton):
171    grok.order(1)
172    grok.context(IStudentsContainer)
173    grok.view(StudentsContainerManagePage)
174    grok.require('waeup.manageStudent')
175    text = _('Add student')
176    target = 'addstudent'
177
178
179class ContactActionButton(ManageActionButton):
180    grok.order(5)
181    grok.context(IStudent)
182    grok.view(StudentBaseDisplayFormPage)
183    grok.require('waeup.viewStudent')
184    icon = 'actionicon_mail.png'
185    text = _('Send email')
186    target = 'contactstudent'
187
188
189class StudentBaseManageActionButton(ManageActionButton):
190    grok.order(1)
191    grok.context(IStudent)
192    grok.view(StudentBaseDisplayFormPage)
193    grok.require('waeup.manageStudent')
194    text = _('Manage')
195    target = 'manage_base'
196
197
198class StudentTrigTransActionButton(ManageActionButton):
199    grok.order(2)
200    grok.context(IStudent)
201    grok.view(StudentBaseDisplayFormPage)
202    grok.require('waeup.triggerTransition')
203    icon = 'actionicon_trigtrans.png'
204    text = _(u'Trigger transition')
205    target = 'trigtrans'
206
207
208class StudentLoginAsActionButton(ManageActionButton):
209    grok.order(3)
210    grok.context(IStudent)
211    grok.view(StudentBaseDisplayFormPage)
212    grok.require('waeup.loginAsStudent')
213    icon = 'actionicon_mask.png'
214    text = _(u'Login as student')
215    target = 'loginasstep1'
216
217
218class AdmissionSlipActionButton(ManageActionButton):
219    grok.order(4)
220    grok.context(IStudent)
221    grok.view(StudentBaseDisplayFormPage)
222    grok.require('waeup.viewStudent')
223    icon = 'actionicon_pdf.png'
224    text = _('Download admission letter')
225    target = 'admission_slip.pdf'
226
227
228class StudentTransferButton(ManageActionButton):
229    grok.order(6)
230    grok.context(IStudent)
231    grok.view(StudentBaseDisplayFormPage)
232    grok.require('waeup.manageStudent')
233    text = _('Transfer student')
234    target = 'transfer'
235    icon = 'actionicon_redo.png'
236
237
238class StudentDeactivateActionButton(ManageActionButton):
239    grok.order(7)
240    grok.context(IStudent)
241    grok.view(StudentBaseDisplayFormPage)
242    grok.require('waeup.manageStudent')
243    text = _('Deactivate account')
244    target = 'deactivate'
245    icon = 'actionicon_traffic_lights_red.png'
246
247    @property
248    def target_url(self):
249        if self.context.suspended:
250            return ''
251        return self.view.url(self.view.context, self.target)
252
253    @property
254    def onclick(self):
255        return "return window.confirm(%s);" % _(
256            "'A history message will be added. Are you sure?'")
257
258
259class StudentActivateActionButton(ManageActionButton):
260    grok.order(7)
261    grok.context(IStudent)
262    grok.view(StudentBaseDisplayFormPage)
263    grok.require('waeup.manageStudent')
264    text = _('Activate account')
265    target = 'activate'
266    icon = 'actionicon_traffic_lights_green.png'
267
268    @property
269    def target_url(self):
270        if not self.context.suspended:
271            return ''
272        return self.view.url(self.view.context, self.target)
273
274    @property
275    def onclick(self):
276        return "return window.confirm(%s);" % _(
277            "'A history message will be added. Are you sure?'")
278
279
280class StudentClearanceManageActionButton(ManageActionButton):
281    grok.order(1)
282    grok.context(IStudent)
283    grok.view(StudentClearanceDisplayFormPage)
284    grok.require('waeup.manageStudent')
285    text = _('Manage')
286    target = 'manage_clearance'
287
288
289class StudentClearActionButton(ManageActionButton):
290    grok.order(2)
291    grok.context(IStudent)
292    grok.view(StudentClearanceDisplayFormPage)
293    grok.require('waeup.clearStudent')
294    text = _('Clear student')
295    target = 'clear'
296    icon = 'actionicon_accept.png'
297
298    @property
299    def target_url(self):
300        cdm = getUtility(
301            IStudentsUtils).clearance_disabled_message(self.context)
302        if cdm:
303            return ''
304        if self.context.state != REQUESTED:
305            return ''
306        return self.view.url(self.view.context, self.target)
307
308class StudentTemporarilyClearActionButton(ManageActionButton):
309    grok.order(3)
310    grok.context(IStudent)
311    grok.view(StudentClearanceDisplayFormPage)
312    grok.require('waeup.clearStudent')
313    text = _('Clear student temporarily')
314    target = 'temp_clearance'
315    icon = 'actionicon_accept.png'
316
317    @property
318    def target_url(self):
319        cdm = getUtility(
320            IStudentsUtils).clearance_disabled_message(self.context)
321        if cdm:
322            return ''
323        if self.context.officer_comment \
324            and self.context.officer_comment.startswith('Temporarily cleared'):
325            return ''
326        if self.context.state != REQUESTED:
327            return ''
328        return self.view.url(self.view.context, self.target)
329
330
331class StudentRejectClearanceActionButton(ManageActionButton):
332    grok.order(4)
333    grok.context(IStudent)
334    grok.view(StudentClearanceDisplayFormPage)
335    grok.require('waeup.clearStudent')
336    text = _('Reject clearance')
337    target = 'reject_clearance'
338    icon = 'actionicon_reject.png'
339
340    @property
341    def target_url(self):
342        cdm = getUtility(
343            IStudentsUtils).clearance_disabled_message(self.context)
344        if cdm:
345            return ''
346        if self.context.state not in (REQUESTED, CLEARED):
347            return ''
348        return self.view.url(self.view.context, self.target)
349
350
351class ClearanceSlipActionButton(ManageActionButton):
352    grok.order(5)
353    grok.context(IStudent)
354    grok.view(StudentClearanceDisplayFormPage)
355    grok.require('waeup.viewStudent')
356    icon = 'actionicon_pdf.png'
357    text = _('Download clearance slip')
358    target = 'clearance_slip.pdf'
359
360
361class ClearanceViewActionButton(ManageActionButton):
362    grok.order(1)
363    grok.context(IStudent)
364    grok.view(StudentClearanceEditFormPage)
365    grok.require('waeup.viewStudent')
366    icon = 'actionicon_view.png'
367    text = _('View')
368    target = 'view_clearance'
369
370
371class PersonalViewActionButton(ManageActionButton):
372    grok.order(1)
373    grok.context(IStudent)
374    grok.view(StudentPersonalEditFormPage)
375    grok.require('waeup.viewStudent')
376    icon = 'actionicon_view.png'
377    text = _('View')
378    target = 'view_personal'
379
380
381class StudentPersonalManageActionButton(ManageActionButton):
382    grok.order(1)
383    grok.context(IStudent)
384    grok.view(StudentPersonalDisplayFormPage)
385    grok.require('waeup.manageStudent')
386    text = _('Manage')
387    target = 'manage_personal'
388
389
390class StudentPersonalEditActionButton(ManageActionButton):
391    grok.order(2)
392    grok.context(IStudent)
393    grok.view(StudentPersonalDisplayFormPage)
394    grok.require('waeup.handleStudent')
395    text = _('Edit')
396    target = 'edit_personal'
397
398
399class StudyCourseManageActionButton(ManageActionButton):
400    grok.order(1)
401    grok.context(IStudentStudyCourse)
402    grok.view(StudyCourseDisplayFormPage)
403    grok.require('waeup.manageStudent')
404    text = _('Manage')
405    target = 'manage'
406
407    @property
408    def target_url(self):
409        if self.context.is_current:
410            return self.view.url(self.view.context, self.target)
411        return False
412
413
414class RevertTransferActionButton(ManageActionButton):
415    grok.order(1)
416    grok.context(IStudentStudyCourse)
417    grok.view(StudyCourseDisplayFormPage)
418    grok.require('waeup.manageStudent')
419    icon = 'actionicon_undo.png'
420    text = _('Reactivate this study course (revert previous transfer)')
421    target = 'revert_transfer'
422
423    @property
424    def target_url(self):
425        if self.context.is_previous:
426            return self.view.url(self.view.context.__parent__, self.target)
427        return False
428
429
430class StudyLevelManageActionButton(ManageActionButton):
431    grok.order(1)
432    grok.context(IStudentStudyLevel)
433    grok.view(StudyLevelDisplayFormPage)
434    grok.require('waeup.manageStudent')
435    text = _('Manage')
436    target = 'manage'
437
438    @property
439    def target_url(self):
440        is_current = self.context.__parent__.is_current
441        if not is_current:
442            return ''
443        return self.view.url(self.view.context, self.target)
444
445
446class StudentValidateCoursesActionButton(ManageActionButton):
447    grok.order(3)
448    grok.context(IStudentStudyLevel)
449    grok.view(StudyLevelDisplayFormPage)
450    grok.require('waeup.validateStudent')
451    text = _('Validate courses')
452    target = 'validate_courses'
453    icon = 'actionicon_accept.png'
454
455    @property
456    def target_url(self):
457        if not self.context.__parent__.is_current:
458            return ''
459        if self.context.student.state != REGISTERED:
460            return ''
461        if str(self.context.__parent__.current_level) != self.context.__name__:
462            return ''
463        return self.view.url(self.view.context, self.target)
464
465
466class StudentRejectCoursesActionButton(ManageActionButton):
467    grok.order(4)
468    grok.context(IStudentStudyLevel)
469    grok.view(StudyLevelDisplayFormPage)
470    grok.require('waeup.validateStudent')
471    text = _('Reject courses')
472    target = 'reject_courses'
473    icon = 'actionicon_reject.png'
474
475    @property
476    def target_url(self):
477        if not self.context.__parent__.is_current:
478            return ''
479        if self.context.student.state not in (VALIDATED, REGISTERED):
480            return ''
481        if str(self.context.__parent__.current_level) != self.context.__name__:
482            return ''
483        return self.view.url(self.view.context, self.target)
484
485
486class StudentUnregisterCoursesActionButton(ManageActionButton):
487    grok.order(5)
488    grok.context(IStudentStudyLevel)
489    grok.view(StudyLevelDisplayFormPage)
490    grok.require('waeup.handleStudent')
491    text = _('Unregister courses')
492    target = 'unregister_courses'
493    icon = 'actionicon_reject.png'
494
495    @property
496    def onclick(self):
497        return "return window.confirm(%s);" % _(
498            "'You really want to unregister your course list?'")
499
500    @property
501    def target_url(self):
502        if not self.context.__parent__.is_current:
503            return ''
504        if self.context.student.state != REGISTERED:
505            return ''
506        if str(self.context.__parent__.current_level) != self.context.__name__:
507            return ''
508        return self.view.url(self.view.context, self.target)
509
510
511class CourseRegistrationSlipActionButton(ManageActionButton):
512    grok.order(6)
513    grok.context(IStudentStudyLevel)
514    grok.view(StudyLevelDisplayFormPage)
515    grok.require('waeup.viewStudent')
516    icon = 'actionicon_pdf.png'
517    text = _('Download course registration slip')
518    target = 'course_registration_slip.pdf'
519
520    @property
521    def target_url(self):
522        is_current = self.context.__parent__.is_current
523        if not is_current:
524            return ''
525        return self.view.url(self.view.context, self.target)
526
527
528class CourseTicketManageActionButton(ManageActionButton):
529    grok.order(1)
530    grok.context(ICourseTicket)
531    grok.view(CourseTicketDisplayFormPage)
532    grok.require('waeup.manageStudent')
533    text = _('Manage')
534    target = 'manage'
535
536
537class PaymentReceiptActionButton(ManageActionButton):
538    grok.order(9)  # This button should always be the last one.
539    grok.context(IStudentOnlinePayment)
540    grok.view(OnlinePaymentDisplayFormPage)
541    grok.require('waeup.viewStudent')
542    icon = 'actionicon_pdf.png'
543    text = _('Download payment slip')
544    target = 'payment_slip.pdf'
545
546    @property
547    def target_url(self):
548        #if self.context.p_state != 'paid':
549        #    return ''
550        return self.view.url(self.view.context, self.target)
551
552
553class ApprovePaymentActionButton(ManageActionButton):
554    grok.order(8)
555    grok.context(IStudentOnlinePayment)
556    grok.view(OnlinePaymentDisplayFormPage)
557    grok.require('waeup.managePortal')
558    icon = 'actionicon_accept.png'
559    text = _('Approve payment')
560    target = 'approve'
561
562    @property
563    def target_url(self):
564        if self.context.p_state in ('paid', 'waived', 'scholarship'):
565            return ''
566        return self.view.url(self.view.context, self.target)
567
568
569class BedTicketSlipActionButton(ManageActionButton):
570    grok.order(1)
571    grok.context(IBedTicket)
572    grok.view(BedTicketDisplayFormPage)
573    grok.require('waeup.viewStudent')
574    icon = 'actionicon_pdf.png'
575    text = _('Download bed allocation slip')
576    target = 'bed_allocation_slip.pdf'
577
578
579class RelocateStudentActionButton(ManageActionButton):
580    grok.order(2)
581    grok.context(IBedTicket)
582    grok.view(BedTicketDisplayFormPage)
583    grok.require('waeup.manageHostels')
584    icon = 'actionicon_reload.png'
585    text = _('Relocate student')
586    target = 'relocate'
587
588
589class StudentBaseActionButton(ManageActionButton):
590    grok.order(1)
591    grok.context(IStudent)
592    grok.view(StudentBaseDisplayFormPage)
593    grok.require('waeup.handleStudent')
594    text = _('Edit')
595    target = 'edit_base'
596
597
598class StudentPasswordActionButton(ManageActionButton):
599    grok.order(2)
600    grok.context(IStudent)
601    grok.view(StudentBaseDisplayFormPage)
602    grok.require('waeup.handleStudent')
603    icon = 'actionicon_key.png'
604    text = _('Change password')
605    target = 'change_password'
606
607
608class StudentPassportActionButton(ManageActionButton):
609    grok.order(3)
610    grok.context(IStudent)
611    grok.view(StudentBaseDisplayFormPage)
612    grok.require('waeup.handleStudent')
613    icon = 'actionicon_portrait.png'
614    text = _('Change portrait')
615    target = 'change_portrait'
616
617    @property
618    def target_url(self):
619        PORTRAIT_CHANGE_STATES = getUtility(
620            IStudentsUtils).PORTRAIT_CHANGE_STATES
621        if self.context.state not in PORTRAIT_CHANGE_STATES:
622            return ''
623        return self.view.url(self.view.context, self.target)
624
625class StudentSignatureActionButton(ManageActionButton):
626    grok.order(4)
627    grok.context(IStudent)
628    grok.view(StudentBaseDisplayFormPage)
629    grok.require('waeup.handleStudent')
630    icon = 'actionicon_signature.png'
631    text = _('Change signature')
632    target = 'change_signature'
633
634    @property
635    def target_url(self):
636        SIGNATURE_CHANGE_STATES = getUtility(
637            IStudentsUtils).SIGNATURE_CHANGE_STATES
638        if self.context.state not in SIGNATURE_CHANGE_STATES:
639            return ''
640        return self.view.url(self.view.context, self.target)
641
642
643class StudentClearanceStartActionButton(ManageActionButton):
644    grok.order(1)
645    grok.context(IStudent)
646    grok.view(StudentClearanceDisplayFormPage)
647    grok.require('waeup.handleStudent')
648    icon = 'actionicon_start.gif'
649    text = _('Start clearance')
650    target = 'start_clearance'
651
652    @property
653    def target_url(self):
654        if self.context.state != ADMITTED:
655            return ''
656        return self.view.url(self.view.context, self.target)
657
658
659class StudentClearanceEditActionButton(ManageActionButton):
660    grok.order(1)
661    grok.context(IStudent)
662    grok.view(StudentClearanceDisplayFormPage)
663    grok.require('waeup.handleStudent')
664    text = _('Edit')
665    target = 'cedit'
666
667    @property
668    def target_url(self):
669        if self.context.clearance_locked:
670            return ''
671        return self.view.url(self.view.context, self.target)
672
673
674class StartSessionActionButton(ManageActionButton):
675    grok.order(1)
676    grok.context(IStudentStudyCourse)
677    grok.view(StudyCourseDisplayFormPage)
678    grok.require('waeup.handleStudent')
679    icon = 'actionicon_start.gif'
680    text = _('Start new session')
681    target = 'start_session'
682
683    @property
684    def target_url(self):
685        if self.context.next_session_allowed and self.context.is_current:
686            return self.view.url(self.view.context, self.target)
687        return False
688
689
690class AddStudyLevelActionButton(AddActionButton):
691    grok.order(1)
692    grok.context(IStudentStudyCourse)
693    grok.view(StudyCourseDisplayFormPage)
694    grok.require('waeup.handleStudent')
695    text = _('Add course list')
696    target = 'add'
697
698    @property
699    def target_url(self):
700        student = self.view.context.student
701        condition1 = student.state != PAID
702        condition2 = str(student['studycourse'].current_level) in \
703            self.view.context.keys()
704        condition3 = not self.context.is_current
705        if condition1 or condition2 or condition3:
706            return ''
707        return self.view.url(self.view.context, self.target)
708
709
710class StudyLevelEditActionButton(ManageActionButton):
711    grok.order(2)
712    grok.context(IStudentStudyLevel)
713    grok.view(StudyLevelDisplayFormPage)
714    grok.require('waeup.editStudyLevel')
715    text = _('Edit course list')
716    target = 'edit'
717
718    @property
719    def target_url(self):
720        student = self.view.context.student
721        condition1 = student.state == PAID
722        condition2 = self.view.context.is_current_level
723        is_current = self.context.__parent__.is_current
724        if condition1 and condition2 and is_current:
725            return self.view.url(self.view.context, self.target)
726        return ''
727
728
729class AddPaymentActionButton(AddActionButton):
730    grok.order(1)
731    grok.context(IStudentPaymentsContainer)
732    grok.view(PaymentsManageFormPage)
733    grok.require('waeup.payStudent')
734    text = _('Add current session payment ticket')
735    target = 'addop'
736
737
738class AddPreviousPaymentActionButton(AddActionButton):
739    grok.order(2)
740    grok.context(IStudentPaymentsContainer)
741    grok.view(PaymentsManageFormPage)
742    grok.require('waeup.payStudent')
743    grok.name('addpreviouspaymentactionbutton')
744    text = _('Add previous session payment ticket')
745    target = 'addpp'
746
747    @property
748    def target_url(self):
749        student = self.view.context.student
750        if student.before_payment or not self.target:
751            return ''
752        return self.view.url(self.view.context, self.target)
753
754
755class AddBalancePaymentActionButton(AddActionButton):
756    grok.order(3)
757    grok.context(IStudentPaymentsContainer)
758    grok.view(PaymentsManageFormPage)
759    grok.require('waeup.manageStudent')
760    grok.name('addbalancepaymentactionbutton')
761    text = _('Add balance payment ticket')
762    target = 'addbp'
763
764    @property
765    def target_url(self):
766        if not self.target:
767            return ''
768        return self.view.url(self.view.context, self.target)
769
770
771class StudyCourseTranscriptActionButton(ManageActionButton):
772    grok.order(2)
773    grok.name('transcript')
774    grok.context(IStudentStudyCourse)
775    grok.view(StudyCourseDisplayFormPage)
776    grok.require('waeup.viewTranscript')
777    text = _('Transcript')
778    target = 'transcript'
779    icon = 'actionicon_transcript.png'
780
781    @property
782    def target_url(self):
783        final_slip = getUtility(IExtFileStore).getFileByContext(
784            self.context.student, attr='final_transcript')
785        if self.context.student.transcript_enabled and not final_slip:
786            return self.view.url(self.view.context, self.target)
787        return False
788
789
790class RequestTranscriptActionButton(ManageActionButton):
791    grok.order(8)
792    grok.context(IStudent)
793    grok.view(StudentBaseDisplayFormPage)
794    grok.require('waeup.handleStudent')
795    text = _('Request transcript')
796    target = 'request_transcript'
797    icon = 'actionicon_transcript.png'
798
799    @property
800    def target_url(self):
801        if self.context.state != GRADUATED:
802            return ''
803        return self.view.url(self.view.context, self.target)
804
805class TORequestTranscriptActionButton(RequestTranscriptActionButton):
806    grok.require('waeup.processTranscript')
807    text = _('Request transcript for student')
808    target = 'request_transcript_for_student'
809
810
811class ValidateTranscriptActionButton(ManageActionButton):
812    grok.order(8)
813    grok.context(IStudentStudyCourse)
814    grok.view(StudyCourseTranscriptPage)
815    grok.require('waeup.processTranscript')
816    text = _('Validate transcript')
817    target = 'validate_transcript'
818    icon = 'actionicon_transcript.png'
819
820    @property
821    def target_url(self):
822        if self.context.student.state != TRANSREQ:
823            return ''
824        return self.view.url(self.view.context, self.target)
825
826
827class ReleaseTranscriptActionButton(ManageActionButton):
828    grok.order(8)
829    grok.context(IStudentStudyCourse)
830    grok.view(StudyCourseTranscriptPage)
831    grok.require('waeup.processTranscript')
832    text = _('Release transcript')
833    target = 'release_transcript'
834    icon = 'actionicon_transcript.png'
835
836    @property
837    def target_url(self):
838        if self.context.student.state != TRANSVAL:
839            return ''
840        return self.view.url(self.view.context, self.target)
841
842
843class TranscriptSlipActionButton(ManageActionButton):
844    grok.order(1)
845    grok.name('transcript_slip')
846    grok.context(IStudentStudyCourse)
847    grok.view(StudyCourseTranscriptPage)
848    grok.require('waeup.downloadTranscript')
849    text = _('Academic Transcript')
850    target = 'transcript.pdf'
851    icon = 'actionicon_pdf.png'
852
853    @property
854    def target_url(self):
855        final_slip = getUtility(IExtFileStore).getFileByContext(
856            self.context.student, attr='final_transcript')
857        if self.context.student.transcript_enabled \
858            and not final_slip:
859            return self.view.url(self.view.context, self.target)
860        return False
861
862
863class SignTranscriptActionButton(ManageActionButton):
864    grok.order(2)
865    grok.context(IStudentStudyCourse)
866    grok.view(StudyCourseTranscriptPage)
867    grok.require('waeup.signTranscript')
868    text = _('Sign transcript electronically')
869    target = 'sign_transcript'
870    icon = 'actionicon_transcript.png'
871
872    @property
873    def target_url(self):
874        if self.context.student.state != TRANSVAL:
875            return ''
876        return self.view.url(self.view.context, self.target)
877
878    @property
879    def onclick(self):
880        return "return window.confirm(%s);" % _(
881            "'Signing a transcript electronically cannot be revoked. "
882            "The electronic signature replaces your handwritten signature.\\n\\n"
883            "You really want to sign the transcript?'")
884
885
886class StudentsTab(PrimaryNavTab):
887    """Students tab in primary navigation.
888    """
889    grok.context(IKofaObject)
890    grok.order(4)
891    grok.require('waeup.viewStudentsContainer')
892    grok.name('studentstab')
893
894    pnav = 4
895    tab_title = _(u'Students')
896
897    @property
898    def link_target(self):
899        return self.view.application_url('students')
900
901
902class PrimaryStudentNavManager(grok.ViewletManager):
903    """Viewlet manager for the primary navigation tab.
904    """
905    grok.name('primary_nav_student')
906
907
908class PrimaryStudentNavTab(grok.Viewlet):
909    """Base for primary student nav tabs.
910    """
911    grok.baseclass()
912    grok.context(IKofaObject)
913    grok.viewletmanager(PrimaryStudentNavManager)
914    template = default_primary_nav_template
915    grok.order(1)
916    grok.require('waeup.Authenticated')
917    pnav = 0
918    tab_title = u'Some Text'
919
920    @property
921    def link_target(self):
922        return self.view.application_url()
923
924    @property
925    def active(self):
926        view_pnav = getattr(self.view, 'pnav', 0)
927        if view_pnav == self.pnav:
928            return 'active'
929        return ''
930
931
932class MyStudentDataTab(PrimaryStudentNavTab):
933    """MyData dropdown tab in primary navigation.
934    """
935    grok.order(3)
936    grok.require('waeup.viewMyStudentDataTab')
937    grok.template('mydatadropdowntabs')
938    grok.name('mystudentdatatab')
939    pnav = 4
940    tab_title = _(u'My Data')
941
942    @property
943    def active(self):
944        view_pnav = getattr(self.view, 'pnav', 0)
945        if view_pnav == self.pnav:
946            return 'active dropdown'
947        return 'dropdown'
948
949    @property
950    def targets(self):
951        student = grok.getSite()['students'][self.request.principal.id]
952        student_url = self.view.url(student)
953        app_slip = getUtility(IExtFileStore).getFileByContext(
954            student, 'application_slip')
955        targets = []
956        if student.getParentsPassword():
957            targets += [
958                {'url': student_url, 'title': 'Base Data'},
959                {'url': student_url + '/studycourse', 'title': _('Study Course')},
960                {'url': student_url + '/payments', 'title': _('Payments')},
961                ]
962            return targets
963        if app_slip:
964            targets = [{'url': student_url + '/application_slip',
965                        'title': _('Application Slip')}, ]
966        targets += [
967            {'url': student_url, 'title': 'Base Data'},
968            {'url': student_url + '/view_clearance',
969             'title': _('Clearance Data')},
970            {'url': student_url + '/view_personal',
971             'title': _('Personal Data')},
972            {'url': student_url + '/studycourse', 'title': _('Study Course')},
973            {'url': student_url + '/payments', 'title': _('Payments')},
974            {'url': student_url + '/accommodation',
975             'title': _('Accommodation Data')},
976            {'url': student_url + '/history', 'title': _('History')},
977            ]
978        return targets
Note: See TracBrowser for help on using the repository browser.