1 | ## $Id: browser.py 10025 2013-03-13 12:12:10Z 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 | StudyLevelEditFormPage, StudyLevelDisplayFormPage, |
---|
29 | StudentBasePDFFormPage, ExportPDFCourseRegistrationSlipPage, |
---|
30 | CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage, |
---|
31 | msave, emit_lock_message) |
---|
32 | from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket |
---|
33 | from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS |
---|
34 | from kofacustom.nigeria.students.browser import ( |
---|
35 | NigeriaOnlinePaymentDisplayFormPage, |
---|
36 | NigeriaStudentBaseManageFormPage, |
---|
37 | NigeriaStudentClearanceEditFormPage, |
---|
38 | NigeriaOnlinePaymentAddFormPage, |
---|
39 | NigeriaExportPDFPaymentSlipPage, |
---|
40 | NigeriaExportPDFClearanceSlipPage, |
---|
41 | ) |
---|
42 | |
---|
43 | from waeup.uniben.students.interfaces import ( |
---|
44 | ICustomStudentOnlinePayment, ICustomStudentStudyCourse, |
---|
45 | ICustomStudentStudyLevel) |
---|
46 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
47 | |
---|
48 | class CustomStudentTriggerTransitionFormPage(StudentTriggerTransitionFormPage): |
---|
49 | """ View to manage student base data |
---|
50 | """ |
---|
51 | |
---|
52 | def getTransitions(self): |
---|
53 | """Return a list of dicts of allowed transition ids and titles. |
---|
54 | |
---|
55 | Each list entry provides keys ``name`` and ``title`` for |
---|
56 | internal name and (human readable) title of a single |
---|
57 | transition. |
---|
58 | """ |
---|
59 | wf_info = IWorkflowInfo(self.context) |
---|
60 | allowed_transitions = [t for t in 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', 'p_item') |
---|
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', 'p_item') |
---|
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 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
200 | 'level_verdict', 'gpa') |
---|
201 | |
---|
202 | def render(self): |
---|
203 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
204 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
205 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
206 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
207 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
208 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
209 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
210 | self.request, self.omit_fields) |
---|
211 | students_utils = getUtility(IStudentsUtils) |
---|
212 | tabledata_1 = sorted( |
---|
213 | [value for value in self.context.values() if value.semester == 1], |
---|
214 | key=lambda value: str(value.semester) + value.code) |
---|
215 | tabledata_2 = sorted( |
---|
216 | [value for value in self.context.values() if value.semester == 2], |
---|
217 | key=lambda value: str(value.semester) + value.code) |
---|
218 | tabledata_3 = sorted( |
---|
219 | [value for value in self.context.values() if value.semester == 3], |
---|
220 | key=lambda value: str(value.semester) + value.code) |
---|
221 | tableheader = [(Code,'code', 2.5), |
---|
222 | (Title,'title', 5), |
---|
223 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
224 | (Cred, 'credits', 1.5), |
---|
225 | ] |
---|
226 | return students_utils.renderPDF( |
---|
227 | self, 'course_registration_slip.pdf', |
---|
228 | self.context.student, studentview, |
---|
229 | tableheader_1=tableheader, |
---|
230 | tabledata_1=tabledata_1, |
---|
231 | tableheader_2=tableheader, |
---|
232 | tabledata_2=tabledata_2, |
---|
233 | tableheader_3=tableheader, |
---|
234 | tabledata_3=tabledata_3 |
---|
235 | ) |
---|
236 | |
---|
237 | class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage): |
---|
238 | """Deliver a PDF slip of the context. |
---|
239 | """ |
---|
240 | |
---|
241 | grok.name('course_result_slip.pdf') |
---|
242 | |
---|
243 | @property |
---|
244 | def label(self): |
---|
245 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
246 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
247 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
248 | target_language=lang) |
---|
249 | return translate(_('Course Result Slip'), |
---|
250 | 'waeup.uniben', target_language=portal_language) \ |
---|
251 | + ' %s' % level_title |
---|
252 | |
---|
253 | def render(self): |
---|
254 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
255 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
256 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
257 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
258 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
259 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
260 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
261 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
262 | self.request, self.omit_fields) |
---|
263 | students_utils = getUtility(IStudentsUtils) |
---|
264 | tabledata_1 = sorted( |
---|
265 | [value for value in self.context.values() if value.semester == 1], |
---|
266 | key=lambda value: str(value.semester) + value.code) |
---|
267 | tabledata_2 = sorted( |
---|
268 | [value for value in self.context.values() if value.semester == 2], |
---|
269 | key=lambda value: str(value.semester) + value.code) |
---|
270 | tabledata_3 = sorted( |
---|
271 | [value for value in self.context.values() if value.semester == 3], |
---|
272 | key=lambda value: str(value.semester) + value.code) |
---|
273 | tableheader = [(Code,'code', 2.5), |
---|
274 | (Title,'title', 5), |
---|
275 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
276 | (Cred, 'credits', 1.5), |
---|
277 | (Grade, 'grade', 1.5), |
---|
278 | ] |
---|
279 | return students_utils.renderPDF( |
---|
280 | self, 'course_registration_slip.pdf', |
---|
281 | self.context.student, studentview, |
---|
282 | tableheader_1=tableheader, |
---|
283 | tabledata_1=tabledata_1, |
---|
284 | tableheader_2=tableheader, |
---|
285 | tabledata_2=tabledata_2, |
---|
286 | tableheader_3=tableheader, |
---|
287 | tabledata_3=tabledata_3 |
---|
288 | ) |
---|
289 | |
---|
290 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
291 | """ Page to display course tickets |
---|
292 | """ |
---|
293 | form_fields = grok.AutoFields(ICourseTicket).omit('score') |
---|