[10765] | 1 | ## $Id: browser.py 15187 2018-10-14 20:28:51Z 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 |
---|
| 20 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
| 21 | from zope.component import getUtility |
---|
| 22 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
| 23 | from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils |
---|
| 24 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
[15176] | 25 | from waeup.kofa.browser.layout import ( |
---|
| 26 | KofaEditFormPage, UtilityView, action, jsaction) |
---|
[10765] | 27 | from waeup.kofa.students.browser import ( |
---|
| 28 | StudyLevelEditFormPage, StudyLevelDisplayFormPage, |
---|
[13062] | 29 | StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip, |
---|
[10765] | 30 | CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage, |
---|
[15088] | 31 | BedTicketAddPage, ExportPDFTranscriptSlip, |
---|
[10765] | 32 | msave, emit_lock_message) |
---|
[15176] | 33 | from waeup.kofa.students.interfaces import ( |
---|
| 34 | IStudentsUtils, ICourseTicket, IStudent) |
---|
[15177] | 35 | from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS, PAID |
---|
[10765] | 36 | from kofacustom.nigeria.students.browser import ( |
---|
| 37 | NigeriaOnlinePaymentDisplayFormPage, |
---|
| 38 | NigeriaStudentBaseManageFormPage, |
---|
| 39 | NigeriaStudentClearanceEditFormPage, |
---|
| 40 | NigeriaOnlinePaymentAddFormPage, |
---|
[13062] | 41 | NigeriaExportPDFPaymentSlip, |
---|
| 42 | NigeriaExportPDFClearanceSlip, |
---|
[10765] | 43 | ) |
---|
[15000] | 44 | from kofacustom.edopoly.students.interfaces import ( |
---|
[10765] | 45 | ICustomStudentOnlinePayment, ICustomStudentStudyCourse, |
---|
[15176] | 46 | ICustomStudentStudyLevel, ICustomStudent) |
---|
[15000] | 47 | from kofacustom.edopoly.interfaces import MessageFactory as _ |
---|
[10765] | 48 | |
---|
[15017] | 49 | class CustomBedTicketAddPage(BedTicketAddPage): |
---|
| 50 | with_ac = False |
---|
[15088] | 51 | |
---|
| 52 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
| 53 | """ Page to display student study levels |
---|
| 54 | """ |
---|
| 55 | grok.template('studylevelpage') |
---|
| 56 | |
---|
| 57 | class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): |
---|
| 58 | """ Page to edit the student study level data by students. |
---|
| 59 | |
---|
| 60 | """ |
---|
| 61 | grok.template('studyleveleditpage') |
---|
| 62 | |
---|
| 63 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
| 64 | """ Page to display course tickets |
---|
| 65 | """ |
---|
| 66 | form_fields = grok.AutoFields(ICourseTicket).omit('score') |
---|
| 67 | |
---|
| 68 | class CustomExportPDFCourseRegistrationSlip(ExportPDFCourseRegistrationSlip): |
---|
| 69 | """Deliver a PDF slip of the context. |
---|
| 70 | """ |
---|
| 71 | |
---|
| 72 | def render(self): |
---|
| 73 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 74 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
---|
| 75 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
---|
| 76 | Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language) |
---|
| 77 | Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language) |
---|
| 78 | Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language) |
---|
| 79 | #Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language) |
---|
| 80 | #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
---|
| 81 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
---|
| 82 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 83 | self.request, self.omit_fields) |
---|
| 84 | students_utils = getUtility(IStudentsUtils) |
---|
| 85 | |
---|
| 86 | tabledata = [] |
---|
| 87 | tableheader = [] |
---|
| 88 | for i in range(1,7): |
---|
| 89 | tabledata.append(sorted( |
---|
| 90 | [value for value in self.context.values() if value.semester == i], |
---|
| 91 | key=lambda value: str(value.semester) + value.code)) |
---|
| 92 | tableheader.append([(Code,'code', 2.5), |
---|
| 93 | (Title,'title', 5), |
---|
| 94 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
| 95 | (Cred, 'credits', 1.5), |
---|
| 96 | #(Mand, 'mandatory', 1.5), |
---|
| 97 | #(Score, 'score', 1.5), |
---|
| 98 | (Grade, 'grade', 1.5), |
---|
| 99 | #('Auto', 'automatic', 1.5) |
---|
| 100 | ]) |
---|
| 101 | return students_utils.renderPDF( |
---|
| 102 | self, 'course_registration_slip.pdf', |
---|
| 103 | self.context.student, studentview, |
---|
| 104 | tableheader=tableheader, |
---|
| 105 | tabledata=tabledata, |
---|
| 106 | omit_fields=self.omit_fields |
---|
| 107 | ) |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip): |
---|
| 111 | """Deliver a PDF slip of the context. |
---|
| 112 | """ |
---|
| 113 | |
---|
| 114 | def render(self): |
---|
| 115 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 116 | Term = translate(_('Term'), 'waeup.kofa', target_language=portal_language) |
---|
| 117 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
---|
| 118 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
---|
| 119 | Cred = translate(_('Credits'), 'waeup.kofa', target_language=portal_language) |
---|
| 120 | #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
---|
| 121 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
---|
| 122 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 123 | self.request, self.omit_fields) |
---|
| 124 | students_utils = getUtility(IStudentsUtils) |
---|
| 125 | |
---|
| 126 | tableheader = [(Code,'code', 2.5), |
---|
| 127 | (Title,'title', 8.5), |
---|
| 128 | (Term, 'semester', 1.5), |
---|
| 129 | (Cred, 'credits', 1.5), |
---|
| 130 | #(Score, 'score', 1.5), |
---|
| 131 | (Grade, 'grade', 1.5), |
---|
| 132 | ] |
---|
| 133 | |
---|
[15167] | 134 | pdfstream = students_utils.renderPDFTranscript( |
---|
[15088] | 135 | self, 'transcript.pdf', |
---|
| 136 | self.context.student, studentview, |
---|
| 137 | omit_fields=self.omit_fields, |
---|
| 138 | tableheader=tableheader, |
---|
| 139 | signatures=self._signatures(), |
---|
| 140 | sigs_in_footer=self._sigsInFooter(), |
---|
[15167] | 141 | digital_sigs=self._digital_sigs(), |
---|
| 142 | save_file=self._save_file(), |
---|
[15088] | 143 | ) |
---|
[15167] | 144 | if not pdfstream: |
---|
| 145 | self.redirect(self.url(self.context.student)) |
---|
| 146 | return |
---|
| 147 | return |
---|
[15176] | 148 | |
---|
| 149 | class StudentGetMatricNumberPage(UtilityView, grok.View): |
---|
| 150 | """ Construct and set the matriculation number. |
---|
| 151 | """ |
---|
| 152 | grok.context(IStudent) |
---|
| 153 | grok.name('get_matric_number') |
---|
| 154 | grok.require('waeup.viewStudent') |
---|
| 155 | |
---|
| 156 | def update(self): |
---|
| 157 | students_utils = getUtility(IStudentsUtils) |
---|
| 158 | msg, mnumber = students_utils.setMatricNumber(self.context) |
---|
| 159 | if msg: |
---|
| 160 | self.flash(msg, type="danger") |
---|
| 161 | else: |
---|
| 162 | self.flash(_('Matriculation number %s assigned.' % mnumber)) |
---|
| 163 | self.context.writeLogMessage(self, '%s assigned' % mnumber) |
---|
| 164 | self.redirect(self.url(self.context)) |
---|
| 165 | return |
---|
| 166 | |
---|
| 167 | def render(self): |
---|
| 168 | return |
---|
| 169 | |
---|
| 170 | class ExportPDFMatricNumberSlip(UtilityView, grok.View): |
---|
| 171 | """Deliver a PDF notification slip. |
---|
| 172 | """ |
---|
| 173 | grok.context(ICustomStudent) |
---|
| 174 | grok.name('matric_number_slip.pdf') |
---|
| 175 | grok.require('waeup.viewStudent') |
---|
| 176 | prefix = 'form' |
---|
| 177 | |
---|
| 178 | form_fields = grok.AutoFields(ICustomStudent).select( |
---|
| 179 | 'student_id', 'matric_number') |
---|
| 180 | omit_fields = ('date_of_birth', 'current_level', 'flash_notice') |
---|
| 181 | |
---|
| 182 | @property |
---|
| 183 | def title(self): |
---|
| 184 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 185 | return translate(_('Matriculation Number'), 'waeup.kofa', |
---|
| 186 | target_language=portal_language) |
---|
| 187 | |
---|
| 188 | @property |
---|
| 189 | def label(self): |
---|
| 190 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 191 | return translate(_('Matriculation Number Slip\n'), |
---|
| 192 | target_language=portal_language) \ |
---|
| 193 | + ' %s' % self.context.display_fullname |
---|
| 194 | |
---|
| 195 | def render(self): |
---|
| 196 | if self.context.state not in (PAID,) or not self.context.is_fresh \ |
---|
| 197 | or not self.context.matric_number: |
---|
| 198 | self.flash('Not allowed.', type="danger") |
---|
| 199 | self.redirect(self.url(self.context)) |
---|
| 200 | return |
---|
| 201 | students_utils = getUtility(IStudentsUtils) |
---|
| 202 | pre_text = _('Congratulations! Your acceptance fee and school fees ' + |
---|
| 203 | 'payments have been received and your matriculation ' + |
---|
| 204 | 'number generated with details as follows.') |
---|
| 205 | return students_utils.renderPDFAdmissionLetter(self, |
---|
| 206 | self.context.student, omit_fields=self.omit_fields, |
---|
[15185] | 207 | pre_text=pre_text, post_text='') |
---|
| 208 | |
---|
| 209 | class MedicalLaboratoryRequestForm(UtilityView, grok.View): |
---|
| 210 | """Deliver a PDF notification slip. |
---|
| 211 | """ |
---|
| 212 | grok.context(ICustomStudent) |
---|
| 213 | grok.name('medical_laboratory_form.pdf') |
---|
| 214 | grok.require('waeup.viewStudent') |
---|
| 215 | prefix = 'form' |
---|
| 216 | |
---|
| 217 | form_fields = grok.AutoFields(ICustomStudent).select( |
---|
| 218 | 'student_id', 'matric_number', 'sex', 'email', 'phone', 'perm_address') |
---|
| 219 | omit_fields = ('current_mode') |
---|
| 220 | |
---|
| 221 | label = u'Student\'s Medical Laboratory Request Form' |
---|
| 222 | title = u'Student\'s Medical Laboratory Request Form' |
---|
| 223 | |
---|
| 224 | post_text = """ |
---|
| 225 | |
---|
| 226 | Laboratory request: Student's Medical Test |
---|
| 227 | |
---|
| 228 | Lab Results/Status: |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | |
---|
[15187] | 233 | |
---|
| 234 | |
---|
| 235 | Medical Laboratory Scientist's Signature: |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | |
---|
| 240 | |
---|
| 241 | |
---|
[15185] | 242 | Notice to all newly admitted students: |
---|
| 243 | |
---|
| 244 | 1. Carry out your mandatory medical laboratory tests at: |
---|
| 245 | (a) the Edo State Polyechnic Health Centre |
---|
| 246 | 2. Evidence of medical screening payment and the downloaded student's laboratory test request form are required for the medical tests to be conducted for students. |
---|
| 247 | 3. Collect your lab tests results and upload during clearance process online. |
---|
| 248 | 4. Students' admission records and clearance are incomplete without medical test result. |
---|
| 249 | 5. Results of medical tests from elsewhere are not accepted. |
---|
| 250 | 6. Medical tests are conducted only within admission period, and will end in matriculation week. Unnecessary delays will not be allowed. |
---|
| 251 | 7. This information applies to both full- time and part-time. |
---|
| 252 | """ |
---|
| 253 | |
---|
| 254 | def render(self): |
---|
| 255 | if not self.context.medical_fee_paid: |
---|
| 256 | self.flash('Not allowed.', type="danger") |
---|
| 257 | self.redirect(self.url(self.context)) |
---|
| 258 | return |
---|
| 259 | students_utils = getUtility(IStudentsUtils) |
---|
| 260 | return students_utils.renderPDFAdmissionLetter(self, |
---|
| 261 | self.context.student, omit_fields=self.omit_fields, |
---|
| 262 | pre_text='', post_text=self.post_text) |
---|