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

Last change on this file since 17936 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
RevLine 
[8926]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
[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):
[15846]67        if not self.context.p_state in ('paid', 'waived', 'scholarship') \
[15842]68            and not self.context.r_company:
[15796]69            return ''
70        return self.view.url(self.view.context, self.target)
71
[9050]72class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage):
73    """A display view for applicant data.
74    """
[8926]75
[10377]76    def _not_paid(self):
77        return self.context.state in ('initialized', 'started',)
78
[9050]79    @property
80    def form_fields(self):
[10223]81        if self.target is not None and self.target.startswith('pg'):
[9050]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)
[9072]89        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
[9054]90        form_fields['notice'].custom_widget = BytesDisplayWidget
[9076]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')
[10377]95        if not getattr(self.context, 'screening_venue') or self._not_paid():
[9076]96            form_fields = form_fields.omit('screening_venue')
[10377]97        if not getattr(self.context, 'screening_date') or self._not_paid():
[9076]98            form_fields = form_fields.omit('screening_date')
[9050]99        return form_fields
100
[8926]101class NigeriaPDFApplicationSlip(PDFApplicationSlip):
102
[10898]103    def _addLoginInformation(self):
104        """ We do no longer render login information on
105        pdf application slips.
106        """
107        return
108
[8926]109    def _reduced_slip(self):
110        return getattr(self.context, 'result_uploaded', False)
111
112    @property
113    def form_fields(self):
[10223]114        if self.target is not None and self.target.startswith('pg'):
[8926]115            form_fields = grok.AutoFields(INigeriaPGApplicant)
116            for field in PG_OMIT_PDF_FIELDS:
117                form_fields = form_fields.omit(field)
[9049]118        else:
119            form_fields = grok.AutoFields(INigeriaUGApplicant)
120            for field in UG_OMIT_PDF_FIELDS:
121                form_fields = form_fields.omit(field)
[8926]122        if not getattr(self.context, 'student_id'):
123            form_fields = form_fields.omit('student_id')
[9076]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')
[8926]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):
[10223]138        if self.target is not None and self.target.startswith('pg'):
[8926]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):
[10223]156        if self.target is not None and self.target.startswith('pg'):
[8926]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)
[9985]172    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac',
173        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8926]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)
[9985]183    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit(
[15472]184        'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item',
185        'p_split_data')
[8926]186    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
187    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
188
[15796]189    @property
190    def payment_slip_download_warning(self):
191        return ''
192
193    def update(self):
[15846]194        if not self.context.p_state in ('paid', 'waived', 'scholarship') \
[15844]195            and not self.context.r_company:
[15796]196            self.redirect(self.url(self.context))
197            return
198        return
199
[8926]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.