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

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

Define and use PRE_OMIT_FIELDS.

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