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