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