[8911] | 1 | ## $Id: browser.py 12122 2014-12-03 06:43:26Z 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 |
---|
[9210] | 20 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
[9380] | 21 | from zope.component import getUtility |
---|
[9281] | 22 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
[11069] | 23 | from waeup.kofa.interfaces import ( |
---|
| 24 | REQUESTED, IExtFileStore, IKofaUtils, IObjectHistory) |
---|
[8911] | 25 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
[12121] | 26 | from waeup.kofa.browser.layout import action, KofaEditFormPage, UtilityView |
---|
[9205] | 27 | from waeup.kofa.students.browser import ( |
---|
[9686] | 28 | StudyLevelEditFormPage, StudyLevelDisplayFormPage, |
---|
| 29 | StudentBasePDFFormPage, ExportPDFCourseRegistrationSlipPage, |
---|
[10025] | 30 | CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage, |
---|
[11069] | 31 | msave, emit_lock_message, |
---|
| 32 | StudentActivatePage, StudentDeactivatePage) |
---|
[9686] | 33 | from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket |
---|
[9251] | 34 | from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS |
---|
[8911] | 35 | from kofacustom.nigeria.students.browser import ( |
---|
| 36 | NigeriaOnlinePaymentDisplayFormPage, |
---|
[9251] | 37 | NigeriaStudentBaseManageFormPage, |
---|
[9380] | 38 | NigeriaStudentClearanceEditFormPage, |
---|
[8911] | 39 | NigeriaOnlinePaymentAddFormPage, |
---|
[9281] | 40 | NigeriaExportPDFPaymentSlipPage, |
---|
[9551] | 41 | NigeriaExportPDFClearanceSlipPage, |
---|
[9281] | 42 | ) |
---|
[8911] | 43 | |
---|
[9210] | 44 | from waeup.uniben.students.interfaces import ( |
---|
[12121] | 45 | ICustomStudent, |
---|
[9921] | 46 | ICustomStudentOnlinePayment, ICustomStudentStudyCourse, |
---|
[11552] | 47 | ICustomStudentStudyLevel, |
---|
| 48 | ICustomUGStudentClearance, |
---|
| 49 | ICustomPGStudentClearance) |
---|
[9210] | 50 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[8911] | 51 | |
---|
| 52 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
| 53 | """ Page to view an online payment ticket |
---|
| 54 | """ |
---|
| 55 | grok.context(ICustomStudentOnlinePayment) |
---|
[9775] | 56 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9993] | 57 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 58 | form_fields[ |
---|
| 59 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 60 | form_fields[ |
---|
| 61 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 62 | |
---|
[9380] | 63 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
| 64 | """ View to edit student clearance data by student |
---|
| 65 | """ |
---|
| 66 | |
---|
[11552] | 67 | @property |
---|
| 68 | def form_fields(self): |
---|
| 69 | if self.context.is_postgrad: |
---|
| 70 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit( |
---|
| 71 | 'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment') |
---|
| 72 | else: |
---|
| 73 | form_fields = grok.AutoFields(ICustomUGStudentClearance).omit( |
---|
| 74 | 'clearance_locked', 'clr_code', 'officer_comment') |
---|
| 75 | form_fields['date_of_birth'].for_display = True |
---|
| 76 | form_fields['nationality'].for_display = True |
---|
| 77 | form_fields['lga'].for_display = True |
---|
| 78 | return form_fields |
---|
| 79 | |
---|
[9380] | 80 | def dataNotComplete(self): |
---|
| 81 | store = getUtility(IExtFileStore) |
---|
| 82 | if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'): |
---|
| 83 | return _('No birth certificate uploaded.') |
---|
| 84 | if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): |
---|
| 85 | return _('No guarantor/referee letter uploaded.') |
---|
| 86 | if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): |
---|
| 87 | return _('No acceptance letter uploaded.') |
---|
| 88 | if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): |
---|
| 89 | return _('No first sitting result uploaded.') |
---|
[9395] | 90 | #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'): |
---|
| 91 | # return _('No second sitting result uploaded.') |
---|
[9380] | 92 | if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'): |
---|
[9848] | 93 | return _('No affidavit of non-membership of secret cults uploaded.') |
---|
[9380] | 94 | return False |
---|
| 95 | |
---|
[8911] | 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) |
---|
[9775] | 106 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9993] | 107 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 108 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9205] | 109 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 110 | |
---|
| 111 | |
---|
[9551] | 112 | class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage): |
---|
| 113 | """Deliver a PDF slip of the context. |
---|
| 114 | """ |
---|
| 115 | |
---|
[11537] | 116 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
| 117 | 'phone', 'adm_code', 'email', 'date_of_birth') |
---|
| 118 | |
---|
[9551] | 119 | def render(self): |
---|
| 120 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 121 | self.request, self.omit_fields) |
---|
| 122 | students_utils = getUtility(IStudentsUtils) |
---|
| 123 | return students_utils.renderPDF( |
---|
| 124 | self, 'clearance_slip.pdf', |
---|
| 125 | self.context.student, studentview, signatures=self._signatures(), |
---|
[10271] | 126 | sigs_in_footer=self._sigsInFooter(), show_scans=False, |
---|
| 127 | omit_fields=self.omit_fields) |
---|
[9551] | 128 | |
---|
[12121] | 129 | |
---|
| 130 | class ExportClearanceInvitationSlipPage(UtilityView, grok.View): |
---|
| 131 | """Deliver an invitation letter to physical clearance. |
---|
| 132 | |
---|
| 133 | This form page is available only in Uniben. |
---|
| 134 | """ |
---|
| 135 | grok.context(ICustomStudent) |
---|
| 136 | grok.name('clearance_invitation_slip.pdf') |
---|
| 137 | grok.require('waeup.viewStudent') |
---|
| 138 | prefix = 'form' |
---|
| 139 | |
---|
| 140 | label = u'Invitation Letter to Physical Clearance' |
---|
| 141 | |
---|
| 142 | omit_fields = ( |
---|
| 143 | 'suspended', 'phone', 'email', |
---|
| 144 | 'adm_code', 'suspended_comment', |
---|
| 145 | 'date_of_birth', 'current_level', |
---|
| 146 | 'faculty', 'department', 'current_mode', |
---|
| 147 | 'entry_session', 'matric_number', 'sex') |
---|
| 148 | |
---|
| 149 | form_fields = [] |
---|
| 150 | |
---|
| 151 | @property |
---|
| 152 | def note(self): |
---|
| 153 | if self.context.physical_clearance_date: |
---|
| 154 | return """ |
---|
| 155 | <br /><br /><br /><br /><font size="12"> |
---|
| 156 | You are kindly invited to physical clearance on %s |
---|
| 157 | |
---|
| 158 | <br /><br /> |
---|
| 159 | Clearance Officer<br /> |
---|
| 160 | </font> |
---|
| 161 | |
---|
| 162 | """ % self.context.physical_clearance_date |
---|
| 163 | return |
---|
| 164 | |
---|
[12122] | 165 | |
---|
| 166 | def update(self): |
---|
| 167 | if self.context.student.state != REQUESTED \ |
---|
| 168 | or not self.context.student.physical_clearance_date: |
---|
| 169 | self.flash(_('Forbidden'), type="warning") |
---|
| 170 | self.redirect(self.url(self.context)) |
---|
| 171 | |
---|
[12121] | 172 | def render(self): |
---|
| 173 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 174 | self.request, self.omit_fields) |
---|
| 175 | students_utils = getUtility(IStudentsUtils) |
---|
| 176 | return students_utils.renderPDF( |
---|
| 177 | self, 'clearance_invitation_slip', |
---|
| 178 | self.context.student, studentview, |
---|
| 179 | omit_fields=self.omit_fields, |
---|
| 180 | note=self.note) |
---|
| 181 | |
---|
[9210] | 182 | class StudyCourseCOEditFormPage(KofaEditFormPage): |
---|
[9281] | 183 | """ Page to edit the student study course data by clearance officers. |
---|
[9210] | 184 | |
---|
| 185 | This form page is available only in Uniben. |
---|
| 186 | """ |
---|
| 187 | grok.context(ICustomStudentStudyCourse) |
---|
| 188 | grok.name('edit_level') |
---|
| 189 | grok.require('waeup.clearStudent') |
---|
| 190 | label = _('Edit current level') |
---|
| 191 | pnav = 4 |
---|
| 192 | form_fields = grok.AutoFields( |
---|
| 193 | ICustomStudentStudyCourse).select('current_level') |
---|
| 194 | |
---|
| 195 | def update(self): |
---|
| 196 | if not (self.context.is_current and |
---|
| 197 | self.context.student.state == REQUESTED): |
---|
| 198 | emit_lock_message(self) |
---|
| 199 | return |
---|
| 200 | super(StudyCourseCOEditFormPage, self).update() |
---|
| 201 | return |
---|
| 202 | |
---|
| 203 | @action(_('Save'), style='primary') |
---|
| 204 | def save(self, **data): |
---|
| 205 | try: |
---|
| 206 | msave(self, **data) |
---|
| 207 | except ConstraintNotSatisfied: |
---|
| 208 | # The selected level might not exist in certificate |
---|
| 209 | self.flash(_('Current level not available for certificate.')) |
---|
| 210 | return |
---|
| 211 | #notify(grok.ObjectModifiedEvent(self.context.__parent__)) |
---|
[9281] | 212 | return |
---|
| 213 | |
---|
| 214 | class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): |
---|
| 215 | """ Page to edit the student study level data by students. |
---|
| 216 | |
---|
| 217 | """ |
---|
[9686] | 218 | grok.template('studyleveleditpage') |
---|
[9281] | 219 | |
---|
[9686] | 220 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
| 221 | """ Page to display student study levels |
---|
| 222 | """ |
---|
| 223 | grok.template('studylevelpage') |
---|
| 224 | |
---|
| 225 | class CustomExportPDFCourseRegistrationSlipPage( |
---|
| 226 | ExportPDFCourseRegistrationSlipPage): |
---|
| 227 | """Deliver a PDF slip of the context. |
---|
| 228 | """ |
---|
| 229 | |
---|
[9921] | 230 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
[10481] | 231 | 'level_verdict', 'gpa') |
---|
[9921] | 232 | |
---|
[10441] | 233 | @property |
---|
| 234 | def tabletitle(self): |
---|
| 235 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 236 | tabletitle = [] |
---|
| 237 | tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa', |
---|
| 238 | target_language=portal_language)) |
---|
| 239 | tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa', |
---|
| 240 | target_language=portal_language)) |
---|
| 241 | tabletitle.append(translate(_('Level Courses'), 'waeup.kofa', |
---|
| 242 | target_language=portal_language)) |
---|
| 243 | tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa', |
---|
| 244 | target_language=portal_language)) |
---|
| 245 | tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa', |
---|
| 246 | target_language=portal_language)) |
---|
| 247 | tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa', |
---|
| 248 | target_language=portal_language)) |
---|
| 249 | return tabletitle |
---|
| 250 | |
---|
[9686] | 251 | def render(self): |
---|
| 252 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9909] | 253 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
| 254 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
| 255 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
| 256 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
| 257 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
[9686] | 258 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 259 | self.request, self.omit_fields) |
---|
| 260 | students_utils = getUtility(IStudentsUtils) |
---|
[10441] | 261 | |
---|
| 262 | tabledata = [] |
---|
| 263 | tableheader = [] |
---|
| 264 | contenttitle = [] |
---|
| 265 | for i in range(1,7): |
---|
| 266 | tabledata.append(sorted( |
---|
| 267 | [value for value in self.context.values() if value.semester == i], |
---|
| 268 | key=lambda value: str(value.semester) + value.code)) |
---|
| 269 | tableheader.append([(Code,'code', 2.5), |
---|
| 270 | (Title,'title', 5), |
---|
| 271 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
| 272 | (Cred, 'credits', 1.5), |
---|
| 273 | ]) |
---|
[9686] | 274 | return students_utils.renderPDF( |
---|
| 275 | self, 'course_registration_slip.pdf', |
---|
| 276 | self.context.student, studentview, |
---|
[10441] | 277 | tableheader=tableheader, |
---|
| 278 | tabledata=tabledata, |
---|
[10271] | 279 | omit_fields=self.omit_fields |
---|
[9908] | 280 | ) |
---|
[9848] | 281 | |
---|
| 282 | class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage): |
---|
| 283 | """Deliver a PDF slip of the context. |
---|
| 284 | """ |
---|
| 285 | |
---|
| 286 | grok.name('course_result_slip.pdf') |
---|
| 287 | |
---|
| 288 | @property |
---|
[10441] | 289 | def tabletitle(self): |
---|
| 290 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 291 | tabletitle = [] |
---|
| 292 | tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa', |
---|
| 293 | target_language=portal_language)) |
---|
| 294 | tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa', |
---|
| 295 | target_language=portal_language)) |
---|
| 296 | tabletitle.append(translate(_('Level Courses'), 'waeup.kofa', |
---|
| 297 | target_language=portal_language)) |
---|
| 298 | tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa', |
---|
| 299 | target_language=portal_language)) |
---|
| 300 | tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa', |
---|
| 301 | target_language=portal_language)) |
---|
| 302 | tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa', |
---|
| 303 | target_language=portal_language)) |
---|
| 304 | return tabletitle |
---|
| 305 | |
---|
| 306 | @property |
---|
[9848] | 307 | def label(self): |
---|
| 308 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 309 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
| 310 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
| 311 | target_language=lang) |
---|
| 312 | return translate(_('Course Result Slip'), |
---|
| 313 | 'waeup.uniben', target_language=portal_language) \ |
---|
| 314 | + ' %s' % level_title |
---|
| 315 | |
---|
| 316 | def render(self): |
---|
| 317 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9909] | 318 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
| 319 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
| 320 | Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) |
---|
| 321 | Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) |
---|
| 322 | Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) |
---|
| 323 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
[9848] | 324 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 325 | self.request, self.omit_fields) |
---|
| 326 | students_utils = getUtility(IStudentsUtils) |
---|
[10441] | 327 | |
---|
| 328 | tabledata = [] |
---|
| 329 | tableheader = [] |
---|
| 330 | contenttitle = [] |
---|
| 331 | for i in range(1,7): |
---|
| 332 | tabledata.append(sorted( |
---|
| 333 | [value for value in self.context.values() if value.semester == i], |
---|
| 334 | key=lambda value: str(value.semester) + value.code)) |
---|
| 335 | tableheader.append([(Code,'code', 2.5), |
---|
| 336 | (Title,'title', 5), |
---|
| 337 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
| 338 | (Cred, 'credits', 1.5), |
---|
| 339 | (Grade, 'grade', 1.5), |
---|
| 340 | ]) |
---|
[9908] | 341 | return students_utils.renderPDF( |
---|
| 342 | self, 'course_registration_slip.pdf', |
---|
| 343 | self.context.student, studentview, |
---|
[10441] | 344 | tableheader=tableheader, |
---|
| 345 | tabledata=tabledata, |
---|
[10271] | 346 | omit_fields=self.omit_fields |
---|
[9908] | 347 | ) |
---|
[9686] | 348 | |
---|
| 349 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
| 350 | """ Page to display course tickets |
---|
| 351 | """ |
---|
| 352 | form_fields = grok.AutoFields(ICourseTicket).omit('score') |
---|
[11069] | 353 | |
---|
| 354 | class CustomStudentActivatePage(StudentActivatePage): |
---|
| 355 | """ Activate student account |
---|
| 356 | """ |
---|
| 357 | |
---|
| 358 | def update(self): |
---|
| 359 | self.context.suspended = False |
---|
| 360 | self.context.writeLogMessage(self, 'account activated') |
---|
| 361 | history = IObjectHistory(self.context) |
---|
| 362 | history.addMessage('Student account activated', user='undisclosed') |
---|
| 363 | self.flash(_('Student account has been activated.')) |
---|
| 364 | self.redirect(self.url(self.context)) |
---|
| 365 | return |
---|
| 366 | |
---|
| 367 | class CustomStudentDeactivatePage(StudentDeactivatePage): |
---|
| 368 | """ Deactivate student account |
---|
| 369 | """ |
---|
| 370 | def update(self): |
---|
| 371 | self.context.suspended = True |
---|
| 372 | self.context.writeLogMessage(self, 'account deactivated') |
---|
| 373 | history = IObjectHistory(self.context) |
---|
| 374 | history.addMessage('Student account deactivated', user='undisclosed') |
---|
| 375 | self.flash(_('Student account has been deactivated.')) |
---|
| 376 | self.redirect(self.url(self.context)) |
---|
| 377 | return |
---|