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