source: main/kofacustom.nigeria/branches/0.1/src/kofacustom/nigeria/applicants/browser.py @ 17944

Last change on this file since 17944 was 10898, checked in by Henrik Bettermann, 11 years ago

Do no longer add login information on application slips.

  • Property svn:keywords set to Id
File size: 10.3 KB
Line 
1## $Id: browser.py 10898 2014-01-13 08:55:38Z 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.interfaces import (
27    IApplicantRegisterUpdate, IApplicant, IApplicantEdit)
28from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
29    ApplicantManageFormPage, ApplicantEditFormPage,
30    ApplicantRegistrationPage, ApplicantAddFormPage,
31    OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage,
32    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
33    ApplicantBaseDisplayFormPage)
34from waeup.kofa.applicants.viewlets import (
35    PaymentReceiptActionButton, PDFActionButton)
36from waeup.kofa.applicants.pdf import PDFApplicationSlip
37from kofacustom.nigeria.applicants.interfaces import (
38    INigeriaPGApplicant, INigeriaUGApplicant,
39    INigeriaPGApplicantEdit, INigeriaUGApplicantEdit,
40    INigeriaApplicantOnlinePayment,IPUTMEApplicantEdit,
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    PUTME_OMIT_DISPLAY_FIELDS,
50    PUTME_OMIT_PDF_FIELDS,
51    PUTME_OMIT_MANAGE_FIELDS,
52    PUTME_OMIT_EDIT_FIELDS,
53    PUTME_OMIT_RESULT_SLIP_FIELDS,
54    PUDE_OMIT_DISPLAY_FIELDS,
55    PUDE_OMIT_PDF_FIELDS,
56    PUDE_OMIT_MANAGE_FIELDS,
57    PUDE_OMIT_EDIT_FIELDS,
58    PUDE_OMIT_RESULT_SLIP_FIELDS,
59    )
60from kofacustom.nigeria.interfaces import MessageFactory as _
61
62class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
63    """A breadcrumb for payments.
64    """
65    grok.context(INigeriaApplicantOnlinePayment)
66
67class PDFActionButton(PDFActionButton):
68
69    @property
70    def text(self):
71        if getattr(self.context, 'result_uploaded', False):
72            return _('Download result slip')
73        return _('Download application slip')
74
75class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage):
76    """A display view for applicant data.
77    """
78
79    def _not_paid(self):
80        return self.context.state in ('initialized', 'started',)
81
82    @property
83    def form_fields(self):
84        if self.target is not None and self.target.startswith('pg'):
85            form_fields = grok.AutoFields(INigeriaPGApplicant)
86            for field in PG_OMIT_DISPLAY_FIELDS:
87                form_fields = form_fields.omit(field)
88        elif self.target is not None and self.target.startswith('putme'):
89            form_fields = grok.AutoFields(INigeriaUGApplicant)
90            for field in PUTME_OMIT_DISPLAY_FIELDS:
91                form_fields = form_fields.omit(field)
92        elif self.target is not None and self.target.startswith('pude'):
93            form_fields = grok.AutoFields(INigeriaUGApplicant)
94            for field in PUDE_OMIT_DISPLAY_FIELDS:
95                form_fields = form_fields.omit(field)
96        else:
97            form_fields = grok.AutoFields(INigeriaUGApplicant)
98            for field in UG_OMIT_DISPLAY_FIELDS:
99                form_fields = form_fields.omit(field)
100        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
101        form_fields['notice'].custom_widget = BytesDisplayWidget
102        if not getattr(self.context, 'student_id'):
103            form_fields = form_fields.omit('student_id')
104        if not getattr(self.context, 'screening_score'):
105            form_fields = form_fields.omit('screening_score')
106        if not getattr(self.context, 'screening_venue') or self._not_paid():
107            form_fields = form_fields.omit('screening_venue')
108        if not getattr(self.context, 'screening_date') or self._not_paid():
109            form_fields = form_fields.omit('screening_date')
110        return form_fields
111
112class NigeriaPDFApplicationSlip(PDFApplicationSlip):
113
114    def _addLoginInformation(self):
115        """ We do no longer render login information on
116        pdf application slips.
117        """
118        return
119
120    def _reduced_slip(self):
121        return getattr(self.context, 'result_uploaded', False)
122
123    @property
124    def form_fields(self):
125        if self.target is not None and self.target.startswith('pg'):
126            form_fields = grok.AutoFields(INigeriaPGApplicant)
127            for field in PG_OMIT_PDF_FIELDS:
128                form_fields = form_fields.omit(field)
129        elif self.target is not None and self.target.startswith('putme'):
130            form_fields = grok.AutoFields(INigeriaUGApplicant)
131            if self._reduced_slip():
132                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
133                    form_fields = form_fields.omit(field)
134            else:
135                for field in PUTME_OMIT_PDF_FIELDS:
136                    form_fields = form_fields.omit(field)
137        elif self.target is not None and self.target.startswith('pude'):
138            form_fields = grok.AutoFields(INigeriaUGApplicant)
139            if self._reduced_slip():
140                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
141                    form_fields = form_fields.omit(field)
142            else:
143                for field in PUDE_OMIT_PDF_FIELDS:
144                    form_fields = form_fields.omit(field)
145        else:
146            form_fields = grok.AutoFields(INigeriaUGApplicant)
147            for field in UG_OMIT_PDF_FIELDS:
148                form_fields = form_fields.omit(field)
149        if not getattr(self.context, 'student_id'):
150            form_fields = form_fields.omit('student_id')
151        if not getattr(self.context, 'screening_score'):
152            form_fields = form_fields.omit('screening_score')
153        if not getattr(self.context, 'screening_venue'):
154            form_fields = form_fields.omit('screening_venue')
155        if not getattr(self.context, 'screening_date'):
156            form_fields = form_fields.omit('screening_date')
157        return form_fields
158
159class NigeriaApplicantManageFormPage(ApplicantManageFormPage):
160    """A full edit view for applicant data.
161    """
162   
163    @property
164    def form_fields(self):
165        if self.target is not None and self.target.startswith('pg'):
166            form_fields = grok.AutoFields(INigeriaPGApplicant)
167            for field in PG_OMIT_MANAGE_FIELDS:
168                form_fields = form_fields.omit(field)
169        elif self.target is not None and self.target.startswith('putme'):
170            form_fields = grok.AutoFields(INigeriaUGApplicant)
171            for field in PUTME_OMIT_MANAGE_FIELDS:
172                form_fields = form_fields.omit(field)
173        elif self.target is not None and self.target.startswith('pude'):
174            form_fields = grok.AutoFields(INigeriaUGApplicant)
175            for field in PUDE_OMIT_MANAGE_FIELDS:
176                form_fields = form_fields.omit(field)
177        else:
178            form_fields = grok.AutoFields(INigeriaUGApplicant)
179            for field in UG_OMIT_MANAGE_FIELDS:
180                form_fields = form_fields.omit(field)
181        form_fields['student_id'].for_display = True
182        form_fields['applicant_id'].for_display = True
183        return form_fields
184
185class NigeriaApplicantEditFormPage(ApplicantEditFormPage):
186    """An applicant-centered edit view for applicant data.
187    """
188
189    @property
190    def form_fields(self):
191        if self.target is not None and self.target.startswith('pg'):
192            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
193            for field in PG_OMIT_EDIT_FIELDS:
194                form_fields = form_fields.omit(field)
195        elif self.target is not None and self.target.startswith('putme'):
196            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
197            for field in PUTME_OMIT_EDIT_FIELDS:
198                form_fields = form_fields.omit(field)
199        elif self.target is not None and self.target.startswith('pude'):
200            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
201            for field in PUDE_OMIT_EDIT_FIELDS:
202                form_fields = form_fields.omit(field)
203        else:
204            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
205            for field in UG_OMIT_EDIT_FIELDS:
206                form_fields = form_fields.omit(field)
207        form_fields['applicant_id'].for_display = True
208        form_fields['reg_number'].for_display = True
209        return form_fields
210
211class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
212    """ Page to view an online payment ticket
213    """
214    grok.context(INigeriaApplicantOnlinePayment)
215    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac',
216        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
217    form_fields[
218        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
219    form_fields[
220        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
221
222class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
223    """Deliver a PDF slip of the context.
224    """
225    grok.context(INigeriaApplicantOnlinePayment)
226    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit(
227        'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
228    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
229    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
230
231class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage):
232    """Captcha'd registration page for applicants.
233    """
234
235    #def _redirect(self, email, password, applicant_id):
236    #    # Forward email and credentials to landing page.
237    #    self.redirect(self.url(self.context, 'registration_complete',
238    #        data = dict(email=email, password=password,
239    #        applicant_id=applicant_id)))
240    #    return
Note: See TracBrowser for help on using the repository browser.