1 | ## $Id: browser.py 9050 2012-07-26 04:35:28Z 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, PDFActionButton) |
---|
36 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
37 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
38 | INigeriaPGApplicant, INigeriaUGApplicant, |
---|
39 | INigeriaPGApplicantEdit, INigeriaUGApplicantEdit, |
---|
40 | INigeriaApplicantOnlinePayment,IPUTMEApplicantEdit, |
---|
41 | UG_OMIT_DISPLAY_FIELDS, PUTME_OMIT_DISPLAY_FIELDS, PG_OMIT_DISPLAY_FIELDS, |
---|
42 | UG_OMIT_PDF_FIELDS, PUTME_OMIT_PDF_FIELDS, PG_OMIT_PDF_FIELDS, |
---|
43 | UG_OMIT_MANAGE_FIELDS, PUTME_OMIT_MANAGE_FIELDS, PG_OMIT_MANAGE_FIELDS, |
---|
44 | UG_OMIT_EDIT_FIELDS, PG_OMIT_EDIT_FIELDS, PUTME_OMIT_EDIT_FIELDS, |
---|
45 | PUTME_OMIT_RESULT_SLIP_FIELDS) |
---|
46 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
47 | |
---|
48 | class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
49 | """A breadcrumb for payments. |
---|
50 | """ |
---|
51 | grok.context(INigeriaApplicantOnlinePayment) |
---|
52 | |
---|
53 | class PaymentReceiptActionButton(PaymentReceiptActionButton): |
---|
54 | grok.order(4) |
---|
55 | grok.context(INigeriaApplicantOnlinePayment) |
---|
56 | |
---|
57 | class PDFActionButton(PDFActionButton): |
---|
58 | |
---|
59 | @property |
---|
60 | def text(self): |
---|
61 | if getattr(self.context, 'result_uploaded', False): |
---|
62 | return _('Download result slip') |
---|
63 | return _('Download application slip') |
---|
64 | |
---|
65 | class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
66 | """A display view for applicant data. |
---|
67 | """ |
---|
68 | |
---|
69 | @property |
---|
70 | def form_fields(self): |
---|
71 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
72 | if target is not None and target.startswith('pg'): |
---|
73 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
74 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
75 | form_fields = form_fields.omit(field) |
---|
76 | elif target is not None and target.startswith('putme'): |
---|
77 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
78 | for field in PUTME_OMIT_DISPLAY_FIELDS: |
---|
79 | form_fields = form_fields.omit(field) |
---|
80 | else: |
---|
81 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
82 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
83 | form_fields = form_fields.omit(field) |
---|
84 | return form_fields |
---|
85 | |
---|
86 | class NigeriaPDFApplicationSlip(PDFApplicationSlip): |
---|
87 | |
---|
88 | def _reduced_slip(self): |
---|
89 | return getattr(self.context, 'result_uploaded', False) |
---|
90 | |
---|
91 | @property |
---|
92 | def note(self): |
---|
93 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
94 | if target is not None and not target.startswith('pg') \ |
---|
95 | and not self._reduced_slip(): |
---|
96 | return _(u'<br /><br /><br />' |
---|
97 | 'Comfirm your exam venue 72 hours to the exam.') |
---|
98 | return |
---|
99 | |
---|
100 | @property |
---|
101 | def form_fields(self): |
---|
102 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
103 | if target is not None and target.startswith('pg'): |
---|
104 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
105 | for field in PG_OMIT_PDF_FIELDS: |
---|
106 | form_fields = form_fields.omit(field) |
---|
107 | elif target is not None and target.startswith('putme'): |
---|
108 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
109 | if self._reduced_slip(): |
---|
110 | for field in PUTME_OMIT_RESULT_SLIP_FIELDS: |
---|
111 | form_fields = form_fields.omit(field) |
---|
112 | else: |
---|
113 | for field in PUTME_OMIT_PDF_FIELDS: |
---|
114 | form_fields = form_fields.omit(field) |
---|
115 | else: |
---|
116 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
117 | for field in UG_OMIT_PDF_FIELDS: |
---|
118 | form_fields = form_fields.omit(field) |
---|
119 | if not getattr(self.context, 'student_id'): |
---|
120 | form_fields = form_fields.omit('student_id') |
---|
121 | return form_fields |
---|
122 | |
---|
123 | class NigeriaApplicantManageFormPage(ApplicantManageFormPage): |
---|
124 | """A full edit view for applicant data. |
---|
125 | """ |
---|
126 | |
---|
127 | @property |
---|
128 | def form_fields(self): |
---|
129 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
130 | if target is not None and target.startswith('pg'): |
---|
131 | form_fields = grok.AutoFields(INigeriaPGApplicant) |
---|
132 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
133 | form_fields = form_fields.omit(field) |
---|
134 | elif target is not None and target.startswith('putme'): |
---|
135 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
136 | for field in PUTME_OMIT_MANAGE_FIELDS: |
---|
137 | form_fields = form_fields.omit(field) |
---|
138 | else: |
---|
139 | form_fields = grok.AutoFields(INigeriaUGApplicant) |
---|
140 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
141 | form_fields = form_fields.omit(field) |
---|
142 | form_fields['student_id'].for_display = True |
---|
143 | form_fields['applicant_id'].for_display = True |
---|
144 | return form_fields |
---|
145 | |
---|
146 | class NigeriaApplicantEditFormPage(ApplicantEditFormPage): |
---|
147 | """An applicant-centered edit view for applicant data. |
---|
148 | """ |
---|
149 | |
---|
150 | @property |
---|
151 | def form_fields(self): |
---|
152 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
153 | if target is not None and target.startswith('pg'): |
---|
154 | form_fields = grok.AutoFields(INigeriaPGApplicantEdit) |
---|
155 | for field in PG_OMIT_EDIT_FIELDS: |
---|
156 | form_fields = form_fields.omit(field) |
---|
157 | elif target is not None and target.startswith('putme'): |
---|
158 | form_fields = grok.AutoFields(IPUTMEApplicantEdit) |
---|
159 | for field in PUTME_OMIT_EDIT_FIELDS: |
---|
160 | form_fields = form_fields.omit(field) |
---|
161 | else: |
---|
162 | form_fields = grok.AutoFields(INigeriaUGApplicantEdit) |
---|
163 | for field in UG_OMIT_EDIT_FIELDS: |
---|
164 | form_fields = form_fields.omit(field) |
---|
165 | form_fields['applicant_id'].for_display = True |
---|
166 | form_fields['reg_number'].for_display = True |
---|
167 | return form_fields |
---|
168 | |
---|
169 | class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
170 | """ Page to view an online payment ticket |
---|
171 | """ |
---|
172 | grok.context(INigeriaApplicantOnlinePayment) |
---|
173 | form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac') |
---|
174 | form_fields[ |
---|
175 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
176 | form_fields[ |
---|
177 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
178 | |
---|
179 | class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
180 | """Deliver a PDF slip of the context. |
---|
181 | """ |
---|
182 | grok.context(INigeriaApplicantOnlinePayment) |
---|
183 | form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac') |
---|
184 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
185 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
186 | |
---|
187 | class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage): |
---|
188 | """Captcha'd registration page for applicants. |
---|
189 | """ |
---|
190 | |
---|
191 | #def _redirect(self, email, password, applicant_id): |
---|
192 | # # Forward email and credentials to landing page. |
---|
193 | # self.redirect(self.url(self.context, 'registration_complete', |
---|
194 | # data = dict(email=email, password=password, |
---|
195 | # applicant_id=applicant_id))) |
---|
196 | # return |
---|