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