1 | ## $Id: browser.py 12876 2015-04-23 21:12:47Z 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.component import getUtility |
---|
21 | from waeup.kofa.browser.layout import UtilityView |
---|
22 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
23 | from waeup.kofa.interfaces import IKofaUtils |
---|
24 | from waeup.kofa.students.interfaces import IStudentsUtils, IStudent |
---|
25 | from waeup.kofa.students.workflow import PAID |
---|
26 | from waeup.kofa.students.browser import ( |
---|
27 | StartClearancePage, |
---|
28 | StudentBasePDFFormPage, |
---|
29 | CourseTicketAddFormPage, |
---|
30 | StudyLevelDisplayFormPage, |
---|
31 | ExportPDFTranscriptPage, |
---|
32 | ExportPDFAdmissionSlipPage, |
---|
33 | ) |
---|
34 | from kofacustom.nigeria.students.browser import ( |
---|
35 | NigeriaOnlinePaymentDisplayFormPage, |
---|
36 | NigeriaOnlinePaymentAddFormPage, |
---|
37 | NigeriaExportPDFPaymentSlipPage, |
---|
38 | NigeriaExportPDFCourseRegistrationSlipPage, |
---|
39 | NigeriaExportPDFClearanceSlipPage, |
---|
40 | ) |
---|
41 | from waeup.aaue.students.interfaces import ( |
---|
42 | ICustomStudentOnlinePayment, |
---|
43 | ICustomStudentStudyLevel, |
---|
44 | ICustomStudent) |
---|
45 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
46 | |
---|
47 | class CustomStartClearancePage(StartClearancePage): |
---|
48 | with_ac = False |
---|
49 | |
---|
50 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
51 | """ Page to view an online payment ticket |
---|
52 | """ |
---|
53 | grok.context(ICustomStudentOnlinePayment) |
---|
54 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
55 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
56 | form_fields[ |
---|
57 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
58 | form_fields[ |
---|
59 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
60 | |
---|
61 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
62 | """ Page to add an online payment ticket |
---|
63 | """ |
---|
64 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
65 | 'p_category') |
---|
66 | |
---|
67 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
68 | """Deliver a PDF slip of the context. |
---|
69 | """ |
---|
70 | grok.context(ICustomStudentOnlinePayment) |
---|
71 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
72 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
73 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
74 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
75 | |
---|
76 | @property |
---|
77 | def note(self): |
---|
78 | text = '' |
---|
79 | if self.context.p_category == 'schoolfee' and self.context.p_level == 100: |
---|
80 | text += '\n\n Amounts include Naira 250 eTranzact transaction ' |
---|
81 | text += 'charge and Naira 2000 cost of matriculation gown.' |
---|
82 | elif self.context.p_category in ('clearance', 'schoolfee'): |
---|
83 | text += '\n\n Amounts include Naira 250 eTranzact transaction charge.' |
---|
84 | return text |
---|
85 | |
---|
86 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
87 | """ Page to display student study levels |
---|
88 | """ |
---|
89 | grok.context(ICustomStudentStudyLevel) |
---|
90 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
91 | 'total_credits', 'gpa', 'level') |
---|
92 | form_fields[ |
---|
93 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
94 | |
---|
95 | class CustomExportPDFCourseRegistrationSlipPage( |
---|
96 | NigeriaExportPDFCourseRegistrationSlipPage): |
---|
97 | """Deliver a PDF slip of the context. |
---|
98 | """ |
---|
99 | grok.context(ICustomStudentStudyLevel) |
---|
100 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
101 | 'level_session', 'level_verdict', |
---|
102 | 'validated_by', 'validation_date', 'gpa', 'level') |
---|
103 | |
---|
104 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
105 | 'phone', 'adm_code', 'sex', 'email', 'date_of_birth', |
---|
106 | 'department', 'current_mode', 'current_level') |
---|
107 | |
---|
108 | @property |
---|
109 | def label(self): |
---|
110 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
111 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
112 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
113 | target_language=lang) |
---|
114 | line0 = '' |
---|
115 | if self.context.student.current_mode.endswith('_pt'): |
---|
116 | line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n' |
---|
117 | line1 = translate(_('Course Registration Slip'), |
---|
118 | 'waeup.kofa', target_language=portal_language) \ |
---|
119 | + ' %s' % level_title |
---|
120 | line2 = translate(_('Session'), |
---|
121 | 'waeup.kofa', target_language=portal_language) \ |
---|
122 | + ' %s' % self.context.getSessionString |
---|
123 | return '%s%s\n%s' % (line0, line1, line2) |
---|
124 | |
---|
125 | @property |
---|
126 | def title(self): |
---|
127 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
128 | return translate(_('Units Registered'), 'waeup.kofa', |
---|
129 | target_language=portal_language) |
---|
130 | |
---|
131 | def _signatures(self): |
---|
132 | return ( |
---|
133 | [('I have selected the course on the advise of my Head of ' |
---|
134 | 'Department. <br>', _('Student\'s Signature'), '<br>')], |
---|
135 | [('This student has satisfied the department\'s requirements. ' |
---|
136 | 'I recommend to approve the course registration. <br>', |
---|
137 | _('Head of Department\'s Signature'), '<br>')], |
---|
138 | [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')], |
---|
139 | [('', _('Director\'s Signature'))] |
---|
140 | ) |
---|
141 | |
---|
142 | def render(self): |
---|
143 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
144 | Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language) |
---|
145 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
146 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
147 | Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language) |
---|
148 | Score = translate('Score', 'waeup.kofa', target_language=portal_language) |
---|
149 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
150 | Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue', |
---|
151 | target_language=portal_language) |
---|
152 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
153 | self.request, self.omit_fields) |
---|
154 | students_utils = getUtility(IStudentsUtils) |
---|
155 | |
---|
156 | tabledata = [] |
---|
157 | tableheader = [] |
---|
158 | contenttitle = [] |
---|
159 | for i in range(1,7): |
---|
160 | tabledata.append(sorted( |
---|
161 | [value for value in self.context.values() if value.semester == i], |
---|
162 | key=lambda value: str(value.semester) + value.code)) |
---|
163 | tableheader.append([(Code,'code', 2.0), |
---|
164 | (Title,'title', 7), |
---|
165 | (Cred, 'credits', 1.5), |
---|
166 | (Score, 'score', 1.4), |
---|
167 | (Grade, 'grade', 1.4), |
---|
168 | (Signature, 'dummy', 3), |
---|
169 | ]) |
---|
170 | if len(self.label.split('\n')) == 3: |
---|
171 | topMargin = 1.9 |
---|
172 | elif len(self.label.split('\n')) == 2: |
---|
173 | topMargin = 1.7 |
---|
174 | else: |
---|
175 | topMargin = 1.5 |
---|
176 | return students_utils.renderPDF( |
---|
177 | self, 'course_registration_slip.pdf', |
---|
178 | self.context.student, studentview, |
---|
179 | tableheader=tableheader, |
---|
180 | tabledata=tabledata, |
---|
181 | signatures=self._signatures(), |
---|
182 | topMargin=topMargin, |
---|
183 | omit_fields=self.omit_fields |
---|
184 | ) |
---|
185 | |
---|
186 | class CustomExportPDFTranscriptPage(ExportPDFTranscriptPage): |
---|
187 | """Deliver a PDF slip of the context. |
---|
188 | """ |
---|
189 | |
---|
190 | def _sigsInFooter(self): |
---|
191 | return [] |
---|
192 | |
---|
193 | def _signatures(self): |
---|
194 | return ([( |
---|
195 | 'Akhimien Felicia O. (MANUPA) <br /> Principal Assistant Registrar <br /> ' |
---|
196 | 'Exams, Records and Data Processing Division <br /> For: Registrar')],) |
---|
197 | |
---|
198 | class CustomExportPDFAdmissionSlipPage(ExportPDFAdmissionSlipPage): |
---|
199 | """Deliver a PDF Admission slip. |
---|
200 | """ |
---|
201 | |
---|
202 | @property |
---|
203 | def label(self): |
---|
204 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
205 | return translate(_('e-Admission Slip \n'), |
---|
206 | 'waeup.kofa', target_language=portal_language) \ |
---|
207 | + ' %s' % self.context.display_fullname |
---|
208 | |
---|
209 | class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage): |
---|
210 | """Deliver a PDF slip of the context. |
---|
211 | """ |
---|
212 | |
---|
213 | @property |
---|
214 | def label(self): |
---|
215 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
216 | return translate(_('Clearance Slip\n'), |
---|
217 | 'waeup.kofa', target_language=portal_language) \ |
---|
218 | + ' %s' % self.context.display_fullname |
---|
219 | |
---|
220 | class StudentGetMatricNumberPage(UtilityView, grok.View): |
---|
221 | """ Construct and set the matriculation number. |
---|
222 | """ |
---|
223 | grok.context(IStudent) |
---|
224 | grok.name('get_matric_number') |
---|
225 | grok.require('waeup.viewStudent') |
---|
226 | |
---|
227 | def update(self): |
---|
228 | students_utils = getUtility(IStudentsUtils) |
---|
229 | msg, mnumber = students_utils.setMatricNumber(self.context) |
---|
230 | if msg: |
---|
231 | self.flash(msg, type="danger") |
---|
232 | else: |
---|
233 | self.flash(_('Matriculation number %s assigned.' % mnumber)) |
---|
234 | self.context.writeLogMessage(self, '%s assigned' % mnumber) |
---|
235 | self.redirect(self.url(self.context)) |
---|
236 | return |
---|
237 | |
---|
238 | def render(self): |
---|
239 | return |
---|
240 | |
---|
241 | class ExportPDFMatricNumberSlipPage(UtilityView, grok.View): |
---|
242 | """Deliver a PDF notification slip. |
---|
243 | """ |
---|
244 | grok.context(ICustomStudent) |
---|
245 | grok.name('matric_number_slip.pdf') |
---|
246 | grok.require('waeup.viewStudent') |
---|
247 | prefix = 'form' |
---|
248 | |
---|
249 | form_fields = grok.AutoFields(ICustomStudent).select( |
---|
250 | 'student_id', 'matric_number') |
---|
251 | omit_fields = ('date_of_birth', 'current_level') |
---|
252 | |
---|
253 | @property |
---|
254 | def label(self): |
---|
255 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
256 | return translate(_('Matriculation Number Slip\n'), |
---|
257 | 'waeup.kofa', target_language=portal_language) \ |
---|
258 | + ' %s' % self.context.display_fullname |
---|
259 | |
---|
260 | def render(self): |
---|
261 | if self.context.state not in (PAID,) or not self.context.is_fresh \ |
---|
262 | or not self.context.matric_number: |
---|
263 | self.flash('Not allowed.', type="danger") |
---|
264 | self.redirect(self.url(self.context)) |
---|
265 | return |
---|
266 | students_utils = getUtility(IStudentsUtils) |
---|
267 | pre_text = _('Congratulations! Your acceptance fee and school fees ' + |
---|
268 | 'payments have been received and your matriculation ' + |
---|
269 | 'number generated with details as follows.') |
---|
270 | return students_utils.renderPDFAdmissionLetter(self, |
---|
271 | self.context.student, omit_fields=self.omit_fields, |
---|
272 | pre_text=pre_text, post_text='') |
---|