[7505] | 1 | ## $Id: browser.py 8722 2012-06-14 08:07:41Z 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 |
---|
[8137] | 20 | from zope.component import getUtility |
---|
[8259] | 21 | from zope.i18n import translate |
---|
[8247] | 22 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
[8137] | 23 | from waeup.kofa.interfaces import IExtFileStore |
---|
[8247] | 24 | from waeup.kofa.browser.layout import action |
---|
[7822] | 25 | from waeup.kofa.students.browser import ( |
---|
[8129] | 26 | StudentPersonalDisplayFormPage, |
---|
[7525] | 27 | StudentClearanceManageFormPage, StudentClearanceEditFormPage, |
---|
[8421] | 28 | StudentClearanceDisplayFormPage, OnlinePaymentFakeApprovePage, |
---|
[8076] | 29 | ExportPDFClearanceSlipPage, StudentBaseManageFormPage, |
---|
[8247] | 30 | StudentBaseEditFormPage, StudentPersonalEditFormPage, |
---|
| 31 | OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage, |
---|
[8722] | 32 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
| 33 | StudentFilesUploadPage, emit_lock_message) |
---|
[8259] | 34 | from waeup.kofa.students.viewlets import ( |
---|
[8722] | 35 | PaymentReceiptActionButton, StudentPassportActionButton) |
---|
[8460] | 36 | from waeup.fceokene.students.interfaces import ( |
---|
[8204] | 37 | ICustomStudentBase, ICustomStudent, ICustomStudentPersonal, |
---|
| 38 | ICustomUGStudentClearance,ICustomPGStudentClearance, |
---|
[8247] | 39 | ICustomStudentOnlinePayment, |
---|
[7879] | 40 | ) |
---|
[8460] | 41 | from waeup.fceokene.interfaces import MessageFactory as _ |
---|
[8722] | 42 | from waeup.kofa.students.workflow import ADMITTED |
---|
[7505] | 43 | |
---|
[8259] | 44 | #class RequestCallbackActionButton(RequestCallbackActionButton): |
---|
| 45 | # """ Display the base package callback button in custom pages. |
---|
| 46 | # """ |
---|
| 47 | # grok.context(ICustomStudentOnlinePayment) |
---|
| 48 | |
---|
| 49 | #class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage): |
---|
| 50 | # """ Activate callback simulation view |
---|
| 51 | # """ |
---|
| 52 | # grok.context(ICustomStudentOnlinePayment) |
---|
| 53 | |
---|
[8247] | 54 | class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
| 55 | """A breadcrumb for payments. |
---|
| 56 | """ |
---|
| 57 | grok.context(ICustomStudentOnlinePayment) |
---|
| 58 | |
---|
[8259] | 59 | class PaymentReceiptActionButton(PaymentReceiptActionButton): |
---|
| 60 | grok.order(4) |
---|
| 61 | grok.context(ICustomStudentOnlinePayment) |
---|
[7998] | 62 | |
---|
[8204] | 63 | class CustomStudentBaseManageFormPage(StudentBaseManageFormPage): |
---|
[8076] | 64 | """ View to manage student base data |
---|
| 65 | """ |
---|
[8204] | 66 | form_fields = grok.AutoFields(ICustomStudentBase).omit('student_id') |
---|
[8076] | 67 | |
---|
[8204] | 68 | class CustomStudentBaseEditFormPage(StudentBaseEditFormPage): |
---|
[8076] | 69 | """ View to edit student base data |
---|
| 70 | """ |
---|
[8204] | 71 | form_fields = grok.AutoFields(ICustomStudentBase).select( |
---|
[8076] | 72 | 'email', 'phone') |
---|
| 73 | |
---|
| 74 | |
---|
[8204] | 75 | class CustomStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage): |
---|
[7505] | 76 | """ Page to display student personal data |
---|
| 77 | """ |
---|
[8204] | 78 | grok.context(ICustomStudent) |
---|
| 79 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
[7505] | 80 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 81 | |
---|
| 82 | |
---|
[8204] | 83 | class CustomStudentPersonalEditFormPage(StudentPersonalEditFormPage): |
---|
[8140] | 84 | """ Page to edit personal data |
---|
| 85 | """ |
---|
[8204] | 86 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
[8140] | 87 | |
---|
| 88 | |
---|
[8204] | 89 | class CustomStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage): |
---|
[7525] | 90 | """ Page to display student clearance data |
---|
| 91 | """ |
---|
[8204] | 92 | grok.context(ICustomStudent) |
---|
[7525] | 93 | |
---|
[7995] | 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'): |
---|
[8204] | 98 | form_fields = grok.AutoFields( |
---|
| 99 | ICustomPGStudentClearance).omit('clearance_locked') |
---|
[7995] | 100 | else: |
---|
[8204] | 101 | form_fields = grok.AutoFields( |
---|
| 102 | ICustomUGStudentClearance).omit('clearance_locked') |
---|
[7995] | 103 | return form_fields |
---|
| 104 | |
---|
[8204] | 105 | class CustomExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage): |
---|
[7995] | 106 | """Deliver a PDF slip of the context. |
---|
| 107 | """ |
---|
[8204] | 108 | grok.context(ICustomStudent) |
---|
[7995] | 109 | |
---|
| 110 | @property |
---|
| 111 | def form_fields(self): |
---|
| 112 | cm = getattr(self.context,'current_mode', None) |
---|
| 113 | if cm is not None and cm.startswith('pg'): |
---|
[8204] | 114 | form_fields = grok.AutoFields( |
---|
| 115 | ICustomPGStudentClearance).omit('clearance_locked') |
---|
[7995] | 116 | else: |
---|
[8204] | 117 | form_fields = grok.AutoFields( |
---|
| 118 | ICustomUGStudentClearance).omit('clearance_locked') |
---|
[7995] | 119 | return form_fields |
---|
| 120 | |
---|
[8204] | 121 | class CustomStudentClearanceManageFormPage(StudentClearanceManageFormPage): |
---|
[7525] | 122 | """ Page to edit student clearance data |
---|
| 123 | """ |
---|
[8204] | 124 | grok.context(ICustomStudent) |
---|
[7525] | 125 | |
---|
[7995] | 126 | @property |
---|
| 127 | def form_fields(self): |
---|
| 128 | cm = getattr(self.context,'current_mode', None) |
---|
| 129 | if cm is not None and cm.startswith('pg'): |
---|
[8204] | 130 | form_fields = grok.AutoFields(ICustomPGStudentClearance) |
---|
[7995] | 131 | else: |
---|
[8204] | 132 | form_fields = grok.AutoFields(ICustomUGStudentClearance) |
---|
[7995] | 133 | return form_fields |
---|
| 134 | |
---|
[8204] | 135 | class CustomStudentClearanceEditFormPage(StudentClearanceEditFormPage): |
---|
[7525] | 136 | """ View to edit student clearance data by student |
---|
| 137 | """ |
---|
[8204] | 138 | grok.context(ICustomStudent) |
---|
[7525] | 139 | |
---|
[7995] | 140 | @property |
---|
| 141 | def form_fields(self): |
---|
| 142 | cm = getattr(self.context,'current_mode', None) |
---|
| 143 | if cm is not None and cm.startswith('pg'): |
---|
[8204] | 144 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit('clearance_locked') |
---|
[7995] | 145 | else: |
---|
[8204] | 146 | form_fields = grok.AutoFields(ICustomUGStudentClearance).omit('clearance_locked') |
---|
[7995] | 147 | return form_fields |
---|
| 148 | |
---|
[8137] | 149 | def dataNotComplete(self): |
---|
| 150 | store = getUtility(IExtFileStore) |
---|
| 151 | if not store.getFileByContext(self.context, attr=u'birth_certicicate.jpg'): |
---|
| 152 | return _('No birth certificate uploaded.') |
---|
| 153 | if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): |
---|
| 154 | return _('No referee letter uploaded.') |
---|
| 155 | if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): |
---|
| 156 | return _('No acceptance letter uploaded.') |
---|
| 157 | if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): |
---|
| 158 | return _('No first sitting result uploaded.') |
---|
| 159 | return False |
---|
| 160 | |
---|
[8247] | 161 | class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
| 162 | """ Page to view an online payment ticket |
---|
| 163 | """ |
---|
| 164 | grok.context(ICustomStudentOnlinePayment) |
---|
| 165 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment) |
---|
| 166 | form_fields[ |
---|
| 167 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 168 | form_fields[ |
---|
| 169 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[8722] | 170 | #grok.template('payment_view') |
---|
[8247] | 171 | |
---|
[8722] | 172 | #@property |
---|
| 173 | #def transaction_code(self): |
---|
| 174 | # tcode = self.context.p_id |
---|
| 175 | # return tcode[len(tcode)-8:len(tcode)] |
---|
[8247] | 176 | |
---|
| 177 | class CustomOnlinePaymentAddFormPage(OnlinePaymentAddFormPage): |
---|
| 178 | """ Page to add an online payment ticket |
---|
| 179 | """ |
---|
| 180 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
| 181 | 'p_category') |
---|
| 182 | |
---|
[8421] | 183 | class CustomOnlinePaymentFakeApprovePage(OnlinePaymentFakeApprovePage): |
---|
| 184 | """ Disable payment approval view for students. |
---|
| 185 | |
---|
| 186 | This view is used for browser tests only and |
---|
| 187 | has to be neutralized here! |
---|
| 188 | """ |
---|
| 189 | |
---|
| 190 | grok.name('fake_approve') |
---|
| 191 | grok.require('waeup.managePortal') |
---|
| 192 | |
---|
| 193 | def update(self): |
---|
| 194 | return |
---|
| 195 | |
---|
[8259] | 196 | class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
| 197 | """Deliver a PDF slip of the context. |
---|
| 198 | """ |
---|
| 199 | grok.context(ICustomStudentOnlinePayment) |
---|
| 200 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment) |
---|
| 201 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 202 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 203 | |
---|
[8722] | 204 | # @property |
---|
| 205 | # def note(self): |
---|
| 206 | # tcode = self.context.p_id |
---|
| 207 | # tcode = tcode[len(tcode)-8:len(tcode)] |
---|
| 208 | # amount = self.context.amount_auth |
---|
| 209 | # note = translate(_( |
---|
| 210 | # u"""<br /><br /><br /> |
---|
| 211 | #The tranzaction code is <strong>${a}</strong>.""", |
---|
| 212 | # mapping = {'a':tcode})) |
---|
| 213 | # return note |
---|
| 214 | |
---|
| 215 | class StudentPassportActionButton(StudentPassportActionButton): |
---|
| 216 | |
---|
[8259] | 217 | @property |
---|
| 218 | def note(self): |
---|
| 219 | tcode = self.context.p_id |
---|
| 220 | tcode = tcode[len(tcode)-8:len(tcode)] |
---|
| 221 | amount = self.context.amount_auth |
---|
| 222 | note = translate(_( |
---|
| 223 | u"""<br /><br /><br /> |
---|
| 224 | The tranzaction code for eTranzact payments is <strong>${a}</strong>.""", |
---|
| 225 | mapping = {'a':tcode})) |
---|
[8722] | 226 | return note |
---|
| 227 | def target_url(self): |
---|
| 228 | slip = getUtility(IExtFileStore).getFileByContext( |
---|
| 229 | self.context, 'application_slip') |
---|
| 230 | if self.context.state != ADMITTED or slip is not None: |
---|
| 231 | return '' |
---|
| 232 | return self.view.url(self.view.context, self.target) |
---|
| 233 | |
---|
| 234 | class CustomStudentFilesUploadPage(StudentFilesUploadPage): |
---|
| 235 | """ View to upload passport picture. |
---|
| 236 | |
---|
| 237 | Students are not allowed to change the picture if they |
---|
| 238 | passed the regular Kofa application. |
---|
| 239 | """ |
---|
| 240 | |
---|
| 241 | def update(self): |
---|
| 242 | slip = getUtility(IExtFileStore).getFileByContext( |
---|
| 243 | self.context, 'application_slip') |
---|
| 244 | if self.context.state != ADMITTED or slip is not None: |
---|
| 245 | emit_lock_message(self) |
---|
| 246 | return |
---|
| 247 | super(StudentFilesUploadPage, self).update() |
---|
| 248 | return |
---|