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

Last change on this file since 15185 was 14827, checked in by Henrik Bettermann, 7 years ago

Revert changes from r18814.

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