source: main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/applicants/browser.py @ 14060

Last change on this file since 14060 was 14060, checked in by Henrik Bettermann, 8 years ago

User other prefixes for Akoka applications.

  • Property svn:keywords set to Id
File size: 14.5 KB
Line 
1## $Id: browser.py 14060 2016-08-08 15:14:20Z 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"""
20import grok
21from zope.component import getUtility
22from zope.i18n import translate
23from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
24from zope.formlib.textwidgets import BytesDisplayWidget
25from waeup.kofa.students.interfaces import IStudentsUtils
26from waeup.kofa.applicants.interfaces import IApplicantRegisterUpdate
27from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
28    ApplicantManageFormPage, ApplicantEditFormPage,
29    ApplicantRegistrationPage, ApplicantAddFormPage,
30    OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage,
31    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
32    ApplicantBaseDisplayFormPage)
33from waeup.kofa.applicants.viewlets import (
34    PaymentReceiptActionButton, PDFActionButton)
35from waeup.kofa.applicants.pdf import PDFApplicationSlip
36from kofacustom.nigeria.applicants.interfaces import (
37    INigeriaPGApplicant, INigeriaUGApplicant,
38    INigeriaPGApplicantEdit, INigeriaUGApplicantEdit,
39    INigeriaApplicantOnlinePayment,IPUTMEApplicantEdit,
40    UG_OMIT_DISPLAY_FIELDS,
41    UG_OMIT_PDF_FIELDS,
42    UG_OMIT_MANAGE_FIELDS,
43    UG_OMIT_EDIT_FIELDS,
44    CBT_OMIT_DISPLAY_FIELDS,
45    CBT_OMIT_PDF_FIELDS,
46    CBT_OMIT_MANAGE_FIELDS,
47    CBT_OMIT_EDIT_FIELDS,
48    AFFIL_OMIT_DISPLAY_FIELDS,
49    AFFIL_OMIT_PDF_FIELDS,
50    AFFIL_OMIT_MANAGE_FIELDS,
51    AFFIL_OMIT_EDIT_FIELDS,
52    PG_OMIT_DISPLAY_FIELDS,
53    PG_OMIT_PDF_FIELDS,
54    PG_OMIT_MANAGE_FIELDS,
55    PG_OMIT_EDIT_FIELDS,
56    PUTME_OMIT_DISPLAY_FIELDS,
57    PUTME_OMIT_PDF_FIELDS,
58    PUTME_OMIT_MANAGE_FIELDS,
59    PUTME_OMIT_EDIT_FIELDS,
60    PUTME_OMIT_RESULT_SLIP_FIELDS,
61    PUDE_OMIT_DISPLAY_FIELDS,
62    PUDE_OMIT_PDF_FIELDS,
63    PUDE_OMIT_MANAGE_FIELDS,
64    PUDE_OMIT_EDIT_FIELDS,
65    PUDE_OMIT_RESULT_SLIP_FIELDS,
66    PRE_OMIT_DISPLAY_FIELDS,
67    PRE_OMIT_PDF_FIELDS,
68    PRE_OMIT_MANAGE_FIELDS,
69    PRE_OMIT_EDIT_FIELDS,
70    )
71from kofacustom.nigeria.interfaces import MessageFactory as _
72
73class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
74    """A breadcrumb for payments.
75    """
76    grok.context(INigeriaApplicantOnlinePayment)
77
78class PDFActionButton(PDFActionButton):
79
80    @property
81    def text(self):
82        if getattr(self.context, 'result_uploaded', False):
83            return _('Download result slip')
84        return _('Download application slip')
85
86class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage):
87    """A display view for applicant data.
88    """
89
90    def _not_paid(self):
91        return self.context.state in ('initialized', 'started',)
92
93    @property
94    def form_fields(self):
95        if self.target is not None and self.target.startswith('pg'):
96            form_fields = grok.AutoFields(INigeriaPGApplicant)
97            for field in PG_OMIT_DISPLAY_FIELDS:
98                form_fields = form_fields.omit(field)
99        elif self.target is not None and self.target.startswith('pre'):
100            form_fields = grok.AutoFields(INigeriaPGApplicant)
101            for field in PRE_OMIT_DISPLAY_FIELDS:
102                form_fields = form_fields.omit(field)
103        elif self.target is not None and self.target.startswith('cbt'): #uniben
104            form_fields = grok.AutoFields(INigeriaUGApplicant)
105            for field in CBT_OMIT_DISPLAY_FIELDS:
106                form_fields = form_fields.omit(field)
107        elif self.target is not None and self.target.startswith('akj'): # uniben
108            form_fields = grok.AutoFields(INigeriaPGApplicant)
109            for field in PRE_OMIT_DISPLAY_FIELDS:
110                form_fields = form_fields.omit(field)
111        elif self.target is not None and self.target.startswith('ak'): # uniben
112            form_fields = grok.AutoFields(INigeriaUGApplicant)
113            for field in AFFIL_OMIT_DISPLAY_FIELDS:
114                form_fields = form_fields.omit(field)
115        elif self.target is not None and self.target.startswith('ase'): # was putme
116            form_fields = grok.AutoFields(INigeriaUGApplicant)
117            for field in PUTME_OMIT_DISPLAY_FIELDS:
118                form_fields = form_fields.omit(field)
119        elif self.target is not None and self.target.startswith('pude'):
120            form_fields = grok.AutoFields(INigeriaUGApplicant)
121            for field in PUDE_OMIT_DISPLAY_FIELDS:
122                form_fields = form_fields.omit(field)
123        else:
124            form_fields = grok.AutoFields(INigeriaUGApplicant)
125            for field in UG_OMIT_DISPLAY_FIELDS:
126                form_fields = form_fields.omit(field)
127        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
128        form_fields['notice'].custom_widget = BytesDisplayWidget
129        if not getattr(self.context, 'student_id'):
130            form_fields = form_fields.omit('student_id')
131        if not getattr(self.context, 'screening_score'):
132            form_fields = form_fields.omit('screening_score')
133        if not getattr(self.context, 'screening_venue') or self._not_paid():
134            form_fields = form_fields.omit('screening_venue')
135        if not getattr(self.context, 'screening_date') or self._not_paid():
136            form_fields = form_fields.omit('screening_date')
137        return form_fields
138
139class NigeriaPDFApplicationSlip(PDFApplicationSlip):
140
141    def _addLoginInformation(self):
142        """ We do no longer render login information on
143        pdf application slips.
144        """
145        return
146
147    def _reduced_slip(self):
148        return getattr(self.context, 'result_uploaded', False)
149
150    @property
151    def form_fields(self):
152        if self.target is not None and self.target.startswith('pg'):
153            form_fields = grok.AutoFields(INigeriaPGApplicant)
154            for field in PG_OMIT_PDF_FIELDS:
155                form_fields = form_fields.omit(field)
156        elif self.target is not None and self.target.startswith('pre'):
157            form_fields = grok.AutoFields(INigeriaPGApplicant)
158            for field in PRE_OMIT_PDF_FIELDS:
159                form_fields = form_fields.omit(field)
160        elif self.target is not None and self.target.startswith('cbt'): # uniben
161            form_fields = grok.AutoFields(INigeriaUGApplicant)
162            for field in CBT_OMIT_PDF_FIELDS:
163                form_fields = form_fields.omit(field)
164        elif self.target is not None and self.target.startswith('ak'): # uniben
165            form_fields = grok.AutoFields(INigeriaUGApplicant)
166            for field in AFFIL_OMIT_PDF_FIELDS:
167                form_fields = form_fields.omit(field)
168        elif self.target is not None and self.target.startswith('akj'): # uniben
169            form_fields = grok.AutoFields(INigeriaPGApplicant)
170            for field in PRE_OMIT_PDF_FIELDS:
171                form_fields = form_fields.omit(field)
172        elif self.target is not None and self.target.startswith('ase'): # was putme
173            form_fields = grok.AutoFields(INigeriaUGApplicant)
174            if self._reduced_slip():
175                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
176                    form_fields = form_fields.omit(field)
177            else:
178                for field in PUTME_OMIT_PDF_FIELDS:
179                    form_fields = form_fields.omit(field)
180        elif self.target is not None and self.target.startswith('pude'):
181            form_fields = grok.AutoFields(INigeriaUGApplicant)
182            if self._reduced_slip():
183                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
184                    form_fields = form_fields.omit(field)
185            else:
186                for field in PUDE_OMIT_PDF_FIELDS:
187                    form_fields = form_fields.omit(field)
188        else:
189            form_fields = grok.AutoFields(INigeriaUGApplicant)
190            for field in UG_OMIT_PDF_FIELDS:
191                form_fields = form_fields.omit(field)
192        if not getattr(self.context, 'student_id'):
193            form_fields = form_fields.omit('student_id')
194        if not getattr(self.context, 'screening_score'):
195            form_fields = form_fields.omit('screening_score')
196        if not getattr(self.context, 'screening_venue'):
197            form_fields = form_fields.omit('screening_venue')
198        if not getattr(self.context, 'screening_date'):
199            form_fields = form_fields.omit('screening_date')
200        return form_fields
201
202class NigeriaApplicantManageFormPage(ApplicantManageFormPage):
203    """A full edit view for applicant data.
204    """
205   
206    @property
207    def form_fields(self):
208        if self.target is not None and self.target.startswith('pg'):
209            form_fields = grok.AutoFields(INigeriaPGApplicant)
210            for field in PG_OMIT_MANAGE_FIELDS:
211                form_fields = form_fields.omit(field)
212        elif self.target is not None and self.target.startswith('pre'):
213            form_fields = grok.AutoFields(INigeriaPGApplicant)
214            for field in PRE_OMIT_MANAGE_FIELDS:
215                form_fields = form_fields.omit(field)
216        elif self.target is not None and self.target.startswith('cbt'): # uniben
217            form_fields = grok.AutoFields(INigeriaUGApplicant)
218            for field in CBT_OMIT_MANAGE_FIELDS:
219                form_fields = form_fields.omit(field)
220        elif self.target is not None and self.target.startswith('akj'): # uniben
221            form_fields = grok.AutoFields(INigeriaPGApplicant)
222            for field in PRE_OMIT_MANAGE_FIELDS:
223                form_fields = form_fields.omit(field)
224        elif self.target is not None and self.target.startswith('ak'): # uniben
225            form_fields = grok.AutoFields(INigeriaUGApplicant)
226            for field in AFFIL_OMIT_MANAGE_FIELDS:
227                form_fields = form_fields.omit(field)
228        elif self.target is not None and self.target.startswith('ase'): # was putme
229            form_fields = grok.AutoFields(INigeriaUGApplicant)
230            for field in PUTME_OMIT_MANAGE_FIELDS:
231                form_fields = form_fields.omit(field)
232        elif self.target is not None and self.target.startswith('pude'):
233            form_fields = grok.AutoFields(INigeriaUGApplicant)
234            for field in PUDE_OMIT_MANAGE_FIELDS:
235                form_fields = form_fields.omit(field)
236        else:
237            form_fields = grok.AutoFields(INigeriaUGApplicant)
238            for field in UG_OMIT_MANAGE_FIELDS:
239                form_fields = form_fields.omit(field)
240        form_fields['student_id'].for_display = True
241        form_fields['applicant_id'].for_display = True
242        return form_fields
243
244class NigeriaApplicantEditFormPage(ApplicantEditFormPage):
245    """An applicant-centered edit view for applicant data.
246    """
247
248    @property
249    def form_fields(self):
250        if self.target is not None and self.target.startswith('pg'):
251            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
252            for field in PG_OMIT_EDIT_FIELDS:
253                form_fields = form_fields.omit(field)
254        elif self.target is not None and self.target.startswith('pre'):
255            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
256            for field in PRE_OMIT_EDIT_FIELDS:
257                form_fields = form_fields.omit(field)
258        elif self.target is not None and self.target.startswith('cbt'): # uniben
259            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
260            for field in CBT_OMIT_EDIT_FIELDS:
261                form_fields = form_fields.omit(field)
262        elif self.target is not None and self.target.startswith('akj'): # uniben
263            form_fields = grok.AutoFields(INigeriaPGApplicant)
264            for field in PRE_OMIT_EDIT_FIELDS:
265                form_fields = form_fields.omit(field)
266        elif self.target is not None and self.target.startswith('ak'): # uniben
267            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
268            for field in AFFIL_OMIT_EDIT_FIELDS:
269                form_fields = form_fields.omit(field)
270        elif self.target is not None and self.target.startswith('ase'): # was putme
271            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
272            for field in PUTME_OMIT_EDIT_FIELDS:
273                form_fields = form_fields.omit(field)
274        elif self.target is not None and self.target.startswith('pude'):
275            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
276            for field in PUDE_OMIT_EDIT_FIELDS:
277                form_fields = form_fields.omit(field)
278        else:
279            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
280            for field in UG_OMIT_EDIT_FIELDS:
281                form_fields = form_fields.omit(field)
282        form_fields['applicant_id'].for_display = True
283        form_fields['reg_number'].for_display = True
284        return form_fields
285
286class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
287    """ Page to view an online payment ticket
288    """
289    grok.context(INigeriaApplicantOnlinePayment)
290    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac',
291        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
292    form_fields[
293        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
294    form_fields[
295        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
296
297class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
298    """Deliver a PDF slip of the context.
299    """
300    grok.context(INigeriaApplicantOnlinePayment)
301    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit(
302        'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
303    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
304    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
305
306class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage):
307    """Captcha'd registration page for applicants.
308    """
309
310    #def _redirect(self, email, password, applicant_id):
311    #    # Forward email and credentials to landing page.
312    #    self.redirect(self.url(self.context, 'registration_complete',
313    #        data = dict(email=email, password=password,
314    #        applicant_id=applicant_id)))
315    #    return
Note: See TracBrowser for help on using the repository browser.