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