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