1 | ## $Id: browser.py 10200 2013-05-22 15:59:20Z 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 CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
49 | """ Page to view an online payment ticket |
---|
50 | """ |
---|
51 | grok.context(ICustomStudentOnlinePayment) |
---|
52 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
53 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
54 | form_fields[ |
---|
55 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
56 | form_fields[ |
---|
57 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
58 | |
---|
59 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
60 | """ View to edit student clearance data by student |
---|
61 | """ |
---|
62 | |
---|
63 | def dataNotComplete(self): |
---|
64 | store = getUtility(IExtFileStore) |
---|
65 | if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'): |
---|
66 | return _('No birth certificate uploaded.') |
---|
67 | if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): |
---|
68 | return _('No guarantor/referee letter uploaded.') |
---|
69 | if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): |
---|
70 | return _('No acceptance letter uploaded.') |
---|
71 | if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): |
---|
72 | return _('No first sitting result uploaded.') |
---|
73 | #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'): |
---|
74 | # return _('No second sitting result uploaded.') |
---|
75 | if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'): |
---|
76 | return _('No affidavit of non-membership of secret cults uploaded.') |
---|
77 | return False |
---|
78 | |
---|
79 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
80 | """ Page to add an online payment ticket |
---|
81 | """ |
---|
82 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
83 | 'p_category') |
---|
84 | |
---|
85 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
86 | """Deliver a PDF slip of the context. |
---|
87 | """ |
---|
88 | grok.context(ICustomStudentOnlinePayment) |
---|
89 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
90 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
91 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
92 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
93 | |
---|
94 | |
---|
95 | class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage): |
---|
96 | """Deliver a PDF slip of the context. |
---|
97 | """ |
---|
98 | |
---|
99 | def render(self): |
---|
100 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
101 | self.request, self.omit_fields) |
---|
102 | students_utils = getUtility(IStudentsUtils) |
---|
103 | return students_utils.renderPDF( |
---|
104 | self, 'clearance_slip.pdf', |
---|
105 | self.context.student, studentview, signatures=self._signatures(), |
---|
106 | sigs_in_footer=self._sigsInFooter(), show_scans=False) |
---|
107 | |
---|
108 | class StudyCourseCOEditFormPage(KofaEditFormPage): |
---|
109 | """ Page to edit the student study course data by clearance officers. |
---|
110 | |
---|
111 | This form page is available only in Uniben. |
---|
112 | """ |
---|
113 | grok.context(ICustomStudentStudyCourse) |
---|
114 | grok.name('edit_level') |
---|
115 | grok.require('waeup.clearStudent') |
---|
116 | label = _('Edit current level') |
---|
117 | pnav = 4 |
---|
118 | form_fields = grok.AutoFields( |
---|
119 | ICustomStudentStudyCourse).select('current_level') |
---|
120 | |
---|
121 | def update(self): |
---|
122 | if not (self.context.is_current and |
---|
123 | self.context.student.state == REQUESTED): |
---|
124 | emit_lock_message(self) |
---|
125 | return |
---|
126 | super(StudyCourseCOEditFormPage, self).update() |
---|
127 | return |
---|
128 | |
---|
129 | @action(_('Save'), style='primary') |
---|
130 | def save(self, **data): |
---|
131 | try: |
---|
132 | msave(self, **data) |
---|
133 | except ConstraintNotSatisfied: |
---|
134 | # The selected level might not exist in certificate |
---|
135 | self.flash(_('Current level not available for certificate.')) |
---|
136 | return |
---|
137 | #notify(grok.ObjectModifiedEvent(self.context.__parent__)) |
---|
138 | return |
---|
139 | |
---|
140 | class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): |
---|
141 | """ Page to edit the student study level data by students. |
---|
142 | |
---|
143 | """ |
---|
144 | grok.template('studyleveleditpage') |
---|
145 | |
---|
146 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
147 | """ Page to display student study levels |
---|
148 | """ |
---|
149 | grok.template('studylevelpage') |
---|
150 | |
---|
151 | class CustomExportPDFCourseRegistrationSlipPage( |
---|
152 | ExportPDFCourseRegistrationSlipPage): |
---|
153 | """Deliver a PDF slip of the context. |
---|
154 | """ |
---|
155 | |
---|
156 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
157 | 'level_verdict', 'gpa') |
---|
158 | |
---|
159 | def render(self): |
---|
160 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
161 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
162 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
163 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
164 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
165 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
166 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
167 | self.request, self.omit_fields) |
---|
168 | students_utils = getUtility(IStudentsUtils) |
---|
169 | tabledata_1 = sorted( |
---|
170 | [value for value in self.context.values() if value.semester == 1], |
---|
171 | key=lambda value: str(value.semester) + value.code) |
---|
172 | tabledata_2 = sorted( |
---|
173 | [value for value in self.context.values() if value.semester == 2], |
---|
174 | key=lambda value: str(value.semester) + value.code) |
---|
175 | tabledata_3 = sorted( |
---|
176 | [value for value in self.context.values() if value.semester == 3], |
---|
177 | key=lambda value: str(value.semester) + value.code) |
---|
178 | tableheader = [(Code,'code', 2.5), |
---|
179 | (Title,'title', 5), |
---|
180 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
181 | (Cred, 'credits', 1.5), |
---|
182 | ] |
---|
183 | return students_utils.renderPDF( |
---|
184 | self, 'course_registration_slip.pdf', |
---|
185 | self.context.student, studentview, |
---|
186 | tableheader_1=tableheader, |
---|
187 | tabledata_1=tabledata_1, |
---|
188 | tableheader_2=tableheader, |
---|
189 | tabledata_2=tabledata_2, |
---|
190 | tableheader_3=tableheader, |
---|
191 | tabledata_3=tabledata_3 |
---|
192 | ) |
---|
193 | |
---|
194 | class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage): |
---|
195 | """Deliver a PDF slip of the context. |
---|
196 | """ |
---|
197 | |
---|
198 | grok.name('course_result_slip.pdf') |
---|
199 | |
---|
200 | @property |
---|
201 | def label(self): |
---|
202 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
203 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
204 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
205 | target_language=lang) |
---|
206 | return translate(_('Course Result Slip'), |
---|
207 | 'waeup.uniben', target_language=portal_language) \ |
---|
208 | + ' %s' % level_title |
---|
209 | |
---|
210 | def render(self): |
---|
211 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
212 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
213 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
214 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
215 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
216 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
217 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
218 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
219 | self.request, self.omit_fields) |
---|
220 | students_utils = getUtility(IStudentsUtils) |
---|
221 | tabledata_1 = sorted( |
---|
222 | [value for value in self.context.values() if value.semester == 1], |
---|
223 | key=lambda value: str(value.semester) + value.code) |
---|
224 | tabledata_2 = sorted( |
---|
225 | [value for value in self.context.values() if value.semester == 2], |
---|
226 | key=lambda value: str(value.semester) + value.code) |
---|
227 | tabledata_3 = sorted( |
---|
228 | [value for value in self.context.values() if value.semester == 3], |
---|
229 | key=lambda value: str(value.semester) + value.code) |
---|
230 | tableheader = [(Code,'code', 2.5), |
---|
231 | (Title,'title', 5), |
---|
232 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
233 | (Cred, 'credits', 1.5), |
---|
234 | (Grade, 'grade', 1.5), |
---|
235 | ] |
---|
236 | return students_utils.renderPDF( |
---|
237 | self, 'course_registration_slip.pdf', |
---|
238 | self.context.student, studentview, |
---|
239 | tableheader_1=tableheader, |
---|
240 | tabledata_1=tabledata_1, |
---|
241 | tableheader_2=tableheader, |
---|
242 | tabledata_2=tabledata_2, |
---|
243 | tableheader_3=tableheader, |
---|
244 | tabledata_3=tabledata_3 |
---|
245 | ) |
---|
246 | |
---|
247 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
248 | """ Page to display course tickets |
---|
249 | """ |
---|
250 | form_fields = grok.AutoFields(ICourseTicket).omit('score') |
---|