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

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

Payment slips must be printable in state 'paid'.

  • Property svn:keywords set to Id
File size: 8.2 KB
Line 
1## $Id: browser.py 15846 2019-11-25 13:29:09Z 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.p_state in ('paid', 'waived', 'scholarship') \
68            and not self.context.r_company:
69            return ''
70        return self.view.url(self.view.context, self.target)
71
72class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage):
73    """A display view for applicant data.
74    """
75
76    def _not_paid(self):
77        return self.context.state in ('initialized', 'started',)
78
79    @property
80    def form_fields(self):
81        if self.target is not None and self.target.startswith('pg'):
82            form_fields = grok.AutoFields(INigeriaPGApplicant)
83            for field in PG_OMIT_DISPLAY_FIELDS:
84                form_fields = form_fields.omit(field)
85        else:
86            form_fields = grok.AutoFields(INigeriaUGApplicant)
87            for field in UG_OMIT_DISPLAY_FIELDS:
88                form_fields = form_fields.omit(field)
89        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
90        form_fields['notice'].custom_widget = BytesDisplayWidget
91        if not getattr(self.context, 'student_id'):
92            form_fields = form_fields.omit('student_id')
93        if not getattr(self.context, 'screening_score'):
94            form_fields = form_fields.omit('screening_score')
95        if not getattr(self.context, 'screening_venue') or self._not_paid():
96            form_fields = form_fields.omit('screening_venue')
97        if not getattr(self.context, 'screening_date') or self._not_paid():
98            form_fields = form_fields.omit('screening_date')
99        return form_fields
100
101class NigeriaPDFApplicationSlip(PDFApplicationSlip):
102
103    def _addLoginInformation(self):
104        """ We do no longer render login information on
105        pdf application slips.
106        """
107        return
108
109    def _reduced_slip(self):
110        return getattr(self.context, 'result_uploaded', False)
111
112    @property
113    def form_fields(self):
114        if self.target is not None and self.target.startswith('pg'):
115            form_fields = grok.AutoFields(INigeriaPGApplicant)
116            for field in PG_OMIT_PDF_FIELDS:
117                form_fields = form_fields.omit(field)
118        else:
119            form_fields = grok.AutoFields(INigeriaUGApplicant)
120            for field in UG_OMIT_PDF_FIELDS:
121                form_fields = form_fields.omit(field)
122        if not getattr(self.context, 'student_id'):
123            form_fields = form_fields.omit('student_id')
124        if not getattr(self.context, 'screening_score'):
125            form_fields = form_fields.omit('screening_score')
126        if not getattr(self.context, 'screening_venue'):
127            form_fields = form_fields.omit('screening_venue')
128        if not getattr(self.context, 'screening_date'):
129            form_fields = form_fields.omit('screening_date')
130        return form_fields
131
132class NigeriaApplicantManageFormPage(ApplicantManageFormPage):
133    """A full edit view for applicant data.
134    """
135   
136    @property
137    def form_fields(self):
138        if self.target is not None and self.target.startswith('pg'):
139            form_fields = grok.AutoFields(INigeriaPGApplicant)
140            for field in PG_OMIT_MANAGE_FIELDS:
141                form_fields = form_fields.omit(field)
142        else:
143            form_fields = grok.AutoFields(INigeriaUGApplicant)
144            for field in UG_OMIT_MANAGE_FIELDS:
145                form_fields = form_fields.omit(field)
146        form_fields['student_id'].for_display = True
147        form_fields['applicant_id'].for_display = True
148        return form_fields
149
150class NigeriaApplicantEditFormPage(ApplicantEditFormPage):
151    """An applicant-centered edit view for applicant data.
152    """
153
154    @property
155    def form_fields(self):
156        if self.target is not None and self.target.startswith('pg'):
157            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
158            for field in PG_OMIT_EDIT_FIELDS:
159                form_fields = form_fields.omit(field)
160        else:
161            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
162            for field in UG_OMIT_EDIT_FIELDS:
163                form_fields = form_fields.omit(field)
164        form_fields['applicant_id'].for_display = True
165        form_fields['reg_number'].for_display = True
166        return form_fields
167
168class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
169    """ Page to view an online payment ticket
170    """
171    grok.context(INigeriaApplicantOnlinePayment)
172    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac',
173        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
174    form_fields[
175        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
176    form_fields[
177        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
178
179class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
180    """Deliver a PDF slip of the context.
181    """
182    grok.context(INigeriaApplicantOnlinePayment)
183    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit(
184        'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item',
185        'p_split_data')
186    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
187    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
188
189    @property
190    def payment_slip_download_warning(self):
191        return ''
192
193    def update(self):
194        if not self.context.p_state in ('paid', 'waived', 'scholarship') \
195            and not self.context.r_company:
196            self.redirect(self.url(self.context))
197            return
198        return
199
200class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage):
201    """Captcha'd registration page for applicants.
202    """
203
204    #def _redirect(self, email, password, applicant_id):
205    #    # Forward email and credentials to landing page.
206    #    self.redirect(self.url(self.context, 'registration_complete',
207    #        data = dict(email=email, password=password,
208    #        applicant_id=applicant_id)))
209    #    return
Note: See TracBrowser for help on using the repository browser.