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

Last change on this file since 17401 was 17400, checked in by Henrik Bettermann, 22 months ago

Show admission slip download button only if student is fresh.

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