[7505] | 1 | ## $Id: browser.py 8247 2012-04-22 12:56:07Z 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 |
---|
[8247] | 21 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
[8137] | 22 | from waeup.kofa.interfaces import IExtFileStore |
---|
[8247] | 23 | from waeup.kofa.browser.layout import action |
---|
[7822] | 24 | from waeup.kofa.students.browser import ( |
---|
[8129] | 25 | StudentPersonalDisplayFormPage, |
---|
[7525] | 26 | StudentClearanceManageFormPage, StudentClearanceEditFormPage, |
---|
[7998] | 27 | StudentClearanceDisplayFormPage, OnlinePaymentCallbackPage, |
---|
[8076] | 28 | ExportPDFClearanceSlipPage, StudentBaseManageFormPage, |
---|
[8247] | 29 | StudentBaseEditFormPage, StudentPersonalEditFormPage, |
---|
| 30 | OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage, |
---|
| 31 | OnlinePaymentBreadcrumb) |
---|
[7879] | 32 | from waeup.kofa.students.viewlets import RequestCallbackActionButton |
---|
[8020] | 33 | from waeup.uniben.students.interfaces import ( |
---|
[8204] | 34 | ICustomStudentBase, ICustomStudent, ICustomStudentPersonal, |
---|
| 35 | ICustomUGStudentClearance,ICustomPGStudentClearance, |
---|
[8247] | 36 | ICustomStudentOnlinePayment, |
---|
[7879] | 37 | ) |
---|
[8020] | 38 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[7505] | 39 | |
---|
[8247] | 40 | class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
| 41 | """A breadcrumb for payments. |
---|
| 42 | """ |
---|
| 43 | grok.context(ICustomStudentOnlinePayment) |
---|
| 44 | |
---|
| 45 | class RequestCallbackActionButton(RequestCallbackActionButton): |
---|
[7998] | 46 | """ Do not display the base package callback button in custom pages. |
---|
| 47 | """ |
---|
| 48 | @property |
---|
| 49 | def target_url(self): |
---|
| 50 | return '' |
---|
| 51 | |
---|
[8204] | 52 | class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage): |
---|
[7998] | 53 | """ Neutralize callback simulation view |
---|
| 54 | """ |
---|
| 55 | def update(self): |
---|
| 56 | return |
---|
| 57 | |
---|
[8204] | 58 | class CustomStudentBaseManageFormPage(StudentBaseManageFormPage): |
---|
[8076] | 59 | """ View to manage student base data |
---|
| 60 | """ |
---|
[8204] | 61 | form_fields = grok.AutoFields(ICustomStudentBase).omit('student_id') |
---|
[8076] | 62 | |
---|
[8204] | 63 | class CustomStudentBaseEditFormPage(StudentBaseEditFormPage): |
---|
[8076] | 64 | """ View to edit student base data |
---|
| 65 | """ |
---|
[8204] | 66 | form_fields = grok.AutoFields(ICustomStudentBase).select( |
---|
[8076] | 67 | 'email', 'phone') |
---|
| 68 | |
---|
| 69 | |
---|
[8204] | 70 | class CustomStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage): |
---|
[7505] | 71 | """ Page to display student personal data |
---|
| 72 | """ |
---|
[8204] | 73 | grok.context(ICustomStudent) |
---|
| 74 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
[7505] | 75 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 76 | |
---|
| 77 | |
---|
[8204] | 78 | class CustomStudentPersonalEditFormPage(StudentPersonalEditFormPage): |
---|
[8140] | 79 | """ Page to edit personal data |
---|
| 80 | """ |
---|
[8204] | 81 | form_fields = grok.AutoFields(ICustomStudentPersonal) |
---|
[8140] | 82 | |
---|
| 83 | |
---|
[8204] | 84 | class CustomStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage): |
---|
[7525] | 85 | """ Page to display student clearance data |
---|
| 86 | """ |
---|
[8204] | 87 | grok.context(ICustomStudent) |
---|
[7525] | 88 | |
---|
[7995] | 89 | @property |
---|
| 90 | def form_fields(self): |
---|
| 91 | cm = getattr(self.context,'current_mode', None) |
---|
| 92 | if cm is not None and cm.startswith('pg'): |
---|
[8204] | 93 | form_fields = grok.AutoFields( |
---|
| 94 | ICustomPGStudentClearance).omit('clearance_locked') |
---|
[7995] | 95 | else: |
---|
[8204] | 96 | form_fields = grok.AutoFields( |
---|
| 97 | ICustomUGStudentClearance).omit('clearance_locked') |
---|
[7995] | 98 | return form_fields |
---|
| 99 | |
---|
[8204] | 100 | class CustomExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage): |
---|
[7995] | 101 | """Deliver a PDF slip of the context. |
---|
| 102 | """ |
---|
[8204] | 103 | grok.context(ICustomStudent) |
---|
[7995] | 104 | |
---|
| 105 | @property |
---|
| 106 | def form_fields(self): |
---|
| 107 | cm = getattr(self.context,'current_mode', None) |
---|
| 108 | if cm is not None and cm.startswith('pg'): |
---|
[8204] | 109 | form_fields = grok.AutoFields( |
---|
| 110 | ICustomPGStudentClearance).omit('clearance_locked') |
---|
[7995] | 111 | else: |
---|
[8204] | 112 | form_fields = grok.AutoFields( |
---|
| 113 | ICustomUGStudentClearance).omit('clearance_locked') |
---|
[7995] | 114 | return form_fields |
---|
| 115 | |
---|
[8204] | 116 | class CustomStudentClearanceManageFormPage(StudentClearanceManageFormPage): |
---|
[7525] | 117 | """ Page to edit student clearance data |
---|
| 118 | """ |
---|
[8204] | 119 | grok.context(ICustomStudent) |
---|
[7525] | 120 | |
---|
[7995] | 121 | @property |
---|
| 122 | def form_fields(self): |
---|
| 123 | cm = getattr(self.context,'current_mode', None) |
---|
| 124 | if cm is not None and cm.startswith('pg'): |
---|
[8204] | 125 | form_fields = grok.AutoFields(ICustomPGStudentClearance) |
---|
[7995] | 126 | else: |
---|
[8204] | 127 | form_fields = grok.AutoFields(ICustomUGStudentClearance) |
---|
[7995] | 128 | return form_fields |
---|
| 129 | |
---|
[8204] | 130 | class CustomStudentClearanceEditFormPage(StudentClearanceEditFormPage): |
---|
[7525] | 131 | """ View to edit student clearance data by student |
---|
| 132 | """ |
---|
[8204] | 133 | grok.context(ICustomStudent) |
---|
[7525] | 134 | |
---|
[7995] | 135 | @property |
---|
| 136 | def form_fields(self): |
---|
| 137 | cm = getattr(self.context,'current_mode', None) |
---|
| 138 | if cm is not None and cm.startswith('pg'): |
---|
[8204] | 139 | form_fields = grok.AutoFields(ICustomPGStudentClearance).omit('clearance_locked') |
---|
[7995] | 140 | else: |
---|
[8204] | 141 | form_fields = grok.AutoFields(ICustomUGStudentClearance).omit('clearance_locked') |
---|
[7995] | 142 | return form_fields |
---|
| 143 | |
---|
[8137] | 144 | def dataNotComplete(self): |
---|
| 145 | store = getUtility(IExtFileStore) |
---|
| 146 | if not store.getFileByContext(self.context, attr=u'birth_certicicate.jpg'): |
---|
| 147 | return _('No birth certificate uploaded.') |
---|
| 148 | if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): |
---|
| 149 | return _('No referee letter uploaded.') |
---|
| 150 | if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): |
---|
| 151 | return _('No acceptance letter uploaded.') |
---|
| 152 | if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): |
---|
| 153 | return _('No first sitting result uploaded.') |
---|
| 154 | return False |
---|
| 155 | |
---|
[8247] | 156 | class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
| 157 | """ Page to view an online payment ticket |
---|
| 158 | """ |
---|
| 159 | grok.context(ICustomStudentOnlinePayment) |
---|
| 160 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment) |
---|
| 161 | form_fields[ |
---|
| 162 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 163 | form_fields[ |
---|
| 164 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 165 | grok.template('payment_view') |
---|
| 166 | |
---|
| 167 | @property |
---|
| 168 | def transaction_code(self): |
---|
| 169 | tcode = self.context.p_id |
---|
| 170 | return tcode[len(tcode)-8:len(tcode)] |
---|
| 171 | |
---|
| 172 | class CustomOnlinePaymentAddFormPage(OnlinePaymentAddFormPage): |
---|
| 173 | """ Page to add an online payment ticket |
---|
| 174 | """ |
---|
| 175 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
| 176 | 'p_category') |
---|
| 177 | factory = u'waeup.CustomStudentOnlinePayment' |
---|
| 178 | |
---|
| 179 | def _fillCustomFields(self, payment, pay_details): |
---|
| 180 | payment.surcharge_1 = pay_details['surcharge_1'] |
---|
| 181 | payment.surcharge_2 = pay_details['surcharge_2'] |
---|
| 182 | payment.surcharge_3 = pay_details['surcharge_3'] |
---|
| 183 | return payment |
---|