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