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