1 | ## $Id: browser.py 9848 2013-01-09 09:33:01Z 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 zope.component import getUtility |
---|
22 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
23 | from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils |
---|
24 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
25 | from waeup.kofa.browser.layout import KofaEditFormPage |
---|
26 | from waeup.kofa.browser.layout import action, jsaction |
---|
27 | from waeup.kofa.students.browser import ( |
---|
28 | StudentClearPage, StudentRejectClearancePage, |
---|
29 | StudyLevelEditFormPage, StudyLevelDisplayFormPage, |
---|
30 | StudentBasePDFFormPage, ExportPDFCourseRegistrationSlipPage, |
---|
31 | CourseTicketDisplayFormPage, |
---|
32 | msave, emit_lock_message) |
---|
33 | from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket |
---|
34 | from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS |
---|
35 | from kofacustom.nigeria.students.browser import ( |
---|
36 | NigeriaOnlinePaymentDisplayFormPage, |
---|
37 | NigeriaStudentBaseManageFormPage, |
---|
38 | NigeriaStudentClearanceEditFormPage, |
---|
39 | NigeriaOnlinePaymentAddFormPage, |
---|
40 | NigeriaExportPDFPaymentSlipPage, |
---|
41 | NigeriaExportPDFClearanceSlipPage, |
---|
42 | ) |
---|
43 | |
---|
44 | from waeup.uniben.students.interfaces import ( |
---|
45 | ICustomStudentOnlinePayment, ICustomStudentStudyCourse) |
---|
46 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
47 | |
---|
48 | class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage): |
---|
49 | """ View to manage student base data |
---|
50 | """ |
---|
51 | #grok.context(ICustomStudent) |
---|
52 | |
---|
53 | def getTransitions(self): |
---|
54 | """Return a list of dicts of allowed transition ids and titles. |
---|
55 | |
---|
56 | Each list entry provides keys ``name`` and ``title`` for |
---|
57 | internal name and (human readable) title of a single |
---|
58 | transition. |
---|
59 | """ |
---|
60 | allowed_transitions = [t for t in self.wf_info.getManualTransitions() |
---|
61 | if not t[0].startswith('pay')] |
---|
62 | if self.context.is_postgrad and not self.context.is_special_postgrad: |
---|
63 | allowed_transitions = [t for t in allowed_transitions |
---|
64 | if not t[0] in FORBIDDEN_POSTGRAD_TRANS] |
---|
65 | return [dict(name='', title=_('No transition'))] +[ |
---|
66 | dict(name=x, title=y) for x, y in allowed_transitions] |
---|
67 | |
---|
68 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
69 | """ Page to view an online payment ticket |
---|
70 | """ |
---|
71 | grok.context(ICustomStudentOnlinePayment) |
---|
72 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
73 | 'provider_amt', 'gateway_amt', 'thirdparty_amt') |
---|
74 | form_fields[ |
---|
75 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
76 | form_fields[ |
---|
77 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
78 | |
---|
79 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
80 | """ View to edit student clearance data by student |
---|
81 | """ |
---|
82 | |
---|
83 | def dataNotComplete(self): |
---|
84 | store = getUtility(IExtFileStore) |
---|
85 | if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'): |
---|
86 | return _('No birth certificate uploaded.') |
---|
87 | if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): |
---|
88 | return _('No guarantor/referee letter uploaded.') |
---|
89 | if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): |
---|
90 | return _('No acceptance letter uploaded.') |
---|
91 | if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): |
---|
92 | return _('No first sitting result uploaded.') |
---|
93 | #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'): |
---|
94 | # return _('No second sitting result uploaded.') |
---|
95 | if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'): |
---|
96 | return _('No affidavit of non-membership of secret cults uploaded.') |
---|
97 | return False |
---|
98 | |
---|
99 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
100 | """ Page to add an online payment ticket |
---|
101 | """ |
---|
102 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
103 | 'p_category') |
---|
104 | |
---|
105 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
106 | """Deliver a PDF slip of the context. |
---|
107 | """ |
---|
108 | grok.context(ICustomStudentOnlinePayment) |
---|
109 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
110 | 'provider_amt', 'gateway_amt', 'thirdparty_amt') |
---|
111 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
112 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
113 | |
---|
114 | |
---|
115 | class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage): |
---|
116 | """Deliver a PDF slip of the context. |
---|
117 | """ |
---|
118 | |
---|
119 | def render(self): |
---|
120 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
121 | self.request, self.omit_fields) |
---|
122 | students_utils = getUtility(IStudentsUtils) |
---|
123 | return students_utils.renderPDF( |
---|
124 | self, 'clearance_slip.pdf', |
---|
125 | self.context.student, studentview, signatures=self._signatures(), |
---|
126 | sigs_in_footer=self._sigsInFooter(), show_scans=False) |
---|
127 | |
---|
128 | class StudyCourseCOEditFormPage(KofaEditFormPage): |
---|
129 | """ Page to edit the student study course data by clearance officers. |
---|
130 | |
---|
131 | This form page is available only in Uniben. |
---|
132 | """ |
---|
133 | grok.context(ICustomStudentStudyCourse) |
---|
134 | grok.name('edit_level') |
---|
135 | grok.require('waeup.clearStudent') |
---|
136 | label = _('Edit current level') |
---|
137 | pnav = 4 |
---|
138 | form_fields = grok.AutoFields( |
---|
139 | ICustomStudentStudyCourse).select('current_level') |
---|
140 | |
---|
141 | def update(self): |
---|
142 | if not (self.context.is_current and |
---|
143 | self.context.student.state == REQUESTED): |
---|
144 | emit_lock_message(self) |
---|
145 | return |
---|
146 | super(StudyCourseCOEditFormPage, self).update() |
---|
147 | return |
---|
148 | |
---|
149 | @action(_('Save'), style='primary') |
---|
150 | def save(self, **data): |
---|
151 | try: |
---|
152 | msave(self, **data) |
---|
153 | except ConstraintNotSatisfied: |
---|
154 | # The selected level might not exist in certificate |
---|
155 | self.flash(_('Current level not available for certificate.')) |
---|
156 | return |
---|
157 | #notify(grok.ObjectModifiedEvent(self.context.__parent__)) |
---|
158 | return |
---|
159 | |
---|
160 | class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): |
---|
161 | """ Page to edit the student study level data by students. |
---|
162 | |
---|
163 | """ |
---|
164 | grok.template('studyleveleditpage') |
---|
165 | |
---|
166 | def _registerCourses(self, **data): |
---|
167 | """ This customized version does allow 'special postgraduate' |
---|
168 | students to register their courses. |
---|
169 | """ |
---|
170 | if self.context.student.is_postgrad and \ |
---|
171 | not self.context.student.is_special_postgrad: |
---|
172 | self.flash(_( |
---|
173 | "You are a postgraduate student, " |
---|
174 | "your course list can't bee registered.")) |
---|
175 | self.redirect(self.url(self.context)) |
---|
176 | return |
---|
177 | students_utils = getUtility(IStudentsUtils) |
---|
178 | max_credits = students_utils.maxCredits(self.context) |
---|
179 | if self.context.total_credits > max_credits: |
---|
180 | self.flash(_('Maximum credits of ${a} exceeded.', |
---|
181 | mapping = {'a':max_credits})) |
---|
182 | return |
---|
183 | IWorkflowInfo(self.context.student).fireTransition( |
---|
184 | 'register_courses') |
---|
185 | self.flash(_('Course list has been registered.')) |
---|
186 | self.redirect(self.url(self.context)) |
---|
187 | return |
---|
188 | |
---|
189 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
190 | """ Page to display student study levels |
---|
191 | """ |
---|
192 | grok.template('studylevelpage') |
---|
193 | |
---|
194 | class CustomExportPDFCourseRegistrationSlipPage( |
---|
195 | ExportPDFCourseRegistrationSlipPage): |
---|
196 | """Deliver a PDF slip of the context. |
---|
197 | """ |
---|
198 | |
---|
199 | def render(self): |
---|
200 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
201 | Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language) |
---|
202 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
203 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
204 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
205 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
206 | Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language) |
---|
207 | Mand = translate('Requ.', 'waeup.kofa', target_language=portal_language) |
---|
208 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
209 | self.request, self.omit_fields) |
---|
210 | students_utils = getUtility(IStudentsUtils) |
---|
211 | tabledata = sorted(self.context.values(), |
---|
212 | key=lambda value: str(value.semester) + value.code) |
---|
213 | return students_utils.renderPDF( |
---|
214 | self, 'course_registration_slip.pdf', |
---|
215 | self.context.student, studentview, |
---|
216 | tableheader=[(Sem,'semester', 1.5),(Code,'code', 2.5), |
---|
217 | (Title,'title', 5), |
---|
218 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
219 | (Cred, 'credits', 1.5), |
---|
220 | (Mand, 'mandatory', 1.5), |
---|
221 | ], |
---|
222 | tabledata=tabledata) |
---|
223 | |
---|
224 | class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage): |
---|
225 | """Deliver a PDF slip of the context. |
---|
226 | """ |
---|
227 | |
---|
228 | grok.name('course_result_slip.pdf') |
---|
229 | |
---|
230 | @property |
---|
231 | def label(self): |
---|
232 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
233 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
234 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
235 | target_language=lang) |
---|
236 | return translate(_('Course Result Slip'), |
---|
237 | 'waeup.uniben', target_language=portal_language) \ |
---|
238 | + ' %s' % level_title |
---|
239 | |
---|
240 | def render(self): |
---|
241 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
242 | Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language) |
---|
243 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
244 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
245 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
246 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
247 | Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language) |
---|
248 | Mand = translate('Requ.', 'waeup.kofa', target_language=portal_language) |
---|
249 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
250 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
251 | self.request, self.omit_fields) |
---|
252 | students_utils = getUtility(IStudentsUtils) |
---|
253 | tabledata = sorted(self.context.values(), |
---|
254 | key=lambda value: str(value.semester) + value.code) |
---|
255 | return students_utils.renderPDF( |
---|
256 | self, 'course_registration_slip.pdf', |
---|
257 | self.context.student, studentview, |
---|
258 | tableheader=[(Sem,'semester', 1.5),(Code,'code', 2.5), |
---|
259 | (Title,'title', 5), |
---|
260 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
261 | (Cred, 'credits', 1.5), |
---|
262 | (Mand, 'mandatory', 1.5), |
---|
263 | (Grade, 'grade', 1.5), |
---|
264 | #('Auto', 'automatic', 1.5) |
---|
265 | ], |
---|
266 | tabledata=tabledata) |
---|
267 | |
---|
268 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
269 | """ Page to display course tickets |
---|
270 | """ |
---|
271 | form_fields = grok.AutoFields(ICourseTicket).omit('score') |
---|