source: main/waeup.kofa/branches/uli-py3/src/waeup/kofa/students/viewlets.py @ 17238

Last change on this file since 17238 was 15972, checked in by Henrik Bettermann, 5 years ago

Add AccommodationDisplayFormPage

  • Property svn:keywords set to Id
File size: 27.9 KB
Line 
1## $Id: viewlets.py 15972 2020-01-31 16:16:18Z 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.manageStudent')
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
308
309class StudentRejectClearanceActionButton(ManageActionButton):
310    grok.order(3)
311    grok.context(IStudent)
312    grok.view(StudentClearanceDisplayFormPage)
313    grok.require('waeup.clearStudent')
314    text = _('Reject clearance')
315    target = 'reject_clearance'
316    icon = 'actionicon_reject.png'
317
318    @property
319    def target_url(self):
320        cdm = getUtility(
321            IStudentsUtils).clearance_disabled_message(self.context)
322        if cdm:
323            return ''
324        if self.context.state not in (REQUESTED, CLEARED):
325            return ''
326        return self.view.url(self.view.context, self.target)
327
328
329class ClearanceSlipActionButton(ManageActionButton):
330    grok.order(4)
331    grok.context(IStudent)
332    grok.view(StudentClearanceDisplayFormPage)
333    grok.require('waeup.viewStudent')
334    icon = 'actionicon_pdf.png'
335    text = _('Download clearance slip')
336    target = 'clearance_slip.pdf'
337
338
339class ClearanceViewActionButton(ManageActionButton):
340    grok.order(1)
341    grok.context(IStudent)
342    grok.view(StudentClearanceEditFormPage)
343    grok.require('waeup.viewStudent')
344    icon = 'actionicon_view.png'
345    text = _('View')
346    target = 'view_clearance'
347
348
349class PersonalViewActionButton(ManageActionButton):
350    grok.order(1)
351    grok.context(IStudent)
352    grok.view(StudentPersonalEditFormPage)
353    grok.require('waeup.viewStudent')
354    icon = 'actionicon_view.png'
355    text = _('View')
356    target = 'view_personal'
357
358
359class StudentPersonalManageActionButton(ManageActionButton):
360    grok.order(1)
361    grok.context(IStudent)
362    grok.view(StudentPersonalDisplayFormPage)
363    grok.require('waeup.manageStudent')
364    text = _('Manage')
365    target = 'manage_personal'
366
367
368class StudentPersonalEditActionButton(ManageActionButton):
369    grok.order(2)
370    grok.context(IStudent)
371    grok.view(StudentPersonalDisplayFormPage)
372    grok.require('waeup.handleStudent')
373    text = _('Edit')
374    target = 'edit_personal'
375
376
377class StudyCourseManageActionButton(ManageActionButton):
378    grok.order(1)
379    grok.context(IStudentStudyCourse)
380    grok.view(StudyCourseDisplayFormPage)
381    grok.require('waeup.manageStudent')
382    text = _('Manage')
383    target = 'manage'
384
385    @property
386    def target_url(self):
387        if self.context.is_current:
388            return self.view.url(self.view.context, self.target)
389        return False
390
391
392class RevertTransferActionButton(ManageActionButton):
393    grok.order(1)
394    grok.context(IStudentStudyCourse)
395    grok.view(StudyCourseDisplayFormPage)
396    grok.require('waeup.manageStudent')
397    icon = 'actionicon_undo.png'
398    text = _('Reactivate this study course (revert previous transfer)')
399    target = 'revert_transfer'
400
401    @property
402    def target_url(self):
403        if self.context.is_previous:
404            return self.view.url(self.view.context.__parent__, self.target)
405        return False
406
407
408class StudyLevelManageActionButton(ManageActionButton):
409    grok.order(1)
410    grok.context(IStudentStudyLevel)
411    grok.view(StudyLevelDisplayFormPage)
412    grok.require('waeup.manageStudent')
413    text = _('Manage')
414    target = 'manage'
415
416    @property
417    def target_url(self):
418        is_current = self.context.__parent__.is_current
419        if not is_current:
420            return ''
421        return self.view.url(self.view.context, self.target)
422
423
424class StudentValidateCoursesActionButton(ManageActionButton):
425    grok.order(3)
426    grok.context(IStudentStudyLevel)
427    grok.view(StudyLevelDisplayFormPage)
428    grok.require('waeup.validateStudent')
429    text = _('Validate courses')
430    target = 'validate_courses'
431    icon = 'actionicon_accept.png'
432
433    @property
434    def target_url(self):
435        if not self.context.__parent__.is_current:
436            return ''
437        if self.context.student.state != REGISTERED:
438            return ''
439        if str(self.context.__parent__.current_level) != self.context.__name__:
440            return ''
441        return self.view.url(self.view.context, self.target)
442
443
444class StudentRejectCoursesActionButton(ManageActionButton):
445    grok.order(4)
446    grok.context(IStudentStudyLevel)
447    grok.view(StudyLevelDisplayFormPage)
448    grok.require('waeup.validateStudent')
449    text = _('Reject courses')
450    target = 'reject_courses'
451    icon = 'actionicon_reject.png'
452
453    @property
454    def target_url(self):
455        if not self.context.__parent__.is_current:
456            return ''
457        if self.context.student.state not in (VALIDATED, REGISTERED):
458            return ''
459        if str(self.context.__parent__.current_level) != self.context.__name__:
460            return ''
461        return self.view.url(self.view.context, self.target)
462
463
464class StudentUnregisterCoursesActionButton(ManageActionButton):
465    grok.order(5)
466    grok.context(IStudentStudyLevel)
467    grok.view(StudyLevelDisplayFormPage)
468    grok.require('waeup.handleStudent')
469    text = _('Unregister courses')
470    target = 'unregister_courses'
471    icon = 'actionicon_reject.png'
472
473    @property
474    def onclick(self):
475        return "return window.confirm(%s);" % _(
476            "'You really want to unregister your course list?'")
477
478    @property
479    def target_url(self):
480        if not self.context.__parent__.is_current:
481            return ''
482        if self.context.student.state != REGISTERED:
483            return ''
484        if str(self.context.__parent__.current_level) != self.context.__name__:
485            return ''
486        return self.view.url(self.view.context, self.target)
487
488
489class CourseRegistrationSlipActionButton(ManageActionButton):
490    grok.order(6)
491    grok.context(IStudentStudyLevel)
492    grok.view(StudyLevelDisplayFormPage)
493    grok.require('waeup.viewStudent')
494    icon = 'actionicon_pdf.png'
495    text = _('Download course registration slip')
496    target = 'course_registration_slip.pdf'
497
498    @property
499    def target_url(self):
500        is_current = self.context.__parent__.is_current
501        if not is_current:
502            return ''
503        return self.view.url(self.view.context, self.target)
504
505
506class CourseTicketManageActionButton(ManageActionButton):
507    grok.order(1)
508    grok.context(ICourseTicket)
509    grok.view(CourseTicketDisplayFormPage)
510    grok.require('waeup.manageStudent')
511    text = _('Manage')
512    target = 'manage'
513
514
515class PaymentReceiptActionButton(ManageActionButton):
516    grok.order(9)  # This button should always be the last one.
517    grok.context(IStudentOnlinePayment)
518    grok.view(OnlinePaymentDisplayFormPage)
519    grok.require('waeup.viewStudent')
520    icon = 'actionicon_pdf.png'
521    text = _('Download payment slip')
522    target = 'payment_slip.pdf'
523
524    @property
525    def target_url(self):
526        #if self.context.p_state != 'paid':
527        #    return ''
528        return self.view.url(self.view.context, self.target)
529
530
531class ApprovePaymentActionButton(ManageActionButton):
532    grok.order(8)
533    grok.context(IStudentOnlinePayment)
534    grok.view(OnlinePaymentDisplayFormPage)
535    grok.require('waeup.managePortal')
536    icon = 'actionicon_accept.png'
537    text = _('Approve payment')
538    target = 'approve'
539
540    @property
541    def target_url(self):
542        if self.context.p_state in ('paid', 'waived', 'scholarship'):
543            return ''
544        return self.view.url(self.view.context, self.target)
545
546
547class BedTicketSlipActionButton(ManageActionButton):
548    grok.order(1)
549    grok.context(IBedTicket)
550    grok.view(BedTicketDisplayFormPage)
551    grok.require('waeup.viewStudent')
552    icon = 'actionicon_pdf.png'
553    text = _('Download bed allocation slip')
554    target = 'bed_allocation_slip.pdf'
555
556
557class RelocateStudentActionButton(ManageActionButton):
558    grok.order(2)
559    grok.context(IBedTicket)
560    grok.view(BedTicketDisplayFormPage)
561    grok.require('waeup.manageHostels')
562    icon = 'actionicon_reload.png'
563    text = _('Relocate student')
564    target = 'relocate'
565
566
567class StudentBaseActionButton(ManageActionButton):
568    grok.order(1)
569    grok.context(IStudent)
570    grok.view(StudentBaseDisplayFormPage)
571    grok.require('waeup.handleStudent')
572    text = _('Edit')
573    target = 'edit_base'
574
575
576class StudentPasswordActionButton(ManageActionButton):
577    grok.order(2)
578    grok.context(IStudent)
579    grok.view(StudentBaseDisplayFormPage)
580    grok.require('waeup.handleStudent')
581    icon = 'actionicon_key.png'
582    text = _('Change password')
583    target = 'change_password'
584
585
586class StudentPassportActionButton(ManageActionButton):
587    grok.order(3)
588    grok.context(IStudent)
589    grok.view(StudentBaseDisplayFormPage)
590    grok.require('waeup.handleStudent')
591    icon = 'actionicon_portrait.png'
592    text = _('Change portrait')
593    target = 'change_portrait'
594
595    @property
596    def target_url(self):
597        PORTRAIT_CHANGE_STATES = getUtility(
598            IStudentsUtils).PORTRAIT_CHANGE_STATES
599        if self.context.state not in PORTRAIT_CHANGE_STATES:
600            return ''
601        return self.view.url(self.view.context, self.target)
602
603
604class StudentClearanceStartActionButton(ManageActionButton):
605    grok.order(1)
606    grok.context(IStudent)
607    grok.view(StudentClearanceDisplayFormPage)
608    grok.require('waeup.handleStudent')
609    icon = 'actionicon_start.gif'
610    text = _('Start clearance')
611    target = 'start_clearance'
612
613    @property
614    def target_url(self):
615        if self.context.state != ADMITTED:
616            return ''
617        return self.view.url(self.view.context, self.target)
618
619
620class StudentClearanceEditActionButton(ManageActionButton):
621    grok.order(1)
622    grok.context(IStudent)
623    grok.view(StudentClearanceDisplayFormPage)
624    grok.require('waeup.handleStudent')
625    text = _('Edit')
626    target = 'cedit'
627
628    @property
629    def target_url(self):
630        if self.context.clearance_locked:
631            return ''
632        return self.view.url(self.view.context, self.target)
633
634
635class StartSessionActionButton(ManageActionButton):
636    grok.order(1)
637    grok.context(IStudentStudyCourse)
638    grok.view(StudyCourseDisplayFormPage)
639    grok.require('waeup.handleStudent')
640    icon = 'actionicon_start.gif'
641    text = _('Start new session')
642    target = 'start_session'
643
644    @property
645    def target_url(self):
646        if self.context.next_session_allowed and self.context.is_current:
647            return self.view.url(self.view.context, self.target)
648        return False
649
650
651class AddStudyLevelActionButton(AddActionButton):
652    grok.order(1)
653    grok.context(IStudentStudyCourse)
654    grok.view(StudyCourseDisplayFormPage)
655    grok.require('waeup.handleStudent')
656    text = _('Add course list')
657    target = 'add'
658
659    @property
660    def target_url(self):
661        student = self.view.context.student
662        condition1 = student.state != PAID
663        condition2 = str(student['studycourse'].current_level) in \
664            self.view.context.keys()
665        condition3 = not self.context.is_current
666        if condition1 or condition2 or condition3:
667            return ''
668        return self.view.url(self.view.context, self.target)
669
670
671class StudyLevelEditActionButton(ManageActionButton):
672    grok.order(2)
673    grok.context(IStudentStudyLevel)
674    grok.view(StudyLevelDisplayFormPage)
675    grok.require('waeup.editStudyLevel')
676    text = _('Edit course list')
677    target = 'edit'
678
679    @property
680    def target_url(self):
681        student = self.view.context.student
682        condition1 = student.state == PAID
683        condition2 = self.view.context.is_current_level
684        is_current = self.context.__parent__.is_current
685        if condition1 and condition2 and is_current:
686            return self.view.url(self.view.context, self.target)
687        return ''
688
689
690class AddPaymentActionButton(AddActionButton):
691    grok.order(1)
692    grok.context(IStudentPaymentsContainer)
693    grok.view(PaymentsManageFormPage)
694    grok.require('waeup.payStudent')
695    text = _('Add current session payment ticket')
696    target = 'addop'
697
698
699class AddPreviousPaymentActionButton(AddActionButton):
700    grok.order(2)
701    grok.context(IStudentPaymentsContainer)
702    grok.view(PaymentsManageFormPage)
703    grok.require('waeup.payStudent')
704    grok.name('addpreviouspaymentactionbutton')
705    text = _('Add previous session payment ticket')
706    target = 'addpp'
707
708    @property
709    def target_url(self):
710        student = self.view.context.student
711        if student.before_payment or not self.target:
712            return ''
713        return self.view.url(self.view.context, self.target)
714
715
716class AddBalancePaymentActionButton(AddActionButton):
717    grok.order(3)
718    grok.context(IStudentPaymentsContainer)
719    grok.view(PaymentsManageFormPage)
720    grok.require('waeup.manageStudent')
721    grok.name('addbalancepaymentactionbutton')
722    text = _('Add balance payment ticket')
723    target = 'addbp'
724
725    @property
726    def target_url(self):
727        if not self.target:
728            return ''
729        return self.view.url(self.view.context, self.target)
730
731
732class StudyCourseTranscriptActionButton(ManageActionButton):
733    grok.order(2)
734    grok.name('transcript')
735    grok.context(IStudentStudyCourse)
736    grok.view(StudyCourseDisplayFormPage)
737    grok.require('waeup.viewTranscript')
738    text = _('Transcript')
739    target = 'transcript'
740    icon = 'actionicon_transcript.png'
741
742    @property
743    def target_url(self):
744        final_slip = getUtility(IExtFileStore).getFileByContext(
745            self.context.student, attr='final_transcript')
746        if self.context.student.transcript_enabled and not final_slip:
747            return self.view.url(self.view.context, self.target)
748        return False
749
750
751class RequestTranscriptActionButton(ManageActionButton):
752    grok.order(8)
753    grok.context(IStudent)
754    grok.view(StudentBaseDisplayFormPage)
755    grok.require('waeup.handleStudent')
756    text = _('Request transcript')
757    target = 'request_transcript'
758    icon = 'actionicon_transcript.png'
759
760    @property
761    def target_url(self):
762        if self.context.state != GRADUATED:
763            return ''
764        return self.view.url(self.view.context, self.target)
765
766
767class ValidateTranscriptActionButton(ManageActionButton):
768    grok.order(8)
769    grok.context(IStudentStudyCourse)
770    grok.view(StudyCourseTranscriptPage)
771    grok.require('waeup.processTranscript')
772    text = _('Validate transcript')
773    target = 'validate_transcript'
774    icon = 'actionicon_transcript.png'
775
776    @property
777    def target_url(self):
778        if self.context.student.state != TRANSREQ:
779            return ''
780        return self.view.url(self.view.context, self.target)
781
782
783class ReleaseTranscriptActionButton(ManageActionButton):
784    grok.order(8)
785    grok.context(IStudentStudyCourse)
786    grok.view(StudyCourseTranscriptPage)
787    grok.require('waeup.processTranscript')
788    text = _('Release transcript')
789    target = 'release_transcript'
790    icon = 'actionicon_transcript.png'
791
792    @property
793    def target_url(self):
794        if self.context.student.state != TRANSVAL:
795            return ''
796        return self.view.url(self.view.context, self.target)
797
798
799class TranscriptSlipActionButton(ManageActionButton):
800    grok.order(1)
801    grok.name('transcript_slip')
802    grok.context(IStudentStudyCourse)
803    grok.view(StudyCourseTranscriptPage)
804    grok.require('waeup.viewTranscript')
805    text = _('Academic Transcript')
806    target = 'transcript.pdf'
807    icon = 'actionicon_pdf.png'
808
809    @property
810    def target_url(self):
811        final_slip = getUtility(IExtFileStore).getFileByContext(
812            self.context.student, attr='final_transcript')
813        if self.context.student.transcript_enabled \
814            and not final_slip:
815            return self.view.url(self.view.context, self.target)
816        return False
817
818
819class SignTranscriptActionButton(ManageActionButton):
820    grok.order(2)
821    grok.context(IStudentStudyCourse)
822    grok.view(StudyCourseTranscriptPage)
823    grok.require('waeup.signTranscript')
824    text = _('Sign transcript electronically')
825    target = 'sign_transcript'
826    icon = 'actionicon_transcript.png'
827
828    @property
829    def target_url(self):
830        if self.context.student.state != TRANSVAL:
831            return ''
832        return self.view.url(self.view.context, self.target)
833
834    @property
835    def onclick(self):
836        return "return window.confirm(%s);" % _(
837            "'Signing a transcript electronically cannot be revoked. "
838            "The electronic signature replaces your handwritten signature.\\n\\n"
839            "You really want to sign the transcript?'")
840
841
842class StudentsTab(PrimaryNavTab):
843    """Students tab in primary navigation.
844    """
845    grok.context(IKofaObject)
846    grok.order(4)
847    grok.require('waeup.viewStudentsContainer')
848    grok.name('studentstab')
849
850    pnav = 4
851    tab_title = _(u'Students')
852
853    @property
854    def link_target(self):
855        return self.view.application_url('students')
856
857
858class PrimaryStudentNavManager(grok.ViewletManager):
859    """Viewlet manager for the primary navigation tab.
860    """
861    grok.name('primary_nav_student')
862
863
864class PrimaryStudentNavTab(grok.Viewlet):
865    """Base for primary student nav tabs.
866    """
867    grok.baseclass()
868    grok.context(IKofaObject)
869    grok.viewletmanager(PrimaryStudentNavManager)
870    template = default_primary_nav_template
871    grok.order(1)
872    grok.require('waeup.Authenticated')
873    pnav = 0
874    tab_title = u'Some Text'
875
876    @property
877    def link_target(self):
878        return self.view.application_url()
879
880    @property
881    def active(self):
882        view_pnav = getattr(self.view, 'pnav', 0)
883        if view_pnav == self.pnav:
884            return 'active'
885        return ''
886
887
888class MyStudentDataTab(PrimaryStudentNavTab):
889    """MyData dropdown tab in primary navigation.
890    """
891    grok.order(3)
892    grok.require('waeup.viewMyStudentDataTab')
893    grok.template('mydatadropdowntabs')
894    grok.name('mystudentdatatab')
895    pnav = 4
896    tab_title = _(u'My Data')
897
898    @property
899    def active(self):
900        view_pnav = getattr(self.view, 'pnav', 0)
901        if view_pnav == self.pnav:
902            return 'active dropdown'
903        return 'dropdown'
904
905    @property
906    def targets(self):
907        student = grok.getSite()['students'][self.request.principal.id]
908        student_url = self.view.url(student)
909        app_slip = getUtility(IExtFileStore).getFileByContext(
910            student, 'application_slip')
911        targets = []
912        if student.getParentsPassword():
913            targets += [
914                {'url': student_url, 'title': 'Base Data'},
915                {'url': student_url + '/studycourse', 'title': _('Study Course')},
916                {'url': student_url + '/payments', 'title': _('Payments')},
917                ]
918            return targets
919        if app_slip:
920            targets = [{'url': student_url + '/application_slip',
921                        'title': _('Application Slip')}, ]
922        targets += [
923            {'url': student_url, 'title': 'Base Data'},
924            {'url': student_url + '/view_clearance',
925             'title': _('Clearance Data')},
926            {'url': student_url + '/view_personal',
927             'title': _('Personal Data')},
928            {'url': student_url + '/studycourse', 'title': _('Study Course')},
929            {'url': student_url + '/payments', 'title': _('Payments')},
930            {'url': student_url + '/accommodation',
931             'title': _('Accommodation Data')},
932            {'url': student_url + '/history', 'title': _('History')},
933            ]
934        return targets
Note: See TracBrowser for help on using the repository browser.