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