[8911] | 1 | ## $Id: browser.py 10819 2013-11-29 13:44:55Z 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 |
---|
[10710] | 20 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
[10691] | 21 | from zope.component import getUtility |
---|
[9156] | 22 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
[10692] | 23 | from waeup.kofa.interfaces import ADMITTED, IKofaUtils |
---|
[10691] | 24 | from waeup.kofa.browser.layout import UtilityView |
---|
| 25 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
[8911] | 26 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
[10691] | 27 | from waeup.kofa.students.browser import ( |
---|
[10692] | 28 | StartClearancePage, BedTicketAddPage, ExportPDFAdmissionSlipPage, |
---|
| 29 | StudentBasePDFFormPage) |
---|
[10691] | 30 | from waeup.kwarapoly.students.interfaces import ( |
---|
[10692] | 31 | ICustomStudent, ICustomStudentBase, ICustomStudentStudyLevel) |
---|
[10691] | 32 | from waeup.kwarapoly.interfaces import MessageFactory as _ |
---|
| 33 | from waeup.kofa.students.workflow import ( |
---|
| 34 | ADMITTED, PAID, REQUESTED, RETURNING, CLEARED, REGISTERED, |
---|
| 35 | VALIDATED, GRADUATED, TRANSCRIPT, CREATED, CLEARANCE) |
---|
[8911] | 36 | from kofacustom.nigeria.students.browser import ( |
---|
| 37 | NigeriaOnlinePaymentDisplayFormPage, |
---|
| 38 | NigeriaOnlinePaymentAddFormPage, |
---|
[9181] | 39 | NigeriaExportPDFPaymentSlipPage, |
---|
[9190] | 40 | NigeriaStudentClearanceEditFormPage, |
---|
[10692] | 41 | NigeriaExportPDFCourseRegistrationSlipPage, |
---|
[10710] | 42 | NigeriaStudentPersonalDisplayFormPage, |
---|
| 43 | NigeriaStudentPersonalEditFormPage, |
---|
[10819] | 44 | NigeriaStudentPersonalManageFormPage, |
---|
| 45 | NigeriaStudentBaseEditFormPage |
---|
[9190] | 46 | ) |
---|
[8911] | 47 | |
---|
[10710] | 48 | from waeup.kwarapoly.students.interfaces import ( |
---|
| 49 | ICustomStudentOnlinePayment, |
---|
| 50 | ICustomStudentPersonal, |
---|
| 51 | ICustomStudentPersonalEdit |
---|
| 52 | ) |
---|
[8911] | 53 | |
---|
[10819] | 54 | class CustomStudentBaseEditFormPage(NigeriaStudentBaseEditFormPage): |
---|
| 55 | """ View to edit student base data |
---|
| 56 | """ |
---|
| 57 | form_fields = grok.AutoFields(ICustomStudentBase).select( |
---|
| 58 | 'email', 'phone', 'sex') |
---|
| 59 | |
---|
[10710] | 60 | class CustomStudentPersonalDisplayFormPage(NigeriaStudentPersonalDisplayFormPage): |
---|
| 61 | """ Page to display student personal data |
---|
| 62 | """ |
---|
| 63 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
| 64 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 65 | form_fields['next_kin_address'].custom_widget = BytesDisplayWidget |
---|
| 66 | form_fields['corr_address'].custom_widget = BytesDisplayWidget |
---|
| 67 | form_fields['sponsor_address'].custom_widget = BytesDisplayWidget |
---|
| 68 | form_fields[ |
---|
| 69 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 70 | |
---|
| 71 | class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage): |
---|
| 72 | """ Page to edit personal data |
---|
| 73 | """ |
---|
| 74 | form_fields = grok.AutoFields(ICustomStudentPersonalEdit).omit( |
---|
| 75 | 'personal_updated') |
---|
| 76 | |
---|
| 77 | class CustomStudentPersonalManageFormPage(NigeriaStudentPersonalManageFormPage): |
---|
| 78 | """ Page to edit personal data |
---|
| 79 | """ |
---|
| 80 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
| 81 | form_fields['personal_updated'].for_display = True |
---|
| 82 | form_fields[ |
---|
| 83 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 84 | |
---|
[8911] | 85 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
| 86 | """ Page to view an online payment ticket |
---|
| 87 | """ |
---|
| 88 | grok.context(ICustomStudentOnlinePayment) |
---|
[9789] | 89 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9992] | 90 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 91 | form_fields[ |
---|
| 92 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 93 | form_fields[ |
---|
| 94 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 95 | |
---|
| 96 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
| 97 | """ Page to add an online payment ticket |
---|
| 98 | """ |
---|
| 99 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
| 100 | 'p_category') |
---|
| 101 | |
---|
| 102 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
| 103 | """Deliver a PDF slip of the context. |
---|
| 104 | """ |
---|
| 105 | grok.context(ICustomStudentOnlinePayment) |
---|
[9789] | 106 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9992] | 107 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 108 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9156] | 109 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 110 | |
---|
| 111 | class CustomStartClearancePage(StartClearancePage): |
---|
| 112 | |
---|
[9955] | 113 | with_ac = False |
---|
[9156] | 114 | |
---|
[9181] | 115 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
| 116 | """ View to edit student clearance data by student |
---|
| 117 | """ |
---|
| 118 | |
---|
| 119 | def dataNotComplete(self): |
---|
[9190] | 120 | return False |
---|
| 121 | |
---|
| 122 | class BedTicketAddPage(BedTicketAddPage): |
---|
| 123 | """ Page to add an online payment ticket |
---|
| 124 | """ |
---|
| 125 | buttonname = _('Create bed ticket') |
---|
| 126 | notice = '' |
---|
[10691] | 127 | with_ac = False |
---|
| 128 | |
---|
| 129 | class CustomExportPDFAdmissionSlipPage(ExportPDFAdmissionSlipPage): |
---|
| 130 | """Deliver a PDF Admission slip. |
---|
| 131 | """ |
---|
| 132 | grok.context(ICustomStudent) |
---|
| 133 | |
---|
| 134 | omit_fields = ('date_of_birth',) |
---|
| 135 | |
---|
| 136 | form_fields = grok.AutoFields(ICustomStudent).select('student_id', 'reg_number') |
---|
| 137 | |
---|
| 138 | def render(self): |
---|
| 139 | if self.context.state in (CREATED, ADMITTED, |
---|
| 140 | CLEARANCE, REQUESTED, CLEARED): |
---|
| 141 | self.flash('Not allowed.') |
---|
| 142 | self.redirect(self.url(self.context)) |
---|
| 143 | return |
---|
| 144 | students_utils = getUtility(IStudentsUtils) |
---|
| 145 | return students_utils.renderPDFAdmissionLetter(self, |
---|
| 146 | self.context.student, omit_fields=self.omit_fields) |
---|
| 147 | |
---|
| 148 | class ExportPDFAdmissionNotificationPage(UtilityView, grok.View): |
---|
| 149 | """Deliver a PDF Admission nostification slip. |
---|
| 150 | """ |
---|
| 151 | grok.context(ICustomStudent) |
---|
| 152 | grok.name('admission_notification.pdf') |
---|
| 153 | grok.require('waeup.viewStudent') |
---|
| 154 | prefix = 'form' |
---|
| 155 | label = 'Notification of Provisional Admission' |
---|
| 156 | |
---|
| 157 | omit_fields = ('date_of_birth',) |
---|
| 158 | |
---|
| 159 | form_fields = grok.AutoFields(ICustomStudent).select( |
---|
| 160 | 'student_id', 'reg_number', 'sex', 'lga') |
---|
| 161 | |
---|
| 162 | def render(self): |
---|
| 163 | if self.context.state not in (ADMITTED, CLEARANCE, REQUESTED, CLEARED): |
---|
| 164 | self.flash('Not allowed.') |
---|
| 165 | self.redirect(self.url(self.context)) |
---|
| 166 | return |
---|
| 167 | students_utils = getUtility(IStudentsUtils) |
---|
| 168 | pre_text = '' |
---|
[10703] | 169 | post_text = post_text_freshers |
---|
[10691] | 170 | return students_utils.renderPDFAdmissionLetter(self, |
---|
| 171 | self.context.student, omit_fields=self.omit_fields, |
---|
| 172 | pre_text=pre_text, post_text=post_text) |
---|
[10692] | 173 | |
---|
| 174 | # copied from waeup.aaue |
---|
| 175 | class CustomExportPDFCourseRegistrationSlipPage( |
---|
| 176 | NigeriaExportPDFCourseRegistrationSlipPage): |
---|
| 177 | """Deliver a PDF slip of the context. |
---|
| 178 | """ |
---|
| 179 | grok.context(ICustomStudentStudyLevel) |
---|
| 180 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
| 181 | 'level_session', 'level_verdict', |
---|
| 182 | 'validated_by', 'validation_date', 'gpa') |
---|
| 183 | |
---|
| 184 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
| 185 | 'phone', 'adm_code', 'sex', 'email', 'date_of_birth', |
---|
| 186 | 'department', 'current_mode') |
---|
| 187 | |
---|
| 188 | @property |
---|
| 189 | def title(self): |
---|
| 190 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 191 | return translate(_('Credits Registered'), 'waeup.kofa', |
---|
| 192 | target_language=portal_language) |
---|
| 193 | |
---|
| 194 | def _signatures(self): |
---|
| 195 | return ( |
---|
| 196 | [('I have selected the course on the advise of my Head of ' |
---|
| 197 | 'Department. <br>', _('Student\'s Signature'), '<br>')], |
---|
| 198 | [('This student has satisfied the department\'s requirements. ' |
---|
| 199 | 'I recommend to approve the course registration. <br>', |
---|
| 200 | _('Head of Department\'s Signature'), '<br>')], |
---|
| 201 | [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')], |
---|
| 202 | [('', _('Director\'s Signature'))] |
---|
| 203 | ) |
---|
| 204 | |
---|
| 205 | def render(self): |
---|
| 206 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 207 | Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language) |
---|
| 208 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
| 209 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
| 210 | Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language) |
---|
| 211 | Score = translate('Score', 'waeup.kofa', target_language=portal_language) |
---|
| 212 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
| 213 | Signature = translate(_('HOD\'s Signature'), 'waeup.kwarapoly', |
---|
| 214 | target_language=portal_language) |
---|
| 215 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 216 | self.request, self.omit_fields) |
---|
| 217 | students_utils = getUtility(IStudentsUtils) |
---|
| 218 | |
---|
| 219 | tabledata = [] |
---|
| 220 | tableheader = [] |
---|
| 221 | contenttitle = [] |
---|
| 222 | for i in range(1,7): |
---|
| 223 | tabledata.append(sorted( |
---|
| 224 | [value for value in self.context.values() if value.semester == i], |
---|
| 225 | key=lambda value: str(value.semester) + value.code)) |
---|
| 226 | tableheader.append([(Code,'code', 2.0), |
---|
| 227 | (Title,'title', 7), |
---|
| 228 | (Cred, 'credits', 1.5), |
---|
| 229 | (Score, 'score', 1.4), |
---|
| 230 | (Grade, 'grade', 1.4), |
---|
| 231 | (Signature, 'dummy', 3), |
---|
| 232 | ]) |
---|
| 233 | if len(self.label.split('\n')) == 3: |
---|
| 234 | topMargin = 1.9 |
---|
| 235 | elif len(self.label.split('\n')) == 2: |
---|
| 236 | topMargin = 1.7 |
---|
| 237 | else: |
---|
| 238 | topMargin = 1.5 |
---|
| 239 | return students_utils.renderPDF( |
---|
| 240 | self, 'course_registration_slip.pdf', |
---|
| 241 | self.context.student, studentview, |
---|
| 242 | tableheader=tableheader, |
---|
| 243 | tabledata=tabledata, |
---|
| 244 | signatures=self._signatures(), |
---|
| 245 | topMargin=topMargin, |
---|
| 246 | omit_fields=self.omit_fields |
---|
[10695] | 247 | ) |
---|
| 248 | |
---|
| 249 | class ExportPDFRegistrationSlipPage(grok.View): |
---|
| 250 | """Deliver a PDF slip of the context. |
---|
| 251 | """ |
---|
| 252 | grok.context(ICustomStudent) |
---|
[10705] | 253 | grok.name('registration_slip.pdf') |
---|
[10695] | 254 | grok.require('waeup.viewStudent') |
---|
| 255 | prefix = 'form' |
---|
| 256 | omit_fields = ( |
---|
| 257 | 'suspended', 'phone', |
---|
[10705] | 258 | 'adm_code', 'suspended_comment', 'email', |
---|
| 259 | 'current_mode', 'matric_number', 'date_of_birth') |
---|
| 260 | title = 'Clearance and Personal Data' |
---|
| 261 | label = 'Profile Registration Slip' |
---|
[10695] | 262 | |
---|
| 263 | form_fields = grok.AutoFields(ICustomStudent).select( |
---|
[10705] | 264 | 'date_of_birth', 'lga', 'nationality', |
---|
| 265 | 'perm_address', 'corr_address', |
---|
| 266 | 'marit_stat', 'sponsor_name', 'sponsor_address', |
---|
| 267 | ) |
---|
[10695] | 268 | |
---|
| 269 | def render(self): |
---|
| 270 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 271 | self.request, self.omit_fields) |
---|
| 272 | students_utils = getUtility(IStudentsUtils) |
---|
| 273 | return students_utils.renderPDF( |
---|
[10705] | 274 | self, 'registration_slip.pdf', |
---|
[10695] | 275 | self.context.student, studentview, signatures=([_('Bursar')],), |
---|
[10703] | 276 | omit_fields=self.omit_fields, |
---|
| 277 | note=post_text_registration) |
---|
| 278 | |
---|
| 279 | post_text_registration = """<br /><br /><br /><br /> |
---|
| 280 | <strong>IMPORTANTANT NOTICE</strong> |
---|
| 281 | <br /><br /> |
---|
[10711] | 282 | This registration slip must be submitted before attendance of lectures. Note that:<br /><br /> |
---|
| 283 | 1. All fees due must be paid in full.<br /><br /> |
---|
| 284 | 2. All information required must be available on the Registration Form.<br /><br /> |
---|
[10703] | 285 | 3. The Signature of all appropriate Polytechnic Authority must be obtained.<br /><br /> |
---|
[10711] | 286 | 4. The endorsed Registration Form should be returned to the respective Institutes and Administrative Offices.<br /><br /> |
---|
| 287 | 5. No student may change his subject or course of study as shown in the signed Registration Form without clearance from Admissions Office and the Director of the appropriate Institute. |
---|
[10703] | 288 | """ |
---|
| 289 | |
---|
| 290 | post_text_freshers = """ |
---|
| 291 | <strong>INSTRUCTIONS TO FRESHERS</strong> |
---|
| 292 | <br /><br /> |
---|
| 293 | You are hereby offered a provisional admission for the 2013/2014 session subject to the conditions that: |
---|
| 294 | <br /><br /> |
---|
| 295 | 1. The information given in your Application Form is correct.<br /><br /> |
---|
| 296 | 2. The original of your Credentials are presented for scrutiny.<br /><br /> |
---|
| 297 | 3. If at any time the Credentials submitted are found to be false/fake or incorrect, your admission shall be withdrawn.<br /><br /> |
---|
| 298 | 4. The name by which you are admitted and registered shall remain same throughout the duration of your programme.<br /><br /> |
---|
| 299 | 5. You are to fill and submit the Undertaking Form at the point of registration failure which your admission will be forfeited.<br /><br /> |
---|
| 300 | 6. You will dress decently covering your nakedness at all times.<br /><br /> |
---|
| 301 | 7. Payment of school fees will be once and in full and should be by Interswitch to the designated Banks. Failure to pay fees by the mode mentioned above by the closing date means you have declined the offer and your place will be given to another eligible candidate immediately.<br /><br /> |
---|
| 302 | 8. You present a Certificate of medical fitness from the Polytechnic Clinic.<br /><br /> |
---|
| 303 | 9. All indigenes of Kwara State are required to present Certificate of Citizenship.<br /><br /> |
---|
| 304 | 10. The Polytechnic reserves the right to withdraw your admission at any stage, if you are found to be a cultist or an expelled individual from any tertiary institution.<br /><br /> |
---|
| 305 | 11. You are prepared to take up accommodation provided on the campuses by the authority.<br /><br /> |
---|
| 306 | 12. There will be no refund of school fees once paid.<br /><br /> |
---|
| 307 | 13. If you accept this offer with above stated conditions, please make a photocopy of this document and return it to the Admission Office immediately.<br /><br /> |
---|
| 308 | 14. You possess the entry requirement for the programme you are admitted into before making payment of school fees and registration.<br /><br /> |
---|
| 309 | """ |
---|