| 1 | ## $Id: browser.py 18249 2026-04-01 22:01:28Z 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 | NigeriaStudentClearanceDisplayFormPage, |
|---|
| 39 | NigeriaStudentClearanceEditFormPage, |
|---|
| 40 | NigeriaStudentClearanceManageFormPage, |
|---|
| 41 | NigeriaExportPDFClearanceSlip, |
|---|
| 42 | NigeriaExportPDFCourseRegistrationSlip, |
|---|
| 43 | NigeriaBedTicketAddPage, |
|---|
| 44 | NigeriaAccommodationManageFormPage, |
|---|
| 45 | NigeriaAccommodationDisplayFormPage, |
|---|
| 46 | ) |
|---|
| 47 | |
|---|
| 48 | from waeup.fceokene.students.interfaces import ( |
|---|
| 49 | ICustomStudentOnlinePayment, |
|---|
| 50 | ICustomUGStudentClearance, |
|---|
| 51 | ICustomPGStudentClearance, |
|---|
| 52 | ICustomStudentStudyLevel) |
|---|
| 53 | |
|---|
| 54 | class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip): |
|---|
| 55 | """Deliver a PDF Admission slip. |
|---|
| 56 | """ |
|---|
| 57 | |
|---|
| 58 | @property |
|---|
| 59 | def label(self): |
|---|
| 60 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 61 | line0 = '' |
|---|
| 62 | if self.context.student.current_mode.startswith('ug') and self.context.student.faccode != 'SUP': |
|---|
| 63 | line0 = 'IN AFFILIATION WITH UNIVERSITY OF IBADAN\n' |
|---|
| 64 | line1 = translate(_('Admission Letter of'), |
|---|
| 65 | 'waeup.kofa', target_language=portal_language) \ |
|---|
| 66 | + ' %s' % self.context.display_fullname |
|---|
| 67 | return '%s%s' % (line0, line1) |
|---|
| 68 | |
|---|
| 69 | @property |
|---|
| 70 | def _post_text(self): |
|---|
| 71 | return """You should note the following as conditions for admission: |
|---|
| 72 | |
|---|
| 73 | 1. At the point of registration, you will be required to present the originals of your |
|---|
| 74 | certificate(s), Jamb Original Result, a Birth Certificate or a Declaration of |
|---|
| 75 | Age Certificate and Evidence of Citizenship Certificate. |
|---|
| 76 | |
|---|
| 77 | 2. Please note that the name by which you are hereby admitted and by which you will |
|---|
| 78 | be registered is the one which will appear on any certificate that the |
|---|
| 79 | Federal College of Education, Okene may issue to you on successful completion of |
|---|
| 80 | your programme except there was a change of name by sworn affidavit or |
|---|
| 81 | marriage certificate in addition to newspaper publication. |
|---|
| 82 | |
|---|
| 83 | 3. You are hereby informed that all fees must be paid at the beginning of the |
|---|
| 84 | academic session. The current school fees can be obtained from the College website. |
|---|
| 85 | |
|---|
| 86 | 4. You will present at the time of registration the Medical Certificate of Fitness |
|---|
| 87 | from the Federal College of Education, Okene Medical Centre. |
|---|
| 88 | |
|---|
| 89 | 5. Students shall be given accommodations on first come, first serve basis. |
|---|
| 90 | |
|---|
| 91 | 6. The offer is not transferable to another session. |
|---|
| 92 | |
|---|
| 93 | 7. You will sign a declaration of good conduct except by deferment on your |
|---|
| 94 | arrival at the College. |
|---|
| 95 | |
|---|
| 96 | Accept my congratulations. Yours faithfully |
|---|
| 97 | |
|---|
| 98 | Ajoge E, A |
|---|
| 99 | Deputy Registrar (Admissions) |
|---|
| 100 | For: Registrar |
|---|
| 101 | """ |
|---|
| 102 | |
|---|
| 103 | def render(self): |
|---|
| 104 | students_utils = getUtility(IStudentsUtils) |
|---|
| 105 | letterhead_path = os.path.join( |
|---|
| 106 | os.path.dirname(__file__), 'static', 'letterhead_admission.jpg') |
|---|
| 107 | topMargin=1.8 |
|---|
| 108 | if self.context.student.current_mode.startswith('ug') and self.context.student.faccode != 'SUP': |
|---|
| 109 | letterhead_path = None |
|---|
| 110 | topMargin=1.3 |
|---|
| 111 | return students_utils.renderPDFAdmissionLetter(self, |
|---|
| 112 | self.context.student, omit_fields=self.omit_fields, |
|---|
| 113 | letterhead_path=letterhead_path, |
|---|
| 114 | topMargin=topMargin, |
|---|
| 115 | post_text=self._post_text) |
|---|
| 116 | |
|---|
| 117 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
|---|
| 118 | """ Page to view an online payment ticket |
|---|
| 119 | """ |
|---|
| 120 | grok.context(ICustomStudentOnlinePayment) |
|---|
| 121 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
|---|
| 122 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', 'p_combi') |
|---|
| 123 | form_fields[ |
|---|
| 124 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 125 | form_fields[ |
|---|
| 126 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 127 | |
|---|
| 128 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
|---|
| 129 | """ Page to add an online payment ticket |
|---|
| 130 | """ |
|---|
| 131 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
|---|
| 132 | 'p_combi') |
|---|
| 133 | |
|---|
| 134 | class OnlinePaymentApproveView(OnlinePaymentApproveView): |
|---|
| 135 | grok.require('waeup.manageStudent') |
|---|
| 136 | |
|---|
| 137 | class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip): |
|---|
| 138 | """Deliver a PDF slip of the context. |
|---|
| 139 | """ |
|---|
| 140 | grok.context(ICustomStudentOnlinePayment) |
|---|
| 141 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
|---|
| 142 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item', 'p_combi') |
|---|
| 143 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 144 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 145 | |
|---|
| 146 | class CustomStartClearancePage(StartClearancePage): |
|---|
| 147 | |
|---|
| 148 | @property |
|---|
| 149 | def with_ac(self): |
|---|
| 150 | mode = getattr(self.context, 'current_mode', None) |
|---|
| 151 | if mode and mode.startswith('ug'): |
|---|
| 152 | return True |
|---|
| 153 | return False |
|---|
| 154 | |
|---|
| 155 | class CustomStudentClearanceDisplayFormPage(NigeriaStudentClearanceDisplayFormPage): |
|---|
| 156 | """ Page to display student clearance data |
|---|
| 157 | """ |
|---|
| 158 | |
|---|
| 159 | @property |
|---|
| 160 | def form_fields(self): |
|---|
| 161 | if self.context.is_postgrad: |
|---|
| 162 | form_fields = grok.AutoFields( |
|---|
| 163 | ICustomPGStudentClearance).omit('clearance_locked') |
|---|
| 164 | else: |
|---|
| 165 | form_fields = grok.AutoFields( |
|---|
| 166 | ICustomUGStudentClearance).omit('clearance_locked') |
|---|
| 167 | if not getattr(self.context, 'officer_comment'): |
|---|
| 168 | form_fields = form_fields.omit('officer_comment') |
|---|
| 169 | else: |
|---|
| 170 | form_fields['officer_comment'].custom_widget = BytesDisplayWidget |
|---|
| 171 | return form_fields |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | class CustomStudentClearanceManageFormPage(NigeriaStudentClearanceManageFormPage): |
|---|
| 175 | """ Page to edit student clearance data |
|---|
| 176 | """ |
|---|
| 177 | |
|---|
| 178 | @property |
|---|
| 179 | def form_fields(self): |
|---|
| 180 | if self.context.is_postgrad: |
|---|
| 181 | form_fields = grok.AutoFields( |
|---|
| 182 | ICustomPGStudentClearance).omit('clr_code') |
|---|
| 183 | else: |
|---|
| 184 | form_fields = grok.AutoFields( |
|---|
| 185 | ICustomUGStudentClearance).omit('clr_code') |
|---|
| 186 | return form_fields |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip): |
|---|
| 190 | """Deliver a PDF slip of the context. |
|---|
| 191 | """ |
|---|
| 192 | |
|---|
| 193 | @property |
|---|
| 194 | def form_fields(self): |
|---|
| 195 | if self.context.is_postgrad: |
|---|
| 196 | form_fields = grok.AutoFields( |
|---|
| 197 | ICustomPGStudentClearance).omit('clearance_locked') |
|---|
| 198 | else: |
|---|
| 199 | form_fields = grok.AutoFields( |
|---|
| 200 | ICustomUGStudentClearance).omit('clearance_locked') |
|---|
| 201 | if not getattr(self.context, 'officer_comment'): |
|---|
| 202 | form_fields = form_fields.omit('officer_comment') |
|---|
| 203 | return form_fields |
|---|
| 204 | |
|---|
| 205 | @property |
|---|
| 206 | def label(self): |
|---|
| 207 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 208 | |
|---|
| 209 | line0 = '' |
|---|
| 210 | if self.context.student.current_mode.startswith('ug'): |
|---|
| 211 | line0 = 'Directorate of Undergraduate Programme\n' |
|---|
| 212 | line1 = translate(_('Clearance Slip of'), |
|---|
| 213 | 'waeup.kofa', target_language=portal_language) \ |
|---|
| 214 | + ' %s' % self.context.display_fullname |
|---|
| 215 | return '%s%s' % (line0, line1) |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
|---|
| 219 | """ View to edit student clearance data by student |
|---|
| 220 | """ |
|---|
| 221 | |
|---|
| 222 | def dataNotComplete(self): |
|---|
| 223 | return False |
|---|
| 224 | |
|---|
| 225 | @property |
|---|
| 226 | def form_fields(self): |
|---|
| 227 | if self.context.is_postgrad: |
|---|
| 228 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit( |
|---|
| 229 | 'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment', |
|---|
| 230 | 'physical_clearance_date') |
|---|
| 231 | else: |
|---|
| 232 | form_fields = grok.AutoFields(ICustomUGStudentClearance).omit( |
|---|
| 233 | 'clearance_locked', 'clr_code', 'officer_comment', |
|---|
| 234 | 'physical_clearance_date') |
|---|
| 235 | return form_fields |
|---|
| 236 | |
|---|
| 237 | class CustomBedTicketAddPage(NigeriaBedTicketAddPage): |
|---|
| 238 | """ Page to add an online payment ticket |
|---|
| 239 | """ |
|---|
| 240 | buttonname = _('Create bed ticket') |
|---|
| 241 | notice = '' |
|---|
| 242 | with_ac = False |
|---|
| 243 | with_bedselection = True |
|---|
| 244 | |
|---|
| 245 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
|---|
| 246 | """ Page to display student study levels |
|---|
| 247 | """ |
|---|
| 248 | grok.context(ICustomStudentStudyLevel) |
|---|
| 249 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit('level') |
|---|
| 250 | form_fields[ |
|---|
| 251 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
|---|
| 252 | |
|---|
| 253 | class CustomExportPDFCourseRegistrationSlip( |
|---|
| 254 | NigeriaExportPDFCourseRegistrationSlip): |
|---|
| 255 | """Deliver a PDF slip of the context. |
|---|
| 256 | """ |
|---|
| 257 | grok.context(ICustomStudentStudyLevel) |
|---|
| 258 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
|---|
| 259 | 'level', 'level_verdict', 'validated_by', 'transcript_remark', 'gpa') |
|---|
| 260 | omit_fields = ('password', 'suspended', 'suspended_comment', |
|---|
| 261 | 'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'current_level', |
|---|
| 262 | 'flash_notice', 'parents_email', 'entry_session', 'password_updated') |
|---|
| 263 | |
|---|
| 264 | class ExportPDFExaminationClearanceSlip1(CustomExportPDFCourseRegistrationSlip): |
|---|
| 265 | """Deliver a PDF slip of the context. |
|---|
| 266 | """ |
|---|
| 267 | grok.name('examination_clearance_slip_1.pdf') |
|---|
| 268 | form_fields = None |
|---|
| 269 | omit_fields = ( |
|---|
| 270 | 'password', 'suspended', 'phone', 'date_of_birth', |
|---|
| 271 | 'parents_email', 'current_mode', 'entry_session', |
|---|
| 272 | 'adm_code', 'sex', 'suspended_comment', |
|---|
| 273 | 'flash_notice') |
|---|
| 274 | semester = 1 |
|---|
| 275 | tabletitle = ['', '', ''] |
|---|
| 276 | |
|---|
| 277 | @property |
|---|
| 278 | def label(self): |
|---|
| 279 | return '%s First Semester Examination Clearance' % self.context.level_session |
|---|
| 280 | |
|---|
| 281 | @property |
|---|
| 282 | def title(self): |
|---|
| 283 | return '' |
|---|
| 284 | |
|---|
| 285 | def update(self): |
|---|
| 286 | if self.context.student.state != VALIDATED \ |
|---|
| 287 | or self.context.student.current_level != self.context.level: |
|---|
| 288 | self.flash(_('Forbidden'), type="warning") |
|---|
| 289 | self.redirect(self.url(self.context)) |
|---|
| 290 | |
|---|
| 291 | def render(self): |
|---|
| 292 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
|---|
| 293 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
|---|
| 294 | studentview = StudentBasePDFFormPage(self.context.student, |
|---|
| 295 | self.request, self.omit_fields) |
|---|
| 296 | students_utils = getUtility(IStudentsUtils) |
|---|
| 297 | |
|---|
| 298 | tabledata = [] |
|---|
| 299 | tableheader = [] |
|---|
| 300 | for i in range(1,7): |
|---|
| 301 | tabledata.append(sorted( |
|---|
| 302 | [value for value in self.context.values() if i == self.semester == value.semester], |
|---|
| 303 | key=lambda value: value.code)) |
|---|
| 304 | tableheader.append([(Code,'code', 2.5), |
|---|
| 305 | ('Invigilator\'s Name','inv', 8), |
|---|
| 306 | ('Signature and Date','sig', 7), |
|---|
| 307 | ]) |
|---|
| 308 | return students_utils.renderPDF( |
|---|
| 309 | self, 'examination_clearance_slip_%s.pdf' % self.semester, |
|---|
| 310 | self.context.student, studentview, |
|---|
| 311 | tableheader=tableheader, |
|---|
| 312 | tabledata=tabledata, |
|---|
| 313 | omit_fields=self.omit_fields, |
|---|
| 314 | topMargin=1.3 |
|---|
| 315 | ) |
|---|
| 316 | |
|---|
| 317 | class ExportPDFExaminationClearanceSlip2(ExportPDFExaminationClearanceSlip1): |
|---|
| 318 | """Deliver a PDF slip of the context. |
|---|
| 319 | """ |
|---|
| 320 | grok.name('examination_clearance_slip_2.pdf') |
|---|
| 321 | semester = 2 |
|---|
| 322 | |
|---|
| 323 | @property |
|---|
| 324 | def label(self): |
|---|
| 325 | return '%s Second Semester Examination Clearance' % self.context.level_session |
|---|
| 326 | |
|---|
| 327 | class CustomPaymentsManageFormPage(PaymentsManageFormPage): |
|---|
| 328 | """ Page to manage the student payments. This manage form page is for |
|---|
| 329 | both students and students officers. FCEOkene does not allow students |
|---|
| 330 | to remove any payment ticket. |
|---|
| 331 | """ |
|---|
| 332 | @property |
|---|
| 333 | def manage_payments_allowed(self): |
|---|
| 334 | return checkPermission('waeup.manageStudent', self.context) |
|---|
| 335 | |
|---|
| 336 | class CustomAccommodationDisplayFormPage(NigeriaAccommodationDisplayFormPage): |
|---|
| 337 | """ Page to view bed tickets. |
|---|
| 338 | """ |
|---|
| 339 | with_hostel_selection = True |
|---|
| 340 | |
|---|
| 341 | class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage): |
|---|
| 342 | """ Page to manage bed tickets. |
|---|
| 343 | This manage form page is for both students and students officers. |
|---|
| 344 | """ |
|---|
| 345 | with_hostel_selection = True |
|---|