[8911] | 1 | ## $Id: browser.py 13437 2015-11-11 13:40:53Z 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 |
---|
[9914] | 20 | from zope.component import getUtility |
---|
[13351] | 21 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
[11597] | 22 | from waeup.kofa.browser.layout import UtilityView |
---|
[8911] | 23 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
[9914] | 24 | from waeup.kofa.interfaces import IKofaUtils |
---|
[11597] | 25 | from waeup.kofa.students.interfaces import IStudentsUtils, IStudent |
---|
[13038] | 26 | from waeup.kofa.students.workflow import PAID, REGISTERED |
---|
[9914] | 27 | from waeup.kofa.students.browser import ( |
---|
[11846] | 28 | StartClearancePage, |
---|
[9914] | 29 | StudentBasePDFFormPage, |
---|
| 30 | CourseTicketAddFormPage, |
---|
| 31 | StudyLevelDisplayFormPage, |
---|
[13059] | 32 | ExportPDFTranscriptSlip, |
---|
| 33 | ExportPDFAdmissionSlip, |
---|
[13353] | 34 | BedTicketAddPage, |
---|
[13380] | 35 | StudentFilesUploadPage, |
---|
[10269] | 36 | ) |
---|
[8911] | 37 | from kofacustom.nigeria.students.browser import ( |
---|
| 38 | NigeriaOnlinePaymentDisplayFormPage, |
---|
| 39 | NigeriaOnlinePaymentAddFormPage, |
---|
[13059] | 40 | NigeriaExportPDFPaymentSlip, |
---|
| 41 | NigeriaExportPDFCourseRegistrationSlip, |
---|
| 42 | NigeriaExportPDFClearanceSlip, |
---|
[13351] | 43 | NigeriaStudentPersonalDisplayFormPage, |
---|
| 44 | NigeriaStudentPersonalEditFormPage, |
---|
| 45 | NigeriaStudentPersonalManageFormPage, |
---|
[13362] | 46 | NigeriaStudentClearanceEditFormPage, |
---|
[10269] | 47 | ) |
---|
[9496] | 48 | from waeup.aaue.students.interfaces import ( |
---|
[9914] | 49 | ICustomStudentOnlinePayment, |
---|
[11607] | 50 | ICustomStudentStudyLevel, |
---|
[13351] | 51 | ICustomStudent, |
---|
| 52 | ICustomStudentPersonal, |
---|
[13362] | 53 | ICustomStudentPersonalEdit, |
---|
| 54 | ICustomUGStudentClearance) |
---|
[13414] | 55 | from waeup.aaue.interswitch.browser import gateway_net_amt |
---|
[9914] | 56 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
[8911] | 57 | |
---|
[13351] | 58 | class CustomStudentPersonalDisplayFormPage(NigeriaStudentPersonalDisplayFormPage): |
---|
| 59 | """ Page to display student personal data |
---|
| 60 | """ |
---|
| 61 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
| 62 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 63 | form_fields['father_address'].custom_widget = BytesDisplayWidget |
---|
| 64 | form_fields['mother_address'].custom_widget = BytesDisplayWidget |
---|
| 65 | form_fields['next_kin_address'].custom_widget = BytesDisplayWidget |
---|
| 66 | form_fields[ |
---|
| 67 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 68 | |
---|
| 69 | class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage): |
---|
| 70 | """ Page to edit personal data |
---|
| 71 | """ |
---|
| 72 | form_fields = grok.AutoFields(ICustomStudentPersonalEdit).omit('personal_updated') |
---|
| 73 | |
---|
| 74 | class CustomStudentPersonalManageFormPage(NigeriaStudentPersonalManageFormPage): |
---|
| 75 | """ Page to edit personal data |
---|
| 76 | """ |
---|
| 77 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
| 78 | form_fields['personal_updated'].for_display = True |
---|
| 79 | form_fields[ |
---|
| 80 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 81 | |
---|
[13362] | 82 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
| 83 | """ View to edit student clearance data by student |
---|
| 84 | """ |
---|
| 85 | |
---|
| 86 | @property |
---|
| 87 | def form_fields(self): |
---|
| 88 | if self.context.is_postgrad: |
---|
| 89 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit( |
---|
| 90 | 'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment', |
---|
| 91 | 'physical_clearance_date') |
---|
| 92 | else: |
---|
| 93 | form_fields = grok.AutoFields(ICustomUGStudentClearance).omit( |
---|
| 94 | 'clearance_locked', 'clr_code', 'officer_comment', |
---|
| 95 | 'physical_clearance_date') |
---|
| 96 | return form_fields |
---|
| 97 | |
---|
[11846] | 98 | class CustomStartClearancePage(StartClearancePage): |
---|
[13360] | 99 | with_ac = False |
---|
[11846] | 100 | |
---|
[13351] | 101 | @property |
---|
| 102 | def all_required_fields_filled(self): |
---|
| 103 | if not self.context.email: |
---|
| 104 | return _("Email address is missing."), 'edit_base' |
---|
| 105 | if not self.context.phone: |
---|
| 106 | return _("Phone number is missing."), 'edit_base' |
---|
| 107 | if not self.context.father_name: |
---|
| 108 | return _("Personal data form is not properly filled."), 'edit_personal' |
---|
| 109 | return |
---|
| 110 | |
---|
[8911] | 111 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
| 112 | """ Page to view an online payment ticket |
---|
| 113 | """ |
---|
| 114 | grok.context(ICustomStudentOnlinePayment) |
---|
[9853] | 115 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9990] | 116 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 117 | form_fields[ |
---|
| 118 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 119 | form_fields[ |
---|
| 120 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 121 | |
---|
| 122 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
| 123 | """ Page to add an online payment ticket |
---|
| 124 | """ |
---|
| 125 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
| 126 | 'p_category') |
---|
| 127 | |
---|
[13059] | 128 | class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip): |
---|
[8911] | 129 | """Deliver a PDF slip of the context. |
---|
| 130 | """ |
---|
| 131 | grok.context(ICustomStudentOnlinePayment) |
---|
[9853] | 132 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9990] | 133 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 134 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9496] | 135 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9914] | 136 | |
---|
[11625] | 137 | @property |
---|
| 138 | def note(self): |
---|
[13408] | 139 | p_session = self.context.p_session |
---|
[13405] | 140 | try: |
---|
[13408] | 141 | academic_session = grok.getSite()['configuration'][str(p_session)] |
---|
[13405] | 142 | except KeyError: |
---|
| 143 | academic_session = None |
---|
[13425] | 144 | text = '\n\n The Amount Authorized is inclusive of: ' |
---|
[13405] | 145 | if self.context.p_category == 'schoolfee_incl' and academic_session: |
---|
[13414] | 146 | welfare_fee = gateway_net_amt(academic_session.welfare_fee) |
---|
| 147 | union_fee = gateway_net_amt(academic_session.union_fee) |
---|
[13437] | 148 | text += ('School Fee, ' |
---|
| 149 | '%s Naira Students\' Union Dues, ' |
---|
| 150 | '%s Naira Student Welfare Assurance Fee and ' |
---|
[13425] | 151 | % (union_fee, welfare_fee)) |
---|
[13410] | 152 | elif self.context.p_category in ( |
---|
| 153 | 'clearance_incl', 'clearance_medical_incl') and academic_session: |
---|
[13414] | 154 | matric_gown_fee = gateway_net_amt(academic_session.matric_gown_fee) |
---|
| 155 | lapel_fee = gateway_net_amt(academic_session.lapel_fee) |
---|
[13437] | 156 | text += ('Acceptance Fee, ' |
---|
| 157 | '%s Naira Matriculation Gown Fee, ' |
---|
| 158 | '%s Naira Lapel/File Fee and ' |
---|
[13408] | 159 | % (matric_gown_fee, lapel_fee)) |
---|
[13437] | 160 | return text + '250.0 Naira Transaction Charge.' |
---|
[11625] | 161 | |
---|
[9914] | 162 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
| 163 | """ Page to display student study levels |
---|
| 164 | """ |
---|
| 165 | grok.context(ICustomStudentStudyLevel) |
---|
[10480] | 166 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
[12876] | 167 | 'total_credits', 'gpa', 'level') |
---|
[9914] | 168 | form_fields[ |
---|
| 169 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 170 | |
---|
[13059] | 171 | class CustomExportPDFCourseRegistrationSlip( |
---|
| 172 | NigeriaExportPDFCourseRegistrationSlip): |
---|
[9914] | 173 | """Deliver a PDF slip of the context. |
---|
| 174 | """ |
---|
| 175 | grok.context(ICustomStudentStudyLevel) |
---|
| 176 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
[10102] | 177 | 'level_session', 'level_verdict', |
---|
[12876] | 178 | 'validated_by', 'validation_date', 'gpa', 'level') |
---|
[9914] | 179 | |
---|
[10269] | 180 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
[10689] | 181 | 'phone', 'adm_code', 'sex', 'email', 'date_of_birth', |
---|
[11538] | 182 | 'department', 'current_mode', 'current_level') |
---|
[10269] | 183 | |
---|
[13038] | 184 | def update(self): |
---|
| 185 | if self.context.student.state != REGISTERED \ |
---|
[13051] | 186 | and self.context.student.current_level == self.context.level: |
---|
[13038] | 187 | self.flash(_('Forbidden'), type="warning") |
---|
| 188 | self.redirect(self.url(self.context)) |
---|
| 189 | |
---|
[9914] | 190 | @property |
---|
| 191 | def label(self): |
---|
| 192 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 193 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
| 194 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
| 195 | target_language=lang) |
---|
| 196 | line0 = '' |
---|
| 197 | if self.context.student.current_mode.endswith('_pt'): |
---|
| 198 | line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n' |
---|
| 199 | line1 = translate(_('Course Registration Slip'), |
---|
| 200 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 201 | + ' %s' % level_title |
---|
| 202 | line2 = translate(_('Session'), |
---|
| 203 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 204 | + ' %s' % self.context.getSessionString |
---|
| 205 | return '%s%s\n%s' % (line0, line1, line2) |
---|
| 206 | |
---|
| 207 | @property |
---|
| 208 | def title(self): |
---|
| 209 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 210 | return translate(_('Units Registered'), 'waeup.kofa', |
---|
| 211 | target_language=portal_language) |
---|
| 212 | |
---|
| 213 | def _signatures(self): |
---|
[9968] | 214 | return ( |
---|
| 215 | [('I have selected the course on the advise of my Head of ' |
---|
| 216 | 'Department. <br>', _('Student\'s Signature'), '<br>')], |
---|
| 217 | [('This student has satisfied the department\'s requirements. ' |
---|
| 218 | 'I recommend to approve the course registration. <br>', |
---|
| 219 | _('Head of Department\'s Signature'), '<br>')], |
---|
| 220 | [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')], |
---|
| 221 | [('', _('Director\'s Signature'))] |
---|
| 222 | ) |
---|
[9914] | 223 | |
---|
| 224 | def render(self): |
---|
| 225 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 226 | Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language) |
---|
| 227 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
| 228 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
| 229 | Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language) |
---|
| 230 | Score = translate('Score', 'waeup.kofa', target_language=portal_language) |
---|
| 231 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
[10269] | 232 | Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue', |
---|
[9914] | 233 | target_language=portal_language) |
---|
| 234 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 235 | self.request, self.omit_fields) |
---|
| 236 | students_utils = getUtility(IStudentsUtils) |
---|
[10442] | 237 | |
---|
| 238 | tabledata = [] |
---|
| 239 | tableheader = [] |
---|
| 240 | contenttitle = [] |
---|
| 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.0), |
---|
| 246 | (Title,'title', 7), |
---|
| 247 | (Cred, 'credits', 1.5), |
---|
| 248 | (Score, 'score', 1.4), |
---|
| 249 | (Grade, 'grade', 1.4), |
---|
| 250 | (Signature, 'dummy', 3), |
---|
| 251 | ]) |
---|
[9914] | 252 | if len(self.label.split('\n')) == 3: |
---|
| 253 | topMargin = 1.9 |
---|
| 254 | elif len(self.label.split('\n')) == 2: |
---|
| 255 | topMargin = 1.7 |
---|
| 256 | else: |
---|
| 257 | topMargin = 1.5 |
---|
| 258 | return students_utils.renderPDF( |
---|
| 259 | self, 'course_registration_slip.pdf', |
---|
| 260 | self.context.student, studentview, |
---|
[10442] | 261 | tableheader=tableheader, |
---|
| 262 | tabledata=tabledata, |
---|
[9914] | 263 | signatures=self._signatures(), |
---|
[10269] | 264 | topMargin=topMargin, |
---|
| 265 | omit_fields=self.omit_fields |
---|
[9914] | 266 | ) |
---|
[10566] | 267 | |
---|
[13059] | 268 | class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip): |
---|
[10566] | 269 | """Deliver a PDF slip of the context. |
---|
| 270 | """ |
---|
| 271 | |
---|
| 272 | def _sigsInFooter(self): |
---|
| 273 | return [] |
---|
| 274 | |
---|
| 275 | def _signatures(self): |
---|
| 276 | return ([( |
---|
[11555] | 277 | 'Akhimien Felicia O. (MANUPA) <br /> Principal Assistant Registrar <br /> ' |
---|
| 278 | 'Exams, Records and Data Processing Division <br /> For: Registrar')],) |
---|
[10922] | 279 | |
---|
[13059] | 280 | class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip): |
---|
[10922] | 281 | """Deliver a PDF Admission slip. |
---|
| 282 | """ |
---|
| 283 | |
---|
| 284 | @property |
---|
| 285 | def label(self): |
---|
| 286 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 287 | return translate(_('e-Admission Slip \n'), |
---|
| 288 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 289 | + ' %s' % self.context.display_fullname |
---|
[11597] | 290 | |
---|
[13059] | 291 | class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip): |
---|
[11606] | 292 | """Deliver a PDF slip of the context. |
---|
| 293 | """ |
---|
| 294 | |
---|
| 295 | @property |
---|
| 296 | def label(self): |
---|
| 297 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 298 | return translate(_('Clearance Slip\n'), |
---|
| 299 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 300 | + ' %s' % self.context.display_fullname |
---|
| 301 | |
---|
[11597] | 302 | class StudentGetMatricNumberPage(UtilityView, grok.View): |
---|
| 303 | """ Construct and set the matriculation number. |
---|
| 304 | """ |
---|
| 305 | grok.context(IStudent) |
---|
| 306 | grok.name('get_matric_number') |
---|
| 307 | grok.require('waeup.viewStudent') |
---|
| 308 | |
---|
| 309 | def update(self): |
---|
| 310 | students_utils = getUtility(IStudentsUtils) |
---|
| 311 | msg, mnumber = students_utils.setMatricNumber(self.context) |
---|
| 312 | if msg: |
---|
| 313 | self.flash(msg, type="danger") |
---|
| 314 | else: |
---|
| 315 | self.flash(_('Matriculation number %s assigned.' % mnumber)) |
---|
[11602] | 316 | self.context.writeLogMessage(self, '%s assigned' % mnumber) |
---|
[11597] | 317 | self.redirect(self.url(self.context)) |
---|
| 318 | return |
---|
| 319 | |
---|
| 320 | def render(self): |
---|
[11607] | 321 | return |
---|
| 322 | |
---|
[13059] | 323 | class ExportPDFMatricNumberSlip(UtilityView, grok.View): |
---|
[11607] | 324 | """Deliver a PDF notification slip. |
---|
| 325 | """ |
---|
| 326 | grok.context(ICustomStudent) |
---|
| 327 | grok.name('matric_number_slip.pdf') |
---|
| 328 | grok.require('waeup.viewStudent') |
---|
| 329 | prefix = 'form' |
---|
| 330 | |
---|
| 331 | form_fields = grok.AutoFields(ICustomStudent).select( |
---|
| 332 | 'student_id', 'matric_number') |
---|
| 333 | omit_fields = ('date_of_birth', 'current_level') |
---|
| 334 | |
---|
| 335 | @property |
---|
| 336 | def label(self): |
---|
| 337 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 338 | return translate(_('Matriculation Number Slip\n'), |
---|
| 339 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 340 | + ' %s' % self.context.display_fullname |
---|
| 341 | |
---|
| 342 | def render(self): |
---|
| 343 | if self.context.state not in (PAID,) or not self.context.is_fresh \ |
---|
| 344 | or not self.context.matric_number: |
---|
| 345 | self.flash('Not allowed.', type="danger") |
---|
| 346 | self.redirect(self.url(self.context)) |
---|
| 347 | return |
---|
| 348 | students_utils = getUtility(IStudentsUtils) |
---|
[11609] | 349 | pre_text = _('Congratulations! Your acceptance fee and school fees ' + |
---|
| 350 | 'payments have been received and your matriculation ' + |
---|
| 351 | 'number generated with details as follows.') |
---|
[11607] | 352 | return students_utils.renderPDFAdmissionLetter(self, |
---|
| 353 | self.context.student, omit_fields=self.omit_fields, |
---|
[13353] | 354 | pre_text=pre_text, post_text='') |
---|
| 355 | |
---|
| 356 | class CustomBedTicketAddPage(BedTicketAddPage): |
---|
[13360] | 357 | with_ac = False |
---|
[13380] | 358 | |
---|
| 359 | class CustomStudentFilesUploadPage(StudentFilesUploadPage): |
---|
| 360 | """ View to upload files by student. Inherit from same class in |
---|
| 361 | base package, not from kofacustom.nigeria which |
---|
| 362 | requires that no application slip exists. |
---|
| 363 | """ |
---|