1 | ## $Id: browser.py 8716 2012-06-14 06:19:53Z 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 waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
24 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
25 | from waeup.kofa.applicants.interfaces import ( |
---|
26 | IApplicantRegisterUpdate, IApplicant, IApplicantEdit) |
---|
27 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
28 | ExportPDFPage, |
---|
29 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
30 | ApplicantRegistrationPage, ApplicantAddFormPage, |
---|
31 | OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage, |
---|
32 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
33 | ApplicantBaseDisplayFormPage) |
---|
34 | from waeup.kofa.applicants.viewlets import ( |
---|
35 | PaymentReceiptActionButton) |
---|
36 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
37 | from waeup.uniben.applicants.interfaces import ( |
---|
38 | IPGApplicant, IUGApplicant, IPGApplicantEdit, IUGApplicantEdit, |
---|
39 | ICustomApplicantOnlinePayment, IPUTMEApplicantEdit, |
---|
40 | UG_OMIT_DISPLAY_FIELDS, PG_OMIT_DISPLAY_FIELDS, |
---|
41 | UG_OMIT_PDF_FIELDS, PG_OMIT_PDF_FIELDS, |
---|
42 | UG_OMIT_MANAGE_FIELDS, PG_OMIT_MANAGE_FIELDS, |
---|
43 | UG_OMIT_EDIT_FIELDS, PG_OMIT_EDIT_FIELDS, PUTME_OMIT_EDIT_FIELDS) |
---|
44 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
45 | |
---|
46 | #class RequestCallbackActionButton(RequestCallbackActionButton): |
---|
47 | # """ Display the base package callback button in custom pages. |
---|
48 | # """ |
---|
49 | # grok.context(ICustomApplicantOnlinePayment) |
---|
50 | |
---|
51 | #class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage): |
---|
52 | # """ Activate callback simulation view |
---|
53 | # """ |
---|
54 | # grok.context(ICustomApplicantOnlinePayment) |
---|
55 | |
---|
56 | class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
57 | """A breadcrumb for payments. |
---|
58 | """ |
---|
59 | grok.context(ICustomApplicantOnlinePayment) |
---|
60 | |
---|
61 | class PaymentReceiptActionButton(PaymentReceiptActionButton): |
---|
62 | grok.order(4) |
---|
63 | grok.context(ICustomApplicantOnlinePayment) |
---|
64 | |
---|
65 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
66 | |
---|
67 | @property |
---|
68 | def note(self): |
---|
69 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
70 | if target is not None and not target.startswith('pg'): |
---|
71 | return _(u'<br /><br /><br />' |
---|
72 | 'Comfirm your exam venue 72 hours to the exam.') |
---|
73 | return |
---|
74 | |
---|
75 | @property |
---|
76 | def form_fields(self): |
---|
77 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
78 | if target is not None and target.startswith('pg'): |
---|
79 | form_fields = grok.AutoFields(IPGApplicant) |
---|
80 | for field in PG_OMIT_PDF_FIELDS: |
---|
81 | form_fields = form_fields.omit(field) |
---|
82 | else: |
---|
83 | form_fields = grok.AutoFields(IUGApplicant) |
---|
84 | for field in UG_OMIT_PDF_FIELDS: |
---|
85 | form_fields = form_fields.omit(field) |
---|
86 | return form_fields |
---|
87 | |
---|
88 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
89 | """A display view for applicant data. |
---|
90 | """ |
---|
91 | |
---|
92 | @property |
---|
93 | def form_fields(self): |
---|
94 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
95 | if target is not None and target.startswith('pg'): |
---|
96 | form_fields = grok.AutoFields(IPGApplicant) |
---|
97 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
98 | form_fields = form_fields.omit(field) |
---|
99 | else: |
---|
100 | form_fields = grok.AutoFields(IUGApplicant) |
---|
101 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
102 | form_fields = form_fields.omit(field) |
---|
103 | return form_fields |
---|
104 | |
---|
105 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
106 | """A full edit view for applicant data. |
---|
107 | """ |
---|
108 | |
---|
109 | @property |
---|
110 | def form_fields(self): |
---|
111 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
112 | if target is not None and target.startswith('pg'): |
---|
113 | form_fields = grok.AutoFields(IPGApplicant) |
---|
114 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
115 | form_fields = form_fields.omit(field) |
---|
116 | else: |
---|
117 | form_fields = grok.AutoFields(IUGApplicant) |
---|
118 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
119 | form_fields = form_fields.omit(field) |
---|
120 | form_fields['student_id'].for_display = True |
---|
121 | form_fields['applicant_id'].for_display = True |
---|
122 | return form_fields |
---|
123 | |
---|
124 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
125 | """An applicant-centered edit view for applicant data. |
---|
126 | """ |
---|
127 | |
---|
128 | @property |
---|
129 | def form_fields(self): |
---|
130 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
131 | if target is not None and target.startswith('pg'): |
---|
132 | form_fields = grok.AutoFields(IPGApplicantEdit) |
---|
133 | for field in PG_OMIT_EDIT_FIELDS: |
---|
134 | form_fields = form_fields.omit(field) |
---|
135 | elif target is not None and target.startswith('putme'): |
---|
136 | form_fields = grok.AutoFields(IPUTMEApplicantEdit) |
---|
137 | for field in PUTME_OMIT_EDIT_FIELDS: |
---|
138 | form_fields = form_fields.omit(field) |
---|
139 | else: |
---|
140 | form_fields = grok.AutoFields(IUGApplicantEdit) |
---|
141 | for field in UG_OMIT_EDIT_FIELDS: |
---|
142 | form_fields = form_fields.omit(field) |
---|
143 | form_fields['applicant_id'].for_display = True |
---|
144 | form_fields['reg_number'].for_display = True |
---|
145 | return form_fields |
---|
146 | |
---|
147 | class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
148 | """ Page to view an online payment ticket |
---|
149 | """ |
---|
150 | grok.context(ICustomApplicantOnlinePayment) |
---|
151 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac') |
---|
152 | form_fields[ |
---|
153 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
154 | form_fields[ |
---|
155 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
156 | #grok.template('payment_view') |
---|
157 | |
---|
158 | #@property |
---|
159 | #def transaction_code(self): |
---|
160 | # tcode = self.context.p_id |
---|
161 | # return tcode[len(tcode)-8:len(tcode)] |
---|
162 | |
---|
163 | class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage): |
---|
164 | """ Page to add an online payment ticket |
---|
165 | """ |
---|
166 | factory = u'waeup.CustomApplicantOnlinePayment' |
---|
167 | |
---|
168 | class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
169 | """Deliver a PDF slip of the context. |
---|
170 | """ |
---|
171 | grok.context(ICustomApplicantOnlinePayment) |
---|
172 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac') |
---|
173 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
174 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
175 | |
---|
176 | # @property |
---|
177 | # def note(self): |
---|
178 | # if self.context.p_state == 'paid': |
---|
179 | # return None |
---|
180 | # tcode = self.context.p_id |
---|
181 | # tcode = tcode[len(tcode)-8:len(tcode)] |
---|
182 | # amount = self.context.amount_auth |
---|
183 | # note = translate(_( |
---|
184 | # u"""<br /><br /><br /> |
---|
185 | #The tranzaction code is <strong>${a}</strong>.""", |
---|
186 | # mapping = {'a':tcode})) |
---|
187 | # return note |
---|
188 | |
---|
189 | class CustomApplicantRegistrationPage(ApplicantRegistrationPage): |
---|
190 | """Captcha'd registration page for applicants. |
---|
191 | """ |
---|
192 | |
---|
193 | def _redirect(self, email, password, applicant_id): |
---|
194 | # Forward email and credentials to landing page. |
---|
195 | self.redirect(self.url(self.context, 'registration_complete', |
---|
196 | data = dict(email=email, password=password, |
---|
197 | applicant_id=applicant_id))) |
---|
198 | return |
---|