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