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

Last change on this file since 10222 was 9985, checked in by Henrik Bettermann, 12 years ago

Adjustments to be made in kofacustom.nigeria.

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