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

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

Add PUDE 'omit' tuples.

  • Property svn:keywords set to Id
File size: 9.7 KB
Line 
1## $Id: browser.py 9054 2012-07-26 06:23:18Z 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 PaymentReceiptActionButton(PaymentReceiptActionButton):
69    grok.order(4)
70    grok.context(INigeriaApplicantOnlinePayment)
71
72class PDFActionButton(PDFActionButton):
73
74    @property
75    def text(self):
76        if getattr(self.context, 'result_uploaded', False):
77            return _('Download result slip')
78        return _('Download application slip')
79
80class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage):
81    """A display view for applicant data.
82    """
83
84    @property
85    def form_fields(self):
86        target = getattr(self.context.__parent__, 'prefix', None)
87        if target is not None and target.startswith('pg'):
88            form_fields = grok.AutoFields(INigeriaPGApplicant)
89            for field in PG_OMIT_DISPLAY_FIELDS:
90                form_fields = form_fields.omit(field)
91        elif target is not None and target.startswith('putme'):
92            form_fields = grok.AutoFields(INigeriaUGApplicant)
93            for field in PUTME_OMIT_DISPLAY_FIELDS:
94                form_fields = form_fields.omit(field)
95        elif target is not None and target.startswith('pude'):
96            form_fields = grok.AutoFields(INigeriaUGApplicant)
97            for field in PUDE_OMIT_DISPLAY_FIELDS:
98                form_fields = form_fields.omit(field)
99        else:
100            form_fields = grok.AutoFields(INigeriaUGApplicant)
101            for field in UG_OMIT_DISPLAY_FIELDS:
102                form_fields = form_fields.omit(field)
103        form_fields['perm_address'].custom_widget = BytesDisplayWidget
104        form_fields['notice'].custom_widget = BytesDisplayWidget
105        return form_fields
106
107class NigeriaPDFApplicationSlip(PDFApplicationSlip):
108
109    def _reduced_slip(self):
110        return getattr(self.context, 'result_uploaded', False)
111
112    @property
113    def note(self):
114        target = getattr(self.context.__parent__, 'prefix', None)
115        if target is not None and not target.startswith('pg') \
116            and not self._reduced_slip():
117            return _(u'<br /><br /><br />'
118                      'Comfirm your exam venue 72 hours to the exam.')
119        return
120
121    @property
122    def form_fields(self):
123        target = getattr(self.context.__parent__, 'prefix', None)
124        if target is not None and target.startswith('pg'):
125            form_fields = grok.AutoFields(INigeriaPGApplicant)
126            for field in PG_OMIT_PDF_FIELDS:
127                form_fields = form_fields.omit(field)
128        elif target is not None and target.startswith('putme'):
129            form_fields = grok.AutoFields(INigeriaUGApplicant)
130            if self._reduced_slip():
131                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
132                    form_fields = form_fields.omit(field)
133            else:
134                for field in PUTME_OMIT_PDF_FIELDS:
135                    form_fields = form_fields.omit(field)
136        elif target is not None and target.startswith('pude'):
137            form_fields = grok.AutoFields(INigeriaUGApplicant)
138            if self._reduced_slip():
139                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
140                    form_fields = form_fields.omit(field)
141            else:
142                for field in PUDE_OMIT_PDF_FIELDS:
143                    form_fields = form_fields.omit(field)
144        else:
145            form_fields = grok.AutoFields(INigeriaUGApplicant)
146            for field in UG_OMIT_PDF_FIELDS:
147                form_fields = form_fields.omit(field)
148        if not getattr(self.context, 'student_id'):
149            form_fields = form_fields.omit('student_id')
150        return form_fields
151
152class NigeriaApplicantManageFormPage(ApplicantManageFormPage):
153    """A full edit view for applicant data.
154    """
155   
156    @property
157    def form_fields(self):
158        target = getattr(self.context.__parent__, 'prefix', None)
159        if target is not None and 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 target is not None and 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 target is not None and 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        target = getattr(self.context.__parent__, 'prefix', None)
186        if target is not None and target.startswith('pg'):
187            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
188            for field in PG_OMIT_EDIT_FIELDS:
189                form_fields = form_fields.omit(field)
190        elif target is not None and target.startswith('putme'):
191            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
192            for field in PUTME_OMIT_EDIT_FIELDS:
193                form_fields = form_fields.omit(field)
194        elif target is not None and target.startswith('pude'):
195            form_fields = grok.AutoFields(INigeriaUGApplicant)
196            for field in PUDE_OMIT_EDIT_FIELDS:
197                form_fields = form_fields.omit(field)
198        else:
199            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
200            for field in UG_OMIT_EDIT_FIELDS:
201                form_fields = form_fields.omit(field)
202        form_fields['applicant_id'].for_display = True
203        form_fields['reg_number'].for_display = True
204        return form_fields
205
206class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
207    """ Page to view an online payment ticket
208    """
209    grok.context(INigeriaApplicantOnlinePayment)
210    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac')
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('ac')
221    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
222    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
223
224class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage):
225    """Captcha'd registration page for applicants.
226    """
227
228    #def _redirect(self, email, password, applicant_id):
229    #    # Forward email and credentials to landing page.
230    #    self.redirect(self.url(self.context, 'registration_complete',
231    #        data = dict(email=email, password=password,
232    #        applicant_id=applicant_id)))
233    #    return
Note: See TracBrowser for help on using the repository browser.