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

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

Shorten prefix again.

  • Property svn:keywords set to Id
File size: 13.4 KB
RevLine 
[8926]1## $Id: browser.py 13556 2015-12-21 15:08:12Z 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
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,
[9049]40    INigeriaApplicantOnlinePayment,IPUTMEApplicantEdit,
[9054]41    UG_OMIT_DISPLAY_FIELDS,
42    UG_OMIT_PDF_FIELDS,
43    UG_OMIT_MANAGE_FIELDS,
44    UG_OMIT_EDIT_FIELDS,
[13142]45    CBT_OMIT_DISPLAY_FIELDS,
46    CBT_OMIT_PDF_FIELDS,
47    CBT_OMIT_MANAGE_FIELDS,
48    CBT_OMIT_EDIT_FIELDS,
[13551]49    AFFIL_OMIT_DISPLAY_FIELDS,
50    AFFIL_OMIT_PDF_FIELDS,
51    AFFIL_OMIT_MANAGE_FIELDS,
52    AFFIL_OMIT_EDIT_FIELDS,
[9054]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,
[13277]67    PRE_OMIT_DISPLAY_FIELDS,
68    PRE_OMIT_PDF_FIELDS,
69    PRE_OMIT_MANAGE_FIELDS,
70    PRE_OMIT_EDIT_FIELDS,
[9054]71    )
[8926]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
[9050]87class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage):
88    """A display view for applicant data.
89    """
[8926]90
[10377]91    def _not_paid(self):
92        return self.context.state in ('initialized', 'started',)
93
[9050]94    @property
95    def form_fields(self):
[10223]96        if self.target is not None and self.target.startswith('pg'):
[9050]97            form_fields = grok.AutoFields(INigeriaPGApplicant)
98            for field in PG_OMIT_DISPLAY_FIELDS:
99                form_fields = form_fields.omit(field)
[13140]100        elif self.target is not None and self.target.startswith('pre'):
101            form_fields = grok.AutoFields(INigeriaPGApplicant)
[13277]102            for field in PRE_OMIT_DISPLAY_FIELDS:
[13140]103                form_fields = form_fields.omit(field)
[13142]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)
[13556]108        elif self.target is not None and self.target.startswith('af'):
[13551]109            form_fields = grok.AutoFields(INigeriaUGApplicant)
110            for field in AFFIL_OMIT_DISPLAY_FIELDS:
111                form_fields = form_fields.omit(field)
[10223]112        elif self.target is not None and self.target.startswith('putme'):
[9050]113            form_fields = grok.AutoFields(INigeriaUGApplicant)
114            for field in PUTME_OMIT_DISPLAY_FIELDS:
115                form_fields = form_fields.omit(field)
[10223]116        elif self.target is not None and self.target.startswith('pude'):
[9054]117            form_fields = grok.AutoFields(INigeriaUGApplicant)
118            for field in PUDE_OMIT_DISPLAY_FIELDS:
119                form_fields = form_fields.omit(field)
[9050]120        else:
121            form_fields = grok.AutoFields(INigeriaUGApplicant)
122            for field in UG_OMIT_DISPLAY_FIELDS:
123                form_fields = form_fields.omit(field)
[9072]124        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
[9054]125        form_fields['notice'].custom_widget = BytesDisplayWidget
[9076]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')
[10377]130        if not getattr(self.context, 'screening_venue') or self._not_paid():
[9076]131            form_fields = form_fields.omit('screening_venue')
[10377]132        if not getattr(self.context, 'screening_date') or self._not_paid():
[9076]133            form_fields = form_fields.omit('screening_date')
[9050]134        return form_fields
135
[8926]136class NigeriaPDFApplicationSlip(PDFApplicationSlip):
137
[10898]138    def _addLoginInformation(self):
139        """ We do no longer render login information on
140        pdf application slips.
141        """
142        return
143
[8926]144    def _reduced_slip(self):
145        return getattr(self.context, 'result_uploaded', False)
146
147    @property
148    def form_fields(self):
[10223]149        if self.target is not None and self.target.startswith('pg'):
[8926]150            form_fields = grok.AutoFields(INigeriaPGApplicant)
151            for field in PG_OMIT_PDF_FIELDS:
152                form_fields = form_fields.omit(field)
[13140]153        elif self.target is not None and self.target.startswith('pre'):
154            form_fields = grok.AutoFields(INigeriaPGApplicant)
[13277]155            for field in PRE_OMIT_PDF_FIELDS:
[13140]156                form_fields = form_fields.omit(field)
[13142]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)
[13556]161        elif self.target is not None and self.target.startswith('af'):
[13551]162            form_fields = grok.AutoFields(INigeriaUGApplicant)
163            for field in AFFIL_OMIT_PDF_FIELDS:
164                form_fields = form_fields.omit(field)
[10223]165        elif self.target is not None and self.target.startswith('putme'):
[8926]166            form_fields = grok.AutoFields(INigeriaUGApplicant)
167            if self._reduced_slip():
[9049]168                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
[8926]169                    form_fields = form_fields.omit(field)
170            else:
[9049]171                for field in PUTME_OMIT_PDF_FIELDS:
[8926]172                    form_fields = form_fields.omit(field)
[10223]173        elif self.target is not None and self.target.startswith('pude'):
[9054]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)
[9049]181        else:
182            form_fields = grok.AutoFields(INigeriaUGApplicant)
183            for field in UG_OMIT_PDF_FIELDS:
184                form_fields = form_fields.omit(field)
[8926]185        if not getattr(self.context, 'student_id'):
186            form_fields = form_fields.omit('student_id')
[9076]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')
[8926]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):
[10223]201        if self.target is not None and self.target.startswith('pg'):
[8926]202            form_fields = grok.AutoFields(INigeriaPGApplicant)
203            for field in PG_OMIT_MANAGE_FIELDS:
204                form_fields = form_fields.omit(field)
[13140]205        elif self.target is not None and self.target.startswith('pre'):
206            form_fields = grok.AutoFields(INigeriaPGApplicant)
[13277]207            for field in PRE_OMIT_MANAGE_FIELDS:
[13140]208                form_fields = form_fields.omit(field)
[13142]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)
[13556]213        elif self.target is not None and self.target.startswith('af'):
[13551]214            form_fields = grok.AutoFields(INigeriaUGApplicant)
215            for field in AFFIL_OMIT_MANAGE_FIELDS:
216                form_fields = form_fields.omit(field)
[10223]217        elif self.target is not None and self.target.startswith('putme'):
[9049]218            form_fields = grok.AutoFields(INigeriaUGApplicant)
219            for field in PUTME_OMIT_MANAGE_FIELDS:
220                form_fields = form_fields.omit(field)
[10223]221        elif self.target is not None and self.target.startswith('pude'):
[9054]222            form_fields = grok.AutoFields(INigeriaUGApplicant)
223            for field in PUDE_OMIT_MANAGE_FIELDS:
224                form_fields = form_fields.omit(field)
[8926]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):
[10223]239        if self.target is not None and self.target.startswith('pg'):
[8926]240            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
241            for field in PG_OMIT_EDIT_FIELDS:
242                form_fields = form_fields.omit(field)
[13140]243        elif self.target is not None and self.target.startswith('pre'):
[13155]244            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
[13277]245            for field in PRE_OMIT_EDIT_FIELDS:
[13140]246                form_fields = form_fields.omit(field)
[13142]247        elif self.target is not None and self.target.startswith('cbt'):
[13155]248            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
[13142]249            for field in CBT_OMIT_EDIT_FIELDS:
250                form_fields = form_fields.omit(field)
[13556]251        elif self.target is not None and self.target.startswith('af'):
[13551]252            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
253            for field in AFFIL_OMIT_EDIT_FIELDS:
254                form_fields = form_fields.omit(field)
[10223]255        elif self.target is not None and self.target.startswith('putme'):
[8926]256            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
257            for field in PUTME_OMIT_EDIT_FIELDS:
258                form_fields = form_fields.omit(field)
[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.