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

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

Temporary solution for reopening application in Uniben. This revision has to be reverted when ase application is finished.

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