1 | ## $Id: browser.py 15977 2020-02-03 14:54:07Z 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 | import os |
---|
20 | from zope.i18n import translate |
---|
21 | from zope.component import getUtility |
---|
22 | from zope.security import checkPermission |
---|
23 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
24 | from waeup.kofa.interfaces import ADMITTED, VALIDATED, IKofaUtils |
---|
25 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
26 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
27 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
28 | from waeup.kofa.students.browser import ( |
---|
29 | StartClearancePage, |
---|
30 | ExportPDFAdmissionSlip, StudyLevelDisplayFormPage, |
---|
31 | PaymentsManageFormPage, |
---|
32 | OnlinePaymentApproveView, |
---|
33 | StudentBasePDFFormPage) |
---|
34 | from kofacustom.nigeria.students.browser import ( |
---|
35 | NigeriaOnlinePaymentDisplayFormPage, |
---|
36 | NigeriaOnlinePaymentAddFormPage, |
---|
37 | NigeriaExportPDFPaymentSlip, |
---|
38 | NigeriaStudentClearanceEditFormPage, |
---|
39 | NigeriaExportPDFClearanceSlip, |
---|
40 | NigeriaExportPDFCourseRegistrationSlip, |
---|
41 | NigeriaBedTicketAddPage, |
---|
42 | ) |
---|
43 | |
---|
44 | from waeup.fceokene.students.interfaces import ( |
---|
45 | ICustomStudentOnlinePayment, ICustomUGStudentClearance, |
---|
46 | ICustomStudentStudyLevel) |
---|
47 | |
---|
48 | class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip): |
---|
49 | """Deliver a PDF Admission slip. |
---|
50 | """ |
---|
51 | |
---|
52 | @property |
---|
53 | def label(self): |
---|
54 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
55 | line0 = '' |
---|
56 | if self.context.student.current_mode.startswith('ug'): |
---|
57 | line0 = 'IN AFFILIATION WITH UNIVERSITY OF IBADAN\n' |
---|
58 | line1 = translate(_('Admission Letter of'), |
---|
59 | 'waeup.kofa', target_language=portal_language) \ |
---|
60 | + ' %s' % self.context.display_fullname |
---|
61 | return '%s%s' % (line0, line1) |
---|
62 | |
---|
63 | @property |
---|
64 | def _post_text(self): |
---|
65 | return """You should note the following as conditions for admission: |
---|
66 | |
---|
67 | 1. At the point of registration, you will be required to present the originals of your certificate(s), |
---|
68 | Jamb Original Result, a Birth Certificate or a Declaration of Age Certificate and Evidence of |
---|
69 | Citizenship Certificate. |
---|
70 | |
---|
71 | 2. Please note that the name by which you are hereby admitted and by which you will be registered |
---|
72 | is the one which will appear on any certificate that the Federal College of Education, Okene may |
---|
73 | issue to you on successful completion of your programme except there was a change of name by |
---|
74 | sworn affidavit or marriage certificate in addition to newspaper publication. |
---|
75 | |
---|
76 | 3. You are hereby informed that all fees must be paid at the beginning of the academic session. |
---|
77 | The current school fees can be obtained from the College website. |
---|
78 | |
---|
79 | 4. You will present at the time of registration the Medical Certificate of Fitness from the Federal |
---|
80 | College of Education, Okene Medical Centre. |
---|
81 | |
---|
82 | 5. Please, note that due to shortage of accommodations, students shall be given accommodations |
---|
83 | on first come, first serve basis. |
---|
84 | |
---|
85 | 6. The offer is not transferable to another session. |
---|
86 | |
---|
87 | 7. You will sign a declaration of good conduct except by deferment on your arrival at the College. |
---|
88 | |
---|
89 | Accept my congratulations. |
---|
90 | |
---|
91 | Yours faithfully |
---|
92 | |
---|
93 | M. S. Adoke |
---|
94 | Deputy Registrar (Admissions) |
---|
95 | For: Registrar |
---|
96 | """ |
---|
97 | |
---|
98 | def render(self): |
---|
99 | students_utils = getUtility(IStudentsUtils) |
---|
100 | letterhead_path = os.path.join( |
---|
101 | os.path.dirname(__file__), 'static', 'letterhead_admission.jpg') |
---|
102 | topMargin=1.6 |
---|
103 | if self.context.student.current_mode.startswith('ug'): |
---|
104 | letterhead_path = None |
---|
105 | topMargin=1.5 |
---|
106 | return students_utils.renderPDFAdmissionLetter(self, |
---|
107 | self.context.student, omit_fields=self.omit_fields, |
---|
108 | letterhead_path=letterhead_path, |
---|
109 | topMargin=topMargin, |
---|
110 | post_text=self._post_text) |
---|
111 | |
---|
112 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
113 | """ Page to view an online payment ticket |
---|
114 | """ |
---|
115 | grok.context(ICustomStudentOnlinePayment) |
---|
116 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
117 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', 'p_combi') |
---|
118 | form_fields[ |
---|
119 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
120 | form_fields[ |
---|
121 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
122 | |
---|
123 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
124 | """ Page to add an online payment ticket |
---|
125 | """ |
---|
126 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
127 | 'p_combi') |
---|
128 | |
---|
129 | class OnlinePaymentApproveView(OnlinePaymentApproveView): |
---|
130 | grok.require('waeup.manageStudent') |
---|
131 | |
---|
132 | class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip): |
---|
133 | """Deliver a PDF slip of the context. |
---|
134 | """ |
---|
135 | grok.context(ICustomStudentOnlinePayment) |
---|
136 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
137 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', 'p_combi') |
---|
138 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
139 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
140 | |
---|
141 | class CustomStartClearancePage(StartClearancePage): |
---|
142 | |
---|
143 | @property |
---|
144 | def with_ac(self): |
---|
145 | mode = getattr(self.context, 'current_mode', None) |
---|
146 | if mode and mode.startswith('ug'): |
---|
147 | return True |
---|
148 | return False |
---|
149 | |
---|
150 | class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip): |
---|
151 | """Deliver a PDF slip of the context. |
---|
152 | """ |
---|
153 | |
---|
154 | @property |
---|
155 | def form_fields(self): |
---|
156 | if self.context.is_postgrad: |
---|
157 | form_fields = grok.AutoFields( |
---|
158 | ICustomPGStudentClearance).omit('clearance_locked') |
---|
159 | else: |
---|
160 | form_fields = grok.AutoFields( |
---|
161 | ICustomUGStudentClearance).omit('clearance_locked') |
---|
162 | if not getattr(self.context, 'officer_comment'): |
---|
163 | form_fields = form_fields.omit('officer_comment') |
---|
164 | return form_fields |
---|
165 | |
---|
166 | @property |
---|
167 | def label(self): |
---|
168 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
169 | |
---|
170 | line0 = '' |
---|
171 | if self.context.student.current_mode.startswith('ug'): |
---|
172 | line0 = 'Directorate of Undergraduate Programme\n' |
---|
173 | line1 = translate(_('Clearance Slip of'), |
---|
174 | 'waeup.kofa', target_language=portal_language) \ |
---|
175 | + ' %s' % self.context.display_fullname |
---|
176 | return '%s%s' % (line0, line1) |
---|
177 | |
---|
178 | |
---|
179 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
180 | """ View to edit student clearance data by student |
---|
181 | """ |
---|
182 | |
---|
183 | def dataNotComplete(self): |
---|
184 | return False |
---|
185 | |
---|
186 | class CustomBedTicketAddPage(NigeriaBedTicketAddPage): |
---|
187 | """ Page to add an online payment ticket |
---|
188 | """ |
---|
189 | buttonname = _('Create bed ticket') |
---|
190 | notice = '' |
---|
191 | with_ac = False |
---|
192 | |
---|
193 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
194 | """ Page to display student study levels |
---|
195 | """ |
---|
196 | grok.context(ICustomStudentStudyLevel) |
---|
197 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit('level') |
---|
198 | form_fields[ |
---|
199 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
200 | |
---|
201 | class CustomExportPDFCourseRegistrationSlip( |
---|
202 | NigeriaExportPDFCourseRegistrationSlip): |
---|
203 | """Deliver a PDF slip of the context. |
---|
204 | """ |
---|
205 | grok.context(ICustomStudentStudyLevel) |
---|
206 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit('level') |
---|
207 | |
---|
208 | class ExportPDFExaminationClearanceSlip(CustomExportPDFCourseRegistrationSlip): |
---|
209 | """Deliver a PDF slip of the context. |
---|
210 | """ |
---|
211 | |
---|
212 | grok.name('examination_clearance_slip.pdf') |
---|
213 | |
---|
214 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
215 | 'gpa', 'transcript_remark', 'total_credits', 'level_verdict') |
---|
216 | |
---|
217 | @property |
---|
218 | def label(self): |
---|
219 | return 'Year %s Examination Clearance' % self.context.level_session |
---|
220 | |
---|
221 | def update(self): |
---|
222 | if self.context.student.state != VALIDATED \ |
---|
223 | or self.context.student.current_level != self.context.level: |
---|
224 | self.flash(_('Forbidden'), type="warning") |
---|
225 | self.redirect(self.url(self.context)) |
---|
226 | |
---|
227 | def render(self): |
---|
228 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
229 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
230 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
231 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
232 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
233 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
234 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
235 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
236 | self.request, self.omit_fields) |
---|
237 | students_utils = getUtility(IStudentsUtils) |
---|
238 | |
---|
239 | tabledata = [] |
---|
240 | tableheader = [] |
---|
241 | for i in range(1,7): |
---|
242 | tabledata.append(sorted( |
---|
243 | [value for value in self.context.values() if value.semester == i], |
---|
244 | key=lambda value: str(value.semester) + value.code)) |
---|
245 | tableheader.append([(Code,'code', 2.5), |
---|
246 | (Title,'title', 5), |
---|
247 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
248 | (Cred, 'credits', 1.5), |
---|
249 | ]) |
---|
250 | return students_utils.renderPDF( |
---|
251 | self, 'examination_clearance_slip.pdf', |
---|
252 | self.context.student, studentview, |
---|
253 | tableheader=tableheader, |
---|
254 | tabledata=tabledata, |
---|
255 | omit_fields=self.omit_fields |
---|
256 | ) |
---|
257 | |
---|
258 | |
---|
259 | class CustomPaymentsManageFormPage(PaymentsManageFormPage): |
---|
260 | """ Page to manage the student payments. This manage form page is for |
---|
261 | both students and students officers. FCEOkene does not allow students |
---|
262 | to remove any payment ticket. |
---|
263 | """ |
---|
264 | @property |
---|
265 | def manage_payments_allowed(self): |
---|
266 | return checkPermission('waeup.manageStudent', self.context) |
---|