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

Last change on this file since 15801 was 15796, checked in by Henrik Bettermann, 5 years ago

Payment slip must not be downloadable before adding surcharges.

  • Property svn:keywords set to Id
File size: 8.1 KB
RevLine 
[8926]1## $Id: browser.py 15796 2019-11-12 08:23:13Z 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.browser import (ApplicantDisplayFormPage,
27    ApplicantManageFormPage, ApplicantEditFormPage,
[14093]28    ApplicantRegistrationPage,
29    OnlinePaymentDisplayFormPage,
[8926]30    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
[14093]31    )
[8926]32from waeup.kofa.applicants.viewlets import (
[15796]33    PDFActionButton, PaymentReceiptActionButton)
[8926]34from waeup.kofa.applicants.pdf import PDFApplicationSlip
35from kofacustom.nigeria.applicants.interfaces import (
36    INigeriaPGApplicant, INigeriaUGApplicant,
37    INigeriaPGApplicantEdit, INigeriaUGApplicantEdit,
[14093]38    INigeriaApplicantOnlinePayment,
[9054]39    UG_OMIT_DISPLAY_FIELDS,
40    UG_OMIT_PDF_FIELDS,
41    UG_OMIT_MANAGE_FIELDS,
42    UG_OMIT_EDIT_FIELDS,
43    PG_OMIT_DISPLAY_FIELDS,
44    PG_OMIT_PDF_FIELDS,
45    PG_OMIT_MANAGE_FIELDS,
46    PG_OMIT_EDIT_FIELDS,
47    )
[8926]48from kofacustom.nigeria.interfaces import MessageFactory as _
49
50class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
51    """A breadcrumb for payments.
52    """
53    grok.context(INigeriaApplicantOnlinePayment)
54
55class PDFActionButton(PDFActionButton):
56
57    @property
58    def text(self):
59        if getattr(self.context, 'result_uploaded', False):
60            return _('Download result slip')
61        return _('Download application slip')
62
[15796]63class PaymentReceiptActionButton(PaymentReceiptActionButton):
64
65    @property
66    def target_url(self):
67        if not self.context.r_company:
68            return ''
69        return self.view.url(self.view.context, self.target)
70
[9050]71class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage):
72    """A display view for applicant data.
73    """
[8926]74
[10377]75    def _not_paid(self):
76        return self.context.state in ('initialized', 'started',)
77
[9050]78    @property
79    def form_fields(self):
[10223]80        if self.target is not None and self.target.startswith('pg'):
[9050]81            form_fields = grok.AutoFields(INigeriaPGApplicant)
82            for field in PG_OMIT_DISPLAY_FIELDS:
83                form_fields = form_fields.omit(field)
84        else:
85            form_fields = grok.AutoFields(INigeriaUGApplicant)
86            for field in UG_OMIT_DISPLAY_FIELDS:
87                form_fields = form_fields.omit(field)
[9072]88        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
[9054]89        form_fields['notice'].custom_widget = BytesDisplayWidget
[9076]90        if not getattr(self.context, 'student_id'):
91            form_fields = form_fields.omit('student_id')
92        if not getattr(self.context, 'screening_score'):
93            form_fields = form_fields.omit('screening_score')
[10377]94        if not getattr(self.context, 'screening_venue') or self._not_paid():
[9076]95            form_fields = form_fields.omit('screening_venue')
[10377]96        if not getattr(self.context, 'screening_date') or self._not_paid():
[9076]97            form_fields = form_fields.omit('screening_date')
[9050]98        return form_fields
99
[8926]100class NigeriaPDFApplicationSlip(PDFApplicationSlip):
101
[10898]102    def _addLoginInformation(self):
103        """ We do no longer render login information on
104        pdf application slips.
105        """
106        return
107
[8926]108    def _reduced_slip(self):
109        return getattr(self.context, 'result_uploaded', False)
110
111    @property
112    def form_fields(self):
[10223]113        if self.target is not None and self.target.startswith('pg'):
[8926]114            form_fields = grok.AutoFields(INigeriaPGApplicant)
115            for field in PG_OMIT_PDF_FIELDS:
116                form_fields = form_fields.omit(field)
[9049]117        else:
118            form_fields = grok.AutoFields(INigeriaUGApplicant)
119            for field in UG_OMIT_PDF_FIELDS:
120                form_fields = form_fields.omit(field)
[8926]121        if not getattr(self.context, 'student_id'):
122            form_fields = form_fields.omit('student_id')
[9076]123        if not getattr(self.context, 'screening_score'):
124            form_fields = form_fields.omit('screening_score')
125        if not getattr(self.context, 'screening_venue'):
126            form_fields = form_fields.omit('screening_venue')
127        if not getattr(self.context, 'screening_date'):
128            form_fields = form_fields.omit('screening_date')
[8926]129        return form_fields
130
131class NigeriaApplicantManageFormPage(ApplicantManageFormPage):
132    """A full edit view for applicant data.
133    """
134   
135    @property
136    def form_fields(self):
[10223]137        if self.target is not None and self.target.startswith('pg'):
[8926]138            form_fields = grok.AutoFields(INigeriaPGApplicant)
139            for field in PG_OMIT_MANAGE_FIELDS:
140                form_fields = form_fields.omit(field)
141        else:
142            form_fields = grok.AutoFields(INigeriaUGApplicant)
143            for field in UG_OMIT_MANAGE_FIELDS:
144                form_fields = form_fields.omit(field)
145        form_fields['student_id'].for_display = True
146        form_fields['applicant_id'].for_display = True
147        return form_fields
148
149class NigeriaApplicantEditFormPage(ApplicantEditFormPage):
150    """An applicant-centered edit view for applicant data.
151    """
152
153    @property
154    def form_fields(self):
[10223]155        if self.target is not None and self.target.startswith('pg'):
[8926]156            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
157            for field in PG_OMIT_EDIT_FIELDS:
158                form_fields = form_fields.omit(field)
159        else:
160            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
161            for field in UG_OMIT_EDIT_FIELDS:
162                form_fields = form_fields.omit(field)
163        form_fields['applicant_id'].for_display = True
164        form_fields['reg_number'].for_display = True
165        return form_fields
166
167class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
168    """ Page to view an online payment ticket
169    """
170    grok.context(INigeriaApplicantOnlinePayment)
[9985]171    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac',
172        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8926]173    form_fields[
174        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
175    form_fields[
176        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
177
178class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
179    """Deliver a PDF slip of the context.
180    """
181    grok.context(INigeriaApplicantOnlinePayment)
[9985]182    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit(
[15472]183        'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item',
184        'p_split_data')
[8926]185    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
186    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
187
[15796]188    @property
189    def payment_slip_download_warning(self):
190        return ''
191
192    def update(self):
193        if not self.context.r_company:
194            self.redirect(self.url(self.context))
195            return
196        return
197
[8926]198class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage):
199    """Captcha'd registration page for applicants.
200    """
201
202    #def _redirect(self, email, password, applicant_id):
203    #    # Forward email and credentials to landing page.
204    #    self.redirect(self.url(self.context, 'registration_complete',
205    #        data = dict(email=email, password=password,
206    #        applicant_id=applicant_id)))
207    #    return
Note: See TracBrowser for help on using the repository browser.