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

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

Add tooltip.

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