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

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

Use correct interface for akj applications.

  • Property svn:keywords set to Id
File size: 14.5 KB
RevLine 
[8926]1## $Id: browser.py 14062 2016-08-09 17:24:03Z 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)
[14060]103        elif self.target is not None and self.target.startswith('cbt'): #uniben
[13142]104            form_fields = grok.AutoFields(INigeriaUGApplicant)
105            for field in CBT_OMIT_DISPLAY_FIELDS:
106                form_fields = form_fields.omit(field)
[14060]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
[13551]112            form_fields = grok.AutoFields(INigeriaUGApplicant)
113            for field in AFFIL_OMIT_DISPLAY_FIELDS:
114                form_fields = form_fields.omit(field)
[13945]115        elif self.target is not None and self.target.startswith('ase'): # was putme
[9050]116            form_fields = grok.AutoFields(INigeriaUGApplicant)
117            for field in PUTME_OMIT_DISPLAY_FIELDS:
118                form_fields = form_fields.omit(field)
[10223]119        elif self.target is not None and self.target.startswith('pude'):
[9054]120            form_fields = grok.AutoFields(INigeriaUGApplicant)
121            for field in PUDE_OMIT_DISPLAY_FIELDS:
122                form_fields = form_fields.omit(field)
[9050]123        else:
124            form_fields = grok.AutoFields(INigeriaUGApplicant)
125            for field in UG_OMIT_DISPLAY_FIELDS:
126                form_fields = form_fields.omit(field)
[9072]127        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
[9054]128        form_fields['notice'].custom_widget = BytesDisplayWidget
[9076]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')
[10377]133        if not getattr(self.context, 'screening_venue') or self._not_paid():
[9076]134            form_fields = form_fields.omit('screening_venue')
[10377]135        if not getattr(self.context, 'screening_date') or self._not_paid():
[9076]136            form_fields = form_fields.omit('screening_date')
[9050]137        return form_fields
138
[8926]139class NigeriaPDFApplicationSlip(PDFApplicationSlip):
140
[10898]141    def _addLoginInformation(self):
142        """ We do no longer render login information on
143        pdf application slips.
144        """
145        return
146
[8926]147    def _reduced_slip(self):
148        return getattr(self.context, 'result_uploaded', False)
149
150    @property
151    def form_fields(self):
[10223]152        if self.target is not None and self.target.startswith('pg'):
[8926]153            form_fields = grok.AutoFields(INigeriaPGApplicant)
154            for field in PG_OMIT_PDF_FIELDS:
155                form_fields = form_fields.omit(field)
[13140]156        elif self.target is not None and self.target.startswith('pre'):
157            form_fields = grok.AutoFields(INigeriaPGApplicant)
[13277]158            for field in PRE_OMIT_PDF_FIELDS:
[13140]159                form_fields = form_fields.omit(field)
[14060]160        elif self.target is not None and self.target.startswith('cbt'): # uniben
[13142]161            form_fields = grok.AutoFields(INigeriaUGApplicant)
162            for field in CBT_OMIT_PDF_FIELDS:
163                form_fields = form_fields.omit(field)
[14062]164        elif self.target is not None and self.target.startswith('akj'): # uniben
165            form_fields = grok.AutoFields(INigeriaPGApplicant)
166            for field in PRE_OMIT_PDF_FIELDS:
167                form_fields = form_fields.omit(field)
[14060]168        elif self.target is not None and self.target.startswith('ak'): # uniben
[13551]169            form_fields = grok.AutoFields(INigeriaUGApplicant)
170            for field in AFFIL_OMIT_PDF_FIELDS:
171                form_fields = form_fields.omit(field)
[13945]172        elif self.target is not None and self.target.startswith('ase'): # was putme
[8926]173            form_fields = grok.AutoFields(INigeriaUGApplicant)
174            if self._reduced_slip():
[9049]175                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
[8926]176                    form_fields = form_fields.omit(field)
177            else:
[9049]178                for field in PUTME_OMIT_PDF_FIELDS:
[8926]179                    form_fields = form_fields.omit(field)
[10223]180        elif self.target is not None and self.target.startswith('pude'):
[9054]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)
[9049]188        else:
189            form_fields = grok.AutoFields(INigeriaUGApplicant)
190            for field in UG_OMIT_PDF_FIELDS:
191                form_fields = form_fields.omit(field)
[8926]192        if not getattr(self.context, 'student_id'):
193            form_fields = form_fields.omit('student_id')
[9076]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')
[8926]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):
[10223]208        if self.target is not None and self.target.startswith('pg'):
[8926]209            form_fields = grok.AutoFields(INigeriaPGApplicant)
210            for field in PG_OMIT_MANAGE_FIELDS:
211                form_fields = form_fields.omit(field)
[13140]212        elif self.target is not None and self.target.startswith('pre'):
213            form_fields = grok.AutoFields(INigeriaPGApplicant)
[13277]214            for field in PRE_OMIT_MANAGE_FIELDS:
[13140]215                form_fields = form_fields.omit(field)
[14060]216        elif self.target is not None and self.target.startswith('cbt'): # uniben
[13142]217            form_fields = grok.AutoFields(INigeriaUGApplicant)
218            for field in CBT_OMIT_MANAGE_FIELDS:
219                form_fields = form_fields.omit(field)
[14060]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
[13551]225            form_fields = grok.AutoFields(INigeriaUGApplicant)
226            for field in AFFIL_OMIT_MANAGE_FIELDS:
227                form_fields = form_fields.omit(field)
[13945]228        elif self.target is not None and self.target.startswith('ase'): # was putme
[9049]229            form_fields = grok.AutoFields(INigeriaUGApplicant)
230            for field in PUTME_OMIT_MANAGE_FIELDS:
231                form_fields = form_fields.omit(field)
[10223]232        elif self.target is not None and self.target.startswith('pude'):
[9054]233            form_fields = grok.AutoFields(INigeriaUGApplicant)
234            for field in PUDE_OMIT_MANAGE_FIELDS:
235                form_fields = form_fields.omit(field)
[8926]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):
[10223]250        if self.target is not None and self.target.startswith('pg'):
[8926]251            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
252            for field in PG_OMIT_EDIT_FIELDS:
253                form_fields = form_fields.omit(field)
[13140]254        elif self.target is not None and self.target.startswith('pre'):
[13155]255            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
[13277]256            for field in PRE_OMIT_EDIT_FIELDS:
[13140]257                form_fields = form_fields.omit(field)
[14060]258        elif self.target is not None and self.target.startswith('cbt'): # uniben
[13155]259            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
[13142]260            for field in CBT_OMIT_EDIT_FIELDS:
261                form_fields = form_fields.omit(field)
[14060]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
[13551]267            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
268            for field in AFFIL_OMIT_EDIT_FIELDS:
269                form_fields = form_fields.omit(field)
[13945]270        elif self.target is not None and self.target.startswith('ase'): # was putme
[14044]271            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
272            for field in PUTME_OMIT_EDIT_FIELDS:
273                form_fields = form_fields.omit(field)
[10223]274        elif self.target is not None and self.target.startswith('pude'):
[9482]275            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
[9054]276            for field in PUDE_OMIT_EDIT_FIELDS:
277                form_fields = form_fields.omit(field)
[8926]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)
[9985]290    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac',
291        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8926]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)
[9985]301    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit(
302        'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8926]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.