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

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

Remove unused import.

  • Property svn:keywords set to Id
File size: 10.2 KB
Line 
1## $Id: browser.py 10573 2013-08-31 15:02:33Z 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 _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        elif self.target is not None and self.target.startswith('putme'):
124            form_fields = grok.AutoFields(INigeriaUGApplicant)
125            if self._reduced_slip():
126                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
127                    form_fields = form_fields.omit(field)
128            else:
129                for field in PUTME_OMIT_PDF_FIELDS:
130                    form_fields = form_fields.omit(field)
131        elif self.target is not None and self.target.startswith('pude'):
132            form_fields = grok.AutoFields(INigeriaUGApplicant)
133            if self._reduced_slip():
134                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
135                    form_fields = form_fields.omit(field)
136            else:
137                for field in PUDE_OMIT_PDF_FIELDS:
138                    form_fields = form_fields.omit(field)
139        else:
140            form_fields = grok.AutoFields(INigeriaUGApplicant)
141            for field in UG_OMIT_PDF_FIELDS:
142                form_fields = form_fields.omit(field)
143        if not getattr(self.context, 'student_id'):
144            form_fields = form_fields.omit('student_id')
145        if not getattr(self.context, 'screening_score'):
146            form_fields = form_fields.omit('screening_score')
147        if not getattr(self.context, 'screening_venue'):
148            form_fields = form_fields.omit('screening_venue')
149        if not getattr(self.context, 'screening_date'):
150            form_fields = form_fields.omit('screening_date')
151        return form_fields
152
153class NigeriaApplicantManageFormPage(ApplicantManageFormPage):
154    """A full edit view for applicant data.
155    """
156   
157    @property
158    def form_fields(self):
159        if self.target is not None and self.target.startswith('pg'):
160            form_fields = grok.AutoFields(INigeriaPGApplicant)
161            for field in PG_OMIT_MANAGE_FIELDS:
162                form_fields = form_fields.omit(field)
163        elif self.target is not None and self.target.startswith('putme'):
164            form_fields = grok.AutoFields(INigeriaUGApplicant)
165            for field in PUTME_OMIT_MANAGE_FIELDS:
166                form_fields = form_fields.omit(field)
167        elif self.target is not None and self.target.startswith('pude'):
168            form_fields = grok.AutoFields(INigeriaUGApplicant)
169            for field in PUDE_OMIT_MANAGE_FIELDS:
170                form_fields = form_fields.omit(field)
171        else:
172            form_fields = grok.AutoFields(INigeriaUGApplicant)
173            for field in UG_OMIT_MANAGE_FIELDS:
174                form_fields = form_fields.omit(field)
175        form_fields['student_id'].for_display = True
176        form_fields['applicant_id'].for_display = True
177        return form_fields
178
179class NigeriaApplicantEditFormPage(ApplicantEditFormPage):
180    """An applicant-centered edit view for applicant data.
181    """
182
183    @property
184    def form_fields(self):
185        if self.target is not None and self.target.startswith('pg'):
186            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
187            for field in PG_OMIT_EDIT_FIELDS:
188                form_fields = form_fields.omit(field)
189        elif self.target is not None and self.target.startswith('putme'):
190            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
191            for field in PUTME_OMIT_EDIT_FIELDS:
192                form_fields = form_fields.omit(field)
193        elif self.target is not None and self.target.startswith('pude'):
194            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
195            for field in PUDE_OMIT_EDIT_FIELDS:
196                form_fields = form_fields.omit(field)
197        else:
198            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
199            for field in UG_OMIT_EDIT_FIELDS:
200                form_fields = form_fields.omit(field)
201        form_fields['applicant_id'].for_display = True
202        form_fields['reg_number'].for_display = True
203        return form_fields
204
205class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
206    """ Page to view an online payment ticket
207    """
208    grok.context(INigeriaApplicantOnlinePayment)
209    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac',
210        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
211    form_fields[
212        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
213    form_fields[
214        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
215
216class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
217    """Deliver a PDF slip of the context.
218    """
219    grok.context(INigeriaApplicantOnlinePayment)
220    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit(
221        'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
222    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
223    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
224
225class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage):
226    """Captcha'd registration page for applicants.
227    """
228
229    #def _redirect(self, email, password, applicant_id):
230    #    # Forward email and credentials to landing page.
231    #    self.redirect(self.url(self.context, 'registration_complete',
232    #        data = dict(email=email, password=password,
233    #        applicant_id=applicant_id)))
234    #    return
Note: See TracBrowser for help on using the repository browser.