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

Last change on this file since 15796 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
Line 
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
24from zope.formlib.textwidgets import BytesDisplayWidget
25from waeup.kofa.students.interfaces import IStudentsUtils
26from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
27    ApplicantManageFormPage, ApplicantEditFormPage,
28    ApplicantRegistrationPage,
29    OnlinePaymentDisplayFormPage,
30    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
31    )
32from waeup.kofa.applicants.viewlets import (
33    PDFActionButton, PaymentReceiptActionButton)
34from waeup.kofa.applicants.pdf import PDFApplicationSlip
35from kofacustom.nigeria.applicants.interfaces import (
36    INigeriaPGApplicant, INigeriaUGApplicant,
37    INigeriaPGApplicantEdit, INigeriaUGApplicantEdit,
38    INigeriaApplicantOnlinePayment,
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    )
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
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
71class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage):
72    """A display view for applicant data.
73    """
74
75    def _not_paid(self):
76        return self.context.state in ('initialized', 'started',)
77
78    @property
79    def form_fields(self):
80        if self.target is not None and self.target.startswith('pg'):
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)
88        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
89        form_fields['notice'].custom_widget = BytesDisplayWidget
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')
94        if not getattr(self.context, 'screening_venue') or self._not_paid():
95            form_fields = form_fields.omit('screening_venue')
96        if not getattr(self.context, 'screening_date') or self._not_paid():
97            form_fields = form_fields.omit('screening_date')
98        return form_fields
99
100class NigeriaPDFApplicationSlip(PDFApplicationSlip):
101
102    def _addLoginInformation(self):
103        """ We do no longer render login information on
104        pdf application slips.
105        """
106        return
107
108    def _reduced_slip(self):
109        return getattr(self.context, 'result_uploaded', False)
110
111    @property
112    def form_fields(self):
113        if self.target is not None and self.target.startswith('pg'):
114            form_fields = grok.AutoFields(INigeriaPGApplicant)
115            for field in PG_OMIT_PDF_FIELDS:
116                form_fields = form_fields.omit(field)
117        else:
118            form_fields = grok.AutoFields(INigeriaUGApplicant)
119            for field in UG_OMIT_PDF_FIELDS:
120                form_fields = form_fields.omit(field)
121        if not getattr(self.context, 'student_id'):
122            form_fields = form_fields.omit('student_id')
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')
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):
137        if self.target is not None and self.target.startswith('pg'):
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):
155        if self.target is not None and self.target.startswith('pg'):
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)
171    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac',
172        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
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)
182    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit(
183        'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item',
184        'p_split_data')
185    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
186    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
187
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
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.