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

Last change on this file since 13140 was 13140, checked in by Henrik Bettermann, 9 years ago

Enable pre-studies (JUPEB) application (Uniben).

Extend pg application form.

  • Property svn:keywords set to Id
File size: 11.4 KB
Line 
1## $Id: browser.py 13140 2015-07-05 15:10: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 (
27    IApplicantRegisterUpdate, IApplicant, IApplicantEdit)
28from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
29    ApplicantManageFormPage, ApplicantEditFormPage,
30    ApplicantRegistrationPage, ApplicantAddFormPage,
31    OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage,
32    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
33    ApplicantBaseDisplayFormPage)
34from waeup.kofa.applicants.viewlets import (
35    PaymentReceiptActionButton, PDFActionButton)
36from waeup.kofa.applicants.pdf import PDFApplicationSlip
37from kofacustom.nigeria.applicants.interfaces import (
38    INigeriaPGApplicant, INigeriaUGApplicant,
39    INigeriaPGApplicantEdit, INigeriaUGApplicantEdit,
40    INigeriaApplicantOnlinePayment,IPUTMEApplicantEdit,
41    UG_OMIT_DISPLAY_FIELDS,
42    UG_OMIT_PDF_FIELDS,
43    UG_OMIT_MANAGE_FIELDS,
44    UG_OMIT_EDIT_FIELDS,
45    PG_OMIT_DISPLAY_FIELDS,
46    PG_OMIT_PDF_FIELDS,
47    PG_OMIT_MANAGE_FIELDS,
48    PG_OMIT_EDIT_FIELDS,
49    PUTME_OMIT_DISPLAY_FIELDS,
50    PUTME_OMIT_PDF_FIELDS,
51    PUTME_OMIT_MANAGE_FIELDS,
52    PUTME_OMIT_EDIT_FIELDS,
53    PUTME_OMIT_RESULT_SLIP_FIELDS,
54    PUDE_OMIT_DISPLAY_FIELDS,
55    PUDE_OMIT_PDF_FIELDS,
56    PUDE_OMIT_MANAGE_FIELDS,
57    PUDE_OMIT_EDIT_FIELDS,
58    PUDE_OMIT_RESULT_SLIP_FIELDS,
59    )
60from kofacustom.nigeria.interfaces import MessageFactory as _
61
62class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
63    """A breadcrumb for payments.
64    """
65    grok.context(INigeriaApplicantOnlinePayment)
66
67class PDFActionButton(PDFActionButton):
68
69    @property
70    def text(self):
71        if getattr(self.context, 'result_uploaded', False):
72            return _('Download result slip')
73        return _('Download application slip')
74
75class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage):
76    """A display view for applicant data.
77    """
78
79    def _not_paid(self):
80        return self.context.state in ('initialized', 'started',)
81
82    @property
83    def form_fields(self):
84        if self.target is not None and self.target.startswith('pg'):
85            form_fields = grok.AutoFields(INigeriaPGApplicant)
86            for field in PG_OMIT_DISPLAY_FIELDS:
87                form_fields = form_fields.omit(field)
88        # Don't know what pre-degree studies are, seems to be pre-postgraduate.
89        # Many modifications are expected. Therefore, we need a dedicated
90        # elif statement (see also pages below)
91        elif self.target is not None and self.target.startswith('pre'):
92            form_fields = grok.AutoFields(INigeriaPGApplicant)
93            for field in PG_OMIT_DISPLAY_FIELDS:
94                form_fields = form_fields.omit(field)
95        elif self.target is not None and self.target.startswith('putme'):
96            form_fields = grok.AutoFields(INigeriaUGApplicant)
97            for field in PUTME_OMIT_DISPLAY_FIELDS:
98                form_fields = form_fields.omit(field)
99        elif self.target is not None and self.target.startswith('pude'):
100            form_fields = grok.AutoFields(INigeriaUGApplicant)
101            for field in PUDE_OMIT_DISPLAY_FIELDS:
102                form_fields = form_fields.omit(field)
103        else:
104            form_fields = grok.AutoFields(INigeriaUGApplicant)
105            for field in UG_OMIT_DISPLAY_FIELDS:
106                form_fields = form_fields.omit(field)
107        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
108        form_fields['notice'].custom_widget = BytesDisplayWidget
109        if not getattr(self.context, 'student_id'):
110            form_fields = form_fields.omit('student_id')
111        if not getattr(self.context, 'screening_score'):
112            form_fields = form_fields.omit('screening_score')
113        if not getattr(self.context, 'screening_venue') or self._not_paid():
114            form_fields = form_fields.omit('screening_venue')
115        if not getattr(self.context, 'screening_date') or self._not_paid():
116            form_fields = form_fields.omit('screening_date')
117        return form_fields
118
119class NigeriaPDFApplicationSlip(PDFApplicationSlip):
120
121    def _addLoginInformation(self):
122        """ We do no longer render login information on
123        pdf application slips.
124        """
125        return
126
127    def _reduced_slip(self):
128        return getattr(self.context, 'result_uploaded', False)
129
130    @property
131    def form_fields(self):
132        if self.target is not None and self.target.startswith('pg'):
133            form_fields = grok.AutoFields(INigeriaPGApplicant)
134            for field in PG_OMIT_PDF_FIELDS:
135                form_fields = form_fields.omit(field)
136        elif self.target is not None and self.target.startswith('pre'):
137            form_fields = grok.AutoFields(INigeriaPGApplicant)
138            for field in PG_OMIT_PDF_FIELDS:
139                form_fields = form_fields.omit(field)
140        elif self.target is not None and self.target.startswith('putme'):
141            form_fields = grok.AutoFields(INigeriaUGApplicant)
142            if self._reduced_slip():
143                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
144                    form_fields = form_fields.omit(field)
145            else:
146                for field in PUTME_OMIT_PDF_FIELDS:
147                    form_fields = form_fields.omit(field)
148        elif self.target is not None and self.target.startswith('pude'):
149            form_fields = grok.AutoFields(INigeriaUGApplicant)
150            if self._reduced_slip():
151                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
152                    form_fields = form_fields.omit(field)
153            else:
154                for field in PUDE_OMIT_PDF_FIELDS:
155                    form_fields = form_fields.omit(field)
156        else:
157            form_fields = grok.AutoFields(INigeriaUGApplicant)
158            for field in UG_OMIT_PDF_FIELDS:
159                form_fields = form_fields.omit(field)
160        if not getattr(self.context, 'student_id'):
161            form_fields = form_fields.omit('student_id')
162        if not getattr(self.context, 'screening_score'):
163            form_fields = form_fields.omit('screening_score')
164        if not getattr(self.context, 'screening_venue'):
165            form_fields = form_fields.omit('screening_venue')
166        if not getattr(self.context, 'screening_date'):
167            form_fields = form_fields.omit('screening_date')
168        return form_fields
169
170class NigeriaApplicantManageFormPage(ApplicantManageFormPage):
171    """A full edit view for applicant data.
172    """
173   
174    @property
175    def form_fields(self):
176        if self.target is not None and self.target.startswith('pg'):
177            form_fields = grok.AutoFields(INigeriaPGApplicant)
178            for field in PG_OMIT_MANAGE_FIELDS:
179                form_fields = form_fields.omit(field)
180        elif self.target is not None and self.target.startswith('pre'):
181            form_fields = grok.AutoFields(INigeriaPGApplicant)
182            for field in PG_OMIT_MANAGE_FIELDS:
183                form_fields = form_fields.omit(field)
184        elif self.target is not None and self.target.startswith('putme'):
185            form_fields = grok.AutoFields(INigeriaUGApplicant)
186            for field in PUTME_OMIT_MANAGE_FIELDS:
187                form_fields = form_fields.omit(field)
188        elif self.target is not None and self.target.startswith('pude'):
189            form_fields = grok.AutoFields(INigeriaUGApplicant)
190            for field in PUDE_OMIT_MANAGE_FIELDS:
191                form_fields = form_fields.omit(field)
192        else:
193            form_fields = grok.AutoFields(INigeriaUGApplicant)
194            for field in UG_OMIT_MANAGE_FIELDS:
195                form_fields = form_fields.omit(field)
196        form_fields['student_id'].for_display = True
197        form_fields['applicant_id'].for_display = True
198        return form_fields
199
200class NigeriaApplicantEditFormPage(ApplicantEditFormPage):
201    """An applicant-centered edit view for applicant data.
202    """
203
204    @property
205    def form_fields(self):
206        if self.target is not None and self.target.startswith('pg'):
207            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
208            for field in PG_OMIT_EDIT_FIELDS:
209                form_fields = form_fields.omit(field)
210        elif self.target is not None and self.target.startswith('pre'):
211            form_fields = grok.AutoFields(INigeriaPGApplicant)
212            for field in PG_OMIT_EDIT_FIELDS:
213                form_fields = form_fields.omit(field)
214        elif self.target is not None and self.target.startswith('putme'):
215            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
216            for field in PUTME_OMIT_EDIT_FIELDS:
217                form_fields = form_fields.omit(field)
218        elif self.target is not None and self.target.startswith('pude'):
219            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
220            for field in PUDE_OMIT_EDIT_FIELDS:
221                form_fields = form_fields.omit(field)
222        else:
223            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
224            for field in UG_OMIT_EDIT_FIELDS:
225                form_fields = form_fields.omit(field)
226        form_fields['applicant_id'].for_display = True
227        form_fields['reg_number'].for_display = True
228        return form_fields
229
230class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
231    """ Page to view an online payment ticket
232    """
233    grok.context(INigeriaApplicantOnlinePayment)
234    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac',
235        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
236    form_fields[
237        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
238    form_fields[
239        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
240
241class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
242    """Deliver a PDF slip of the context.
243    """
244    grok.context(INigeriaApplicantOnlinePayment)
245    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit(
246        'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
247    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
248    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
249
250class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage):
251    """Captcha'd registration page for applicants.
252    """
253
254    #def _redirect(self, email, password, applicant_id):
255    #    # Forward email and credentials to landing page.
256    #    self.redirect(self.url(self.context, 'registration_complete',
257    #        data = dict(email=email, password=password,
258    #        applicant_id=applicant_id)))
259    #    return
Note: See TracBrowser for help on using the repository browser.