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

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

Do not ask other applicants than ase for bank account data.

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