[8862] | 1 | ## $Id: browser.py 13620 2016-01-16 15:01:09Z 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.formlib.textwidgets import BytesDisplayWidget |
---|
| 20 | from zope.component import getUtility |
---|
| 21 | from zope.i18n import translate |
---|
[13620] | 22 | from datetime import datetime |
---|
[8862] | 23 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
[13620] | 24 | from waeup.kofa.interfaces import IExtFileStore, IObjectHistory |
---|
| 25 | from waeup.kofa.browser.layout import action, UtilityView |
---|
| 26 | from waeup.kofa.utils.helpers import get_current_principal |
---|
[8862] | 27 | from waeup.kofa.students.browser import ( |
---|
[8904] | 28 | StudentPersonalDisplayFormPage, StudentPersonalManageFormPage, |
---|
[8862] | 29 | StudentClearanceManageFormPage, StudentClearanceEditFormPage, |
---|
[13058] | 30 | StudentClearanceDisplayFormPage, OnlinePaymentFakeApproveView, |
---|
| 31 | ExportPDFClearanceSlip, StudentBaseManageFormPage, |
---|
[8966] | 32 | StudentBaseDisplayFormPage, |
---|
[8862] | 33 | StudentBaseEditFormPage, StudentPersonalEditFormPage, |
---|
| 34 | OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage, |
---|
[13058] | 35 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlip, |
---|
| 36 | ExportPDFCourseRegistrationSlip, |
---|
| 37 | ExportPDFBedTicketSlip, |
---|
[13458] | 38 | StudentFilesUploadPage, emit_lock_message, |
---|
| 39 | AccommodationManageFormPage) |
---|
[10707] | 40 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
[8862] | 41 | from waeup.kofa.students.viewlets import ( |
---|
| 42 | PaymentReceiptActionButton, StudentPassportActionButton) |
---|
| 43 | from kofacustom.nigeria.students.interfaces import ( |
---|
[8863] | 44 | INigeriaStudentBase, INigeriaStudent, INigeriaStudentPersonal, |
---|
[9564] | 45 | INigeriaStudentPersonalEdit, |
---|
[8863] | 46 | INigeriaUGStudentClearance,INigeriaPGStudentClearance, |
---|
[8904] | 47 | INigeriaStudentOnlinePayment |
---|
[8862] | 48 | ) |
---|
| 49 | from waeup.kofa.students.workflow import ADMITTED |
---|
| 50 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
| 51 | |
---|
[8863] | 52 | class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
[8862] | 53 | """A breadcrumb for payments. |
---|
| 54 | """ |
---|
[8863] | 55 | grok.context(INigeriaStudentOnlinePayment) |
---|
[8862] | 56 | |
---|
| 57 | class PaymentReceiptActionButton(PaymentReceiptActionButton): |
---|
| 58 | grok.order(4) |
---|
[8863] | 59 | grok.context(INigeriaStudentOnlinePayment) |
---|
[8862] | 60 | |
---|
[8966] | 61 | class NigeriaStudentBaseDisplayFormPage(StudentBaseDisplayFormPage): |
---|
| 62 | """ Page to display student base data |
---|
| 63 | """ |
---|
[9704] | 64 | form_fields = grok.AutoFields(INigeriaStudentBase).omit( |
---|
| 65 | 'password', 'suspended', 'suspended_comment') |
---|
[13620] | 66 | form_fields[ |
---|
| 67 | 'financial_clearance_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[8966] | 68 | |
---|
[8863] | 69 | class NigeriaStudentBaseManageFormPage(StudentBaseManageFormPage): |
---|
[8862] | 70 | """ View to manage student base data |
---|
| 71 | """ |
---|
[9144] | 72 | form_fields = grok.AutoFields(INigeriaStudentBase).omit( |
---|
[13620] | 73 | 'student_id', 'adm_code', 'suspended', |
---|
| 74 | 'financially_cleared_by', 'financial_clearance_date') |
---|
[8862] | 75 | |
---|
[8863] | 76 | class NigeriaStudentBaseEditFormPage(StudentBaseEditFormPage): |
---|
[8862] | 77 | """ View to edit student base data |
---|
| 78 | """ |
---|
[8863] | 79 | form_fields = grok.AutoFields(INigeriaStudentBase).select( |
---|
[8862] | 80 | 'email', 'phone') |
---|
| 81 | |
---|
[8863] | 82 | class NigeriaStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage): |
---|
[8862] | 83 | """ Page to display student personal data |
---|
| 84 | """ |
---|
[9562] | 85 | form_fields = grok.AutoFields(INigeriaStudentPersonal) |
---|
[8862] | 86 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
[9053] | 87 | form_fields['next_kin_address'].custom_widget = BytesDisplayWidget |
---|
[9562] | 88 | form_fields[ |
---|
| 89 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[8862] | 90 | |
---|
[8863] | 91 | class NigeriaStudentPersonalEditFormPage(StudentPersonalEditFormPage): |
---|
[8862] | 92 | """ Page to edit personal data |
---|
| 93 | """ |
---|
[9564] | 94 | form_fields = grok.AutoFields(INigeriaStudentPersonalEdit).omit('personal_updated') |
---|
[8862] | 95 | |
---|
[8904] | 96 | class NigeriaStudentPersonalManageFormPage(StudentPersonalManageFormPage): |
---|
| 97 | """ Page to edit personal data |
---|
| 98 | """ |
---|
| 99 | form_fields = grok.AutoFields(INigeriaStudentPersonal) |
---|
[9554] | 100 | form_fields['personal_updated'].for_display = True |
---|
[9572] | 101 | form_fields[ |
---|
| 102 | 'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[8904] | 103 | |
---|
[8863] | 104 | class NigeriaStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage): |
---|
[8862] | 105 | """ Page to display student clearance data |
---|
| 106 | """ |
---|
| 107 | |
---|
| 108 | @property |
---|
| 109 | def form_fields(self): |
---|
[9248] | 110 | if self.context.is_postgrad: |
---|
[8862] | 111 | form_fields = grok.AutoFields( |
---|
[8863] | 112 | INigeriaPGStudentClearance).omit('clearance_locked') |
---|
[8862] | 113 | else: |
---|
| 114 | form_fields = grok.AutoFields( |
---|
[8863] | 115 | INigeriaUGStudentClearance).omit('clearance_locked') |
---|
[9535] | 116 | if not getattr(self.context, 'officer_comment'): |
---|
| 117 | form_fields = form_fields.omit('officer_comment') |
---|
| 118 | else: |
---|
| 119 | form_fields['officer_comment'].custom_widget = BytesDisplayWidget |
---|
[8862] | 120 | return form_fields |
---|
| 121 | |
---|
[13058] | 122 | class NigeriaExportPDFClearanceSlip(ExportPDFClearanceSlip): |
---|
[8862] | 123 | """Deliver a PDF slip of the context. |
---|
| 124 | """ |
---|
[9704] | 125 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
[11536] | 126 | 'phone', 'adm_code', 'email', 'date_of_birth', 'current_level') |
---|
[8862] | 127 | |
---|
| 128 | @property |
---|
| 129 | def form_fields(self): |
---|
[9248] | 130 | if self.context.is_postgrad: |
---|
[8862] | 131 | form_fields = grok.AutoFields( |
---|
[8863] | 132 | INigeriaPGStudentClearance).omit('clearance_locked') |
---|
[8862] | 133 | else: |
---|
| 134 | form_fields = grok.AutoFields( |
---|
[8863] | 135 | INigeriaUGStudentClearance).omit('clearance_locked') |
---|
[9535] | 136 | if not getattr(self.context, 'officer_comment'): |
---|
| 137 | form_fields = form_fields.omit('officer_comment') |
---|
[8862] | 138 | return form_fields |
---|
| 139 | |
---|
[8863] | 140 | class NigeriaStudentClearanceManageFormPage(StudentClearanceManageFormPage): |
---|
[8862] | 141 | """ Page to edit student clearance data |
---|
| 142 | """ |
---|
| 143 | |
---|
| 144 | @property |
---|
| 145 | def form_fields(self): |
---|
[9248] | 146 | if self.context.is_postgrad: |
---|
[9249] | 147 | form_fields = grok.AutoFields( |
---|
| 148 | INigeriaPGStudentClearance).omit('clr_code') |
---|
[8862] | 149 | else: |
---|
[9249] | 150 | form_fields = grok.AutoFields( |
---|
| 151 | INigeriaUGStudentClearance).omit('clr_code') |
---|
[8862] | 152 | return form_fields |
---|
| 153 | |
---|
[8863] | 154 | class NigeriaStudentClearanceEditFormPage(StudentClearanceEditFormPage): |
---|
[8862] | 155 | """ View to edit student clearance data by student |
---|
| 156 | """ |
---|
| 157 | |
---|
| 158 | @property |
---|
| 159 | def form_fields(self): |
---|
[9248] | 160 | if self.context.is_postgrad: |
---|
[8946] | 161 | form_fields = grok.AutoFields(INigeriaPGStudentClearance).omit( |
---|
[12107] | 162 | 'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment', |
---|
[12120] | 163 | 'physical_clearance_date') |
---|
[8862] | 164 | else: |
---|
[8946] | 165 | form_fields = grok.AutoFields(INigeriaUGStudentClearance).omit( |
---|
[12107] | 166 | 'clearance_locked', 'clr_code', 'officer_comment', |
---|
[12120] | 167 | 'physical_clearance_date') |
---|
[8862] | 168 | return form_fields |
---|
| 169 | |
---|
[13058] | 170 | class NigeriaExportPDFCourseRegistrationSlip(ExportPDFCourseRegistrationSlip): |
---|
[9376] | 171 | """Deliver a PDF slip of the context. |
---|
| 172 | """ |
---|
[9704] | 173 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
[11536] | 174 | 'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'current_level') |
---|
[9376] | 175 | |
---|
[8863] | 176 | class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
[8862] | 177 | """ Page to view an online payment ticket |
---|
| 178 | """ |
---|
[8863] | 179 | grok.context(INigeriaStudentOnlinePayment) |
---|
[9774] | 180 | form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).omit( |
---|
[9985] | 181 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8862] | 182 | form_fields[ |
---|
| 183 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 184 | form_fields[ |
---|
| 185 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 186 | |
---|
[8863] | 187 | class NigeriaOnlinePaymentAddFormPage(OnlinePaymentAddFormPage): |
---|
[8862] | 188 | """ Page to add an online payment ticket |
---|
| 189 | """ |
---|
[8863] | 190 | form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).select( |
---|
[8862] | 191 | 'p_category') |
---|
| 192 | |
---|
[13058] | 193 | class NigeriaOnlinePaymentFakeApproveView(OnlinePaymentFakeApproveView): |
---|
[8862] | 194 | """ Disable payment approval view for students. |
---|
| 195 | |
---|
| 196 | This view is used for browser tests only and |
---|
| 197 | has to be neutralized here! |
---|
| 198 | """ |
---|
| 199 | grok.name('fake_approve') |
---|
| 200 | grok.require('waeup.managePortal') |
---|
| 201 | |
---|
| 202 | def update(self): |
---|
| 203 | return |
---|
| 204 | |
---|
[13058] | 205 | class NigeriaExportPDFPaymentSlip(ExportPDFPaymentSlip): |
---|
[8862] | 206 | """Deliver a PDF slip of the context. |
---|
| 207 | """ |
---|
[8863] | 208 | grok.context(INigeriaStudentOnlinePayment) |
---|
[9774] | 209 | form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).omit( |
---|
[9985] | 210 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8862] | 211 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 212 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9704] | 213 | omit_fields = ('password', 'suspended', 'suspended_comment', 'phone', |
---|
[11536] | 214 | 'adm_code', 'sex', 'email', 'date_of_birth', 'current_level') |
---|
[8862] | 215 | |
---|
[13458] | 216 | class NigeriaAccommodationManageFormPage(AccommodationManageFormPage): |
---|
| 217 | """ Page to manage bed tickets. |
---|
| 218 | This manage form page is for both students and students officers. |
---|
| 219 | """ |
---|
| 220 | with_hostel_selection = False |
---|
| 221 | |
---|
[13058] | 222 | class NigeriaExportPDFBedTicketSlip(ExportPDFBedTicketSlip): |
---|
[9376] | 223 | """Deliver a PDF slip of the context. |
---|
| 224 | """ |
---|
[9704] | 225 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
[11536] | 226 | 'phone', 'adm_code', 'email', 'date_of_birth', 'current_level') |
---|
[9376] | 227 | |
---|
[8862] | 228 | class StudentPassportActionButton(StudentPassportActionButton): |
---|
| 229 | |
---|
| 230 | @property |
---|
| 231 | def target_url(self): |
---|
[10707] | 232 | # Passport pictures must not be editable if application slip |
---|
| 233 | # exists. |
---|
[8862] | 234 | slip = getUtility(IExtFileStore).getFileByContext( |
---|
| 235 | self.context, 'application_slip') |
---|
[13130] | 236 | PORTRAIT_CHANGE_STATES = getUtility(IStudentsUtils).PORTRAIT_CHANGE_STATES |
---|
| 237 | if self.context.state not in PORTRAIT_CHANGE_STATES or slip is not None: |
---|
[8862] | 238 | return '' |
---|
| 239 | return self.view.url(self.view.context, self.target) |
---|
| 240 | |
---|
[8863] | 241 | class NigeriaStudentFilesUploadPage(StudentFilesUploadPage): |
---|
[8862] | 242 | """ View to upload passport picture. |
---|
| 243 | |
---|
| 244 | Students are not allowed to change the picture if they |
---|
| 245 | passed the regular Kofa application. |
---|
| 246 | """ |
---|
| 247 | |
---|
| 248 | def update(self): |
---|
[10707] | 249 | # Passport pictures must not be editable if application slip |
---|
| 250 | # exists. |
---|
[8862] | 251 | slip = getUtility(IExtFileStore).getFileByContext( |
---|
| 252 | self.context, 'application_slip') |
---|
[13130] | 253 | PORTRAIT_CHANGE_STATES = getUtility(IStudentsUtils).PORTRAIT_CHANGE_STATES |
---|
| 254 | if self.context.state not in PORTRAIT_CHANGE_STATES or slip is not None: |
---|
[8862] | 255 | emit_lock_message(self) |
---|
| 256 | return |
---|
| 257 | super(StudentFilesUploadPage, self).update() |
---|
[13620] | 258 | return |
---|
| 259 | |
---|
| 260 | class ClearStudentFinancially(UtilityView, grok.View): |
---|
| 261 | """ Clear student financially by bursary officer |
---|
| 262 | """ |
---|
| 263 | grok.context(INigeriaStudent) |
---|
| 264 | grok.name('clear_financially') |
---|
| 265 | grok.require('waeup.clearStudentFinancially') |
---|
| 266 | |
---|
| 267 | def update(self): |
---|
| 268 | if self.context.financially_cleared_by: |
---|
| 269 | self.flash(_('This student has already been financially cleared.'), |
---|
| 270 | type="danger") |
---|
| 271 | self.redirect(self.url(self.context)) |
---|
| 272 | return |
---|
| 273 | user = get_current_principal() |
---|
| 274 | if user is None: |
---|
| 275 | usertitle = 'system' |
---|
| 276 | else: |
---|
| 277 | usertitle = getattr(user, 'public_name', None) |
---|
| 278 | if not usertitle: |
---|
| 279 | usertitle = user.title |
---|
| 280 | self.context.financially_cleared_by = usertitle |
---|
| 281 | self.context.financial_clearance_date = datetime.utcnow() |
---|
| 282 | self.context.writeLogMessage(self,'financially cleared') |
---|
| 283 | history = IObjectHistory(self.context) |
---|
| 284 | history.addMessage('Financially cleared') |
---|
| 285 | self.flash(_('Student has been financially cleared.')) |
---|
| 286 | self.redirect(self.url(self.context)) |
---|
| 287 | return |
---|
| 288 | |
---|
| 289 | def render(self): |
---|
| 290 | return |
---|
| 291 | |
---|
| 292 | class WithdrawFinancialClearance(UtilityView, grok.View): |
---|
| 293 | """ Withdraw financial clearance by bursary officer |
---|
| 294 | """ |
---|
| 295 | grok.context(INigeriaStudent) |
---|
| 296 | grok.name('withdraw_financial_clearance') |
---|
| 297 | grok.require('waeup.clearStudentFinancially') |
---|
| 298 | |
---|
| 299 | def update(self): |
---|
| 300 | if not self.context.financially_cleared_by: |
---|
| 301 | self.flash(_('This student has not yet been financially cleared.'), |
---|
| 302 | type="danger") |
---|
| 303 | self.redirect(self.url(self.context)) |
---|
| 304 | return |
---|
| 305 | self.context.financially_cleared_by = None |
---|
| 306 | self.context.financial_clearance_date = None |
---|
| 307 | self.context.writeLogMessage(self,'financial clearance withdrawn') |
---|
| 308 | history = IObjectHistory(self.context) |
---|
| 309 | history.addMessage('Financial clearance withdrawn') |
---|
| 310 | self.flash(_('Financial clearance withdrawn.')) |
---|
| 311 | self.redirect(self.url(self.context)) |
---|
| 312 | return |
---|
| 313 | |
---|
| 314 | def render(self): |
---|
[8862] | 315 | return |
---|