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