1 | ## $Id: browser.py 9251 2012-09-28 06:22:59Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | import grok |
---|
19 | from zope.i18n import translate |
---|
20 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
21 | from waeup.kofa.interfaces import REQUESTED |
---|
22 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
23 | from waeup.kofa.browser.layout import KofaEditFormPage |
---|
24 | from waeup.kofa.browser.viewlets import ManageActionButton |
---|
25 | from waeup.kofa.browser.layout import action |
---|
26 | from waeup.kofa.students.browser import ( |
---|
27 | StudentClearPage, StudentRejectClearancePage, |
---|
28 | StudyCourseDisplayFormPage, msave, emit_lock_message) |
---|
29 | from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS |
---|
30 | from kofacustom.nigeria.students.browser import ( |
---|
31 | NigeriaOnlinePaymentDisplayFormPage, |
---|
32 | NigeriaStudentBaseManageFormPage, |
---|
33 | NigeriaOnlinePaymentAddFormPage, |
---|
34 | NigeriaExportPDFPaymentSlipPage) |
---|
35 | #from waeup.uniben.students.interfaces import ICustomStudent |
---|
36 | |
---|
37 | from waeup.uniben.students.interfaces import ( |
---|
38 | ICustomStudentOnlinePayment, ICustomStudentStudyCourse) |
---|
39 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
40 | |
---|
41 | class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage): |
---|
42 | """ View to manage student base data |
---|
43 | """ |
---|
44 | #grok.context(ICustomStudent) |
---|
45 | |
---|
46 | def getTransitions(self): |
---|
47 | """Return a list of dicts of allowed transition ids and titles. |
---|
48 | |
---|
49 | Each list entry provides keys ``name`` and ``title`` for |
---|
50 | internal name and (human readable) title of a single |
---|
51 | transition. |
---|
52 | """ |
---|
53 | allowed_transitions = [t for t in self.wf_info.getManualTransitions() |
---|
54 | if not t[0].startswith('pay')] |
---|
55 | if self.context.is_postgrad and not self.context.is_special_postgrad: |
---|
56 | allowed_transitions = [t for t in allowed_transitions |
---|
57 | if not t[0] in FORBIDDEN_POSTGRAD_TRANS] |
---|
58 | return [dict(name='', title=_('No transition'))] +[ |
---|
59 | dict(name=x, title=y) for x, y in allowed_transitions] |
---|
60 | |
---|
61 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
62 | """ Page to view an online payment ticket |
---|
63 | """ |
---|
64 | grok.context(ICustomStudentOnlinePayment) |
---|
65 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment) |
---|
66 | form_fields[ |
---|
67 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
68 | form_fields[ |
---|
69 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
70 | |
---|
71 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
72 | """ Page to add an online payment ticket |
---|
73 | """ |
---|
74 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
75 | 'p_category') |
---|
76 | |
---|
77 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
78 | """Deliver a PDF slip of the context. |
---|
79 | """ |
---|
80 | grok.context(ICustomStudentOnlinePayment) |
---|
81 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment) |
---|
82 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
83 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
84 | |
---|
85 | |
---|
86 | ## In case we need to deactivate clearance |
---|
87 | #class CustomStudentClearPage(StudentClearPage): |
---|
88 | # """ Clear student by clearance officer |
---|
89 | # """ |
---|
90 | # def update(self): |
---|
91 | # self.flash('Clearance temporarily disabled!') |
---|
92 | # self.redirect(self.url(self.context,'view_clearance')) |
---|
93 | # return |
---|
94 | |
---|
95 | #class CustomStudentRejectClearancePage(StudentRejectClearancePage): |
---|
96 | # """ Reject clearance by clearance officers |
---|
97 | # """ |
---|
98 | |
---|
99 | # def update(self): |
---|
100 | # self.flash('Clearance temporarily disabled!') |
---|
101 | # self.redirect(self.url(self.context,'view_clearance')) |
---|
102 | # return |
---|
103 | |
---|
104 | class StudyCourseEditActionButton(ManageActionButton): |
---|
105 | grok.order(1) |
---|
106 | grok.context(ICustomStudentStudyCourse) |
---|
107 | grok.view(StudyCourseDisplayFormPage) |
---|
108 | grok.require('waeup.clearStudent') |
---|
109 | text = _('Edit level') |
---|
110 | target = 'edit_level' |
---|
111 | |
---|
112 | @property |
---|
113 | def target_url(self): |
---|
114 | if self.context.is_current and self.context.student.state == REQUESTED: |
---|
115 | return self.view.url(self.view.context, self.target) |
---|
116 | return False |
---|
117 | |
---|
118 | class StudyCourseCOEditFormPage(KofaEditFormPage): |
---|
119 | """ Page to edit the student study course data by clearance officers |
---|
120 | |
---|
121 | This form page is available only in Uniben. |
---|
122 | """ |
---|
123 | grok.context(ICustomStudentStudyCourse) |
---|
124 | grok.name('edit_level') |
---|
125 | grok.require('waeup.clearStudent') |
---|
126 | label = _('Edit current level') |
---|
127 | pnav = 4 |
---|
128 | form_fields = grok.AutoFields( |
---|
129 | ICustomStudentStudyCourse).select('current_level') |
---|
130 | |
---|
131 | def update(self): |
---|
132 | if not (self.context.is_current and |
---|
133 | self.context.student.state == REQUESTED): |
---|
134 | emit_lock_message(self) |
---|
135 | return |
---|
136 | super(StudyCourseCOEditFormPage, self).update() |
---|
137 | return |
---|
138 | |
---|
139 | @action(_('Save'), style='primary') |
---|
140 | def save(self, **data): |
---|
141 | try: |
---|
142 | msave(self, **data) |
---|
143 | except ConstraintNotSatisfied: |
---|
144 | # The selected level might not exist in certificate |
---|
145 | self.flash(_('Current level not available for certificate.')) |
---|
146 | return |
---|
147 | #notify(grok.ObjectModifiedEvent(self.context.__parent__)) |
---|
148 | return |
---|