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