1 | ## $Id: browser.py 9056 2012-07-26 06:58:38Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 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 | """UI components for basic applicants and related components. |
---|
19 | """ |
---|
20 | import grok |
---|
21 | from zope.component import getUtility |
---|
22 | from zope.i18n import translate |
---|
23 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
24 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
25 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
26 | from waeup.kofa.applicants.interfaces import ( |
---|
27 | IApplicantRegisterUpdate, IApplicant, IApplicantEdit) |
---|
28 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
29 | ExportPDFPage, |
---|
30 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
31 | ApplicantRegistrationPage, ApplicantAddFormPage, |
---|
32 | OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage, |
---|
33 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
34 | ApplicantBaseDisplayFormPage) |
---|
35 | from waeup.kofa.applicants.viewlets import ( |
---|
36 | PaymentReceiptActionButton, PDFActionButton) |
---|
37 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
38 | from waeup.uniben.applicants.interfaces import ( |
---|
39 | ICustomPGApplicant, ICustomUGApplicant, ICustomPGApplicantEdit, ICustomUGApplicantEdit, |
---|
40 | ICustomApplicantOnlinePayment, IPUTMEApplicantEdit, |
---|
41 | UG_OMIT_DISPLAY_FIELDS, |
---|
42 | UG_OMIT_PDF_FIELDS, |
---|
43 | UG_OMIT_MANAGE_FIELDS, |
---|
44 | UG_OMIT_EDIT_FIELDS, |
---|
45 | PG_OMIT_DISPLAY_FIELDS, |
---|
46 | PG_OMIT_PDF_FIELDS, |
---|
47 | PG_OMIT_MANAGE_FIELDS, |
---|
48 | PG_OMIT_EDIT_FIELDS, |
---|
49 | PUTME_OMIT_DISPLAY_FIELDS, |
---|
50 | PUTME_OMIT_PDF_FIELDS, |
---|
51 | PUTME_OMIT_MANAGE_FIELDS, |
---|
52 | PUTME_OMIT_EDIT_FIELDS, |
---|
53 | PUTME_OMIT_RESULT_SLIP_FIELDS, |
---|
54 | PUDE_OMIT_DISPLAY_FIELDS, |
---|
55 | PUDE_OMIT_PDF_FIELDS, |
---|
56 | PUDE_OMIT_MANAGE_FIELDS, |
---|
57 | PUDE_OMIT_EDIT_FIELDS, |
---|
58 | PUDE_OMIT_RESULT_SLIP_FIELDS, |
---|
59 | ) |
---|
60 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
61 | |
---|
62 | class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
63 | """A breadcrumb for payments. |
---|
64 | """ |
---|
65 | grok.context(ICustomApplicantOnlinePayment) |
---|
66 | |
---|
67 | class PaymentReceiptActionButton(PaymentReceiptActionButton): |
---|
68 | grok.order(4) |
---|
69 | grok.context(ICustomApplicantOnlinePayment) |
---|
70 | |
---|
71 | class PDFActionButton(PDFActionButton): |
---|
72 | |
---|
73 | @property |
---|
74 | def text(self): |
---|
75 | if getattr(self.context, 'result_uploaded', False): |
---|
76 | return _('Download result slip') |
---|
77 | return _('Download application slip') |
---|
78 | |
---|
79 | |
---|
80 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
81 | """A display view for applicant data. |
---|
82 | """ |
---|
83 | |
---|
84 | @property |
---|
85 | def form_fields(self): |
---|
86 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
87 | if target is not None and target.startswith('pg'): |
---|
88 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
89 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
90 | form_fields = form_fields.omit(field) |
---|
91 | elif target is not None and target.startswith('putme'): |
---|
92 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
93 | for field in PUTME_OMIT_DISPLAY_FIELDS: |
---|
94 | form_fields = form_fields.omit(field) |
---|
95 | elif target is not None and target.startswith('pude'): |
---|
96 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
97 | for field in PUDE_OMIT_DISPLAY_FIELDS: |
---|
98 | form_fields = form_fields.omit(field) |
---|
99 | else: |
---|
100 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
101 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
102 | form_fields = form_fields.omit(field) |
---|
103 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
104 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
105 | return form_fields |
---|
106 | |
---|
107 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
108 | |
---|
109 | def _reduced_slip(self): |
---|
110 | return getattr(self.context, 'result_uploaded', False) |
---|
111 | |
---|
112 | @property |
---|
113 | def note(self): |
---|
114 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
115 | if target is not None and not target.startswith('pg') \ |
---|
116 | and not self._reduced_slip(): |
---|
117 | return _(u'<br /><br /><br />' |
---|
118 | 'Comfirm your exam venue 72 hours to the exam.') |
---|
119 | return |
---|
120 | |
---|
121 | @property |
---|
122 | def form_fields(self): |
---|
123 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
124 | if target is not None and target.startswith('pg'): |
---|
125 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
126 | for field in PG_OMIT_PDF_FIELDS: |
---|
127 | form_fields = form_fields.omit(field) |
---|
128 | elif target is not None and target.startswith('putme'): |
---|
129 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
130 | if self._reduced_slip(): |
---|
131 | for field in PUTME_OMIT_RESULT_SLIP_FIELDS: |
---|
132 | form_fields = form_fields.omit(field) |
---|
133 | else: |
---|
134 | for field in PUTME_OMIT_PDF_FIELDS: |
---|
135 | form_fields = form_fields.omit(field) |
---|
136 | elif target is not None and target.startswith('pude'): |
---|
137 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
138 | if self._reduced_slip(): |
---|
139 | for field in PUDE_OMIT_RESULT_SLIP_FIELDS: |
---|
140 | form_fields = form_fields.omit(field) |
---|
141 | else: |
---|
142 | for field in PUDE_OMIT_PDF_FIELDS: |
---|
143 | form_fields = form_fields.omit(field) |
---|
144 | else: |
---|
145 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
146 | for field in UG_OMIT_PDF_FIELDS: |
---|
147 | form_fields = form_fields.omit(field) |
---|
148 | if not getattr(self.context, 'student_id'): |
---|
149 | form_fields = form_fields.omit('student_id') |
---|
150 | return form_fields |
---|
151 | |
---|
152 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
153 | """A full edit view for applicant data. |
---|
154 | """ |
---|
155 | |
---|
156 | @property |
---|
157 | def form_fields(self): |
---|
158 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
159 | if target is not None and target.startswith('pg'): |
---|
160 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
161 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
162 | form_fields = form_fields.omit(field) |
---|
163 | elif target is not None and target.startswith('putme'): |
---|
164 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
165 | for field in PUTME_OMIT_MANAGE_FIELDS: |
---|
166 | form_fields = form_fields.omit(field) |
---|
167 | elif target is not None and target.startswith('pude'): |
---|
168 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
169 | for field in PUDE_OMIT_MANAGE_FIELDS: |
---|
170 | form_fields = form_fields.omit(field) |
---|
171 | else: |
---|
172 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
173 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
174 | form_fields = form_fields.omit(field) |
---|
175 | form_fields['student_id'].for_display = True |
---|
176 | form_fields['applicant_id'].for_display = True |
---|
177 | return form_fields |
---|
178 | |
---|
179 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
180 | """An applicant-centered edit view for applicant data. |
---|
181 | """ |
---|
182 | |
---|
183 | @property |
---|
184 | def form_fields(self): |
---|
185 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
186 | if target is not None and target.startswith('pg'): |
---|
187 | form_fields = grok.AutoFields(ICustomPGApplicantEdit) |
---|
188 | for field in PG_OMIT_EDIT_FIELDS: |
---|
189 | form_fields = form_fields.omit(field) |
---|
190 | elif target is not None and target.startswith('putme'): |
---|
191 | form_fields = grok.AutoFields(IPUTMEApplicantEdit) |
---|
192 | for field in PUTME_OMIT_EDIT_FIELDS: |
---|
193 | form_fields = form_fields.omit(field) |
---|
194 | elif target is not None and target.startswith('pude'): |
---|
195 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
196 | for field in PUDE_OMIT_EDIT_FIELDS: |
---|
197 | form_fields = form_fields.omit(field) |
---|
198 | else: |
---|
199 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
200 | for field in UG_OMIT_EDIT_FIELDS: |
---|
201 | form_fields = form_fields.omit(field) |
---|
202 | form_fields['applicant_id'].for_display = True |
---|
203 | form_fields['reg_number'].for_display = True |
---|
204 | return form_fields |
---|
205 | |
---|
206 | class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
207 | """ Page to view an online payment ticket |
---|
208 | """ |
---|
209 | grok.context(ICustomApplicantOnlinePayment) |
---|
210 | # We temporarily omit r_company since this attribute was not set in 2012 |
---|
211 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit( |
---|
212 | 'ac', 'r_company') |
---|
213 | form_fields[ |
---|
214 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
215 | form_fields[ |
---|
216 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
217 | |
---|
218 | class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
219 | """Deliver a PDF slip of the context. |
---|
220 | """ |
---|
221 | grok.context(ICustomApplicantOnlinePayment) |
---|
222 | # We temporarily omit r_company since this attribute was not set in 2012 |
---|
223 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit( |
---|
224 | 'ac', 'r_company') |
---|
225 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
226 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
227 | |
---|
228 | class CustomApplicantRegistrationPage(ApplicantRegistrationPage): |
---|
229 | """Captcha'd registration page for applicants. |
---|
230 | """ |
---|
231 | |
---|
232 | #def _redirect(self, email, password, applicant_id): |
---|
233 | # # Forward email and credentials to landing page. |
---|
234 | # self.redirect(self.url(self.context, 'registration_complete', |
---|
235 | # data = dict(email=email, password=password, |
---|
236 | # applicant_id=applicant_id))) |
---|
237 | # return |
---|