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

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

Setup Nigerian applicant components with interfaces. (More tests will follow.)

  • Property svn:keywords set to Id
File size: 7.5 KB
Line 
1## $Id: browser.py 8926 2012-07-07 07:31:40Z 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 waeup.kofa.students.interfaces import IStudentsUtils
25from waeup.kofa.applicants.interfaces import (
26    IApplicantRegisterUpdate, IApplicant, IApplicantEdit)
27from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
28    ExportPDFPage,
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, PG_OMIT_DISPLAY_FIELDS,
42    UG_OMIT_PDF_FIELDS, PG_OMIT_PDF_FIELDS,
43    UG_OMIT_MANAGE_FIELDS, PG_OMIT_MANAGE_FIELDS,
44    UG_OMIT_EDIT_FIELDS, PG_OMIT_EDIT_FIELDS, PUTME_OMIT_EDIT_FIELDS,
45    UG_OMIT_RESULT_SLIP_FIELDS)
46from kofacustom.nigeria.interfaces import MessageFactory as _
47
48class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
49    """A breadcrumb for payments.
50    """
51    grok.context(INigeriaApplicantOnlinePayment)
52
53class PaymentReceiptActionButton(PaymentReceiptActionButton):
54    grok.order(4)
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
65
66class NigeriaPDFApplicationSlip(PDFApplicationSlip):
67
68    def _reduced_slip(self):
69        return getattr(self.context, 'result_uploaded', False)
70
71    @property
72    def note(self):
73        target = getattr(self.context.__parent__, 'prefix', None)
74        if target is not None and not target.startswith('pg') \
75            and not self._reduced_slip():
76            return _(u'<br /><br /><br />'
77                      'Comfirm your exam venue 72 hours to the exam.')
78        return
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_PDF_FIELDS:
86                form_fields = form_fields.omit(field)
87        else:
88            form_fields = grok.AutoFields(INigeriaUGApplicant)
89            if self._reduced_slip():
90                for field in UG_OMIT_RESULT_SLIP_FIELDS:
91                    form_fields = form_fields.omit(field)
92            else:
93                for field in UG_OMIT_PDF_FIELDS:
94                    form_fields = form_fields.omit(field)
95        if not getattr(self.context, 'student_id'):
96            form_fields = form_fields.omit('student_id')
97        return form_fields
98
99class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage):
100    """A display view for applicant data.
101    """
102
103    @property
104    def form_fields(self):
105        target = getattr(self.context.__parent__, 'prefix', None)
106        if target is not None and target.startswith('pg'):
107            form_fields = grok.AutoFields(INigeriaPGApplicant)
108            for field in PG_OMIT_DISPLAY_FIELDS:
109                form_fields = form_fields.omit(field)
110        else:
111            form_fields = grok.AutoFields(INigeriaUGApplicant)
112            for field in UG_OMIT_DISPLAY_FIELDS:
113                form_fields = form_fields.omit(field)
114        return form_fields
115
116class NigeriaApplicantManageFormPage(ApplicantManageFormPage):
117    """A full edit view for applicant data.
118    """
119   
120    @property
121    def form_fields(self):
122        target = getattr(self.context.__parent__, 'prefix', None)
123        if target is not None and target.startswith('pg'):
124            form_fields = grok.AutoFields(INigeriaPGApplicant)
125            for field in PG_OMIT_MANAGE_FIELDS:
126                form_fields = form_fields.omit(field)
127        else:
128            form_fields = grok.AutoFields(INigeriaUGApplicant)
129            for field in UG_OMIT_MANAGE_FIELDS:
130                form_fields = form_fields.omit(field)
131        form_fields['student_id'].for_display = True
132        form_fields['applicant_id'].for_display = True
133        return form_fields
134
135class NigeriaApplicantEditFormPage(ApplicantEditFormPage):
136    """An applicant-centered edit view for applicant data.
137    """
138
139    @property
140    def form_fields(self):
141        target = getattr(self.context.__parent__, 'prefix', None)
142        if target is not None and target.startswith('pg'):
143            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
144            for field in PG_OMIT_EDIT_FIELDS:
145                form_fields = form_fields.omit(field)
146        elif target is not None and target.startswith('putme'):
147            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
148            for field in PUTME_OMIT_EDIT_FIELDS:
149                form_fields = form_fields.omit(field)
150        else:
151            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
152            for field in UG_OMIT_EDIT_FIELDS:
153                form_fields = form_fields.omit(field)
154        form_fields['applicant_id'].for_display = True
155        form_fields['reg_number'].for_display = True
156        return form_fields
157
158class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
159    """ Page to view an online payment ticket
160    """
161    grok.context(INigeriaApplicantOnlinePayment)
162    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac')
163    form_fields[
164        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
165    form_fields[
166        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
167
168class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
169    """Deliver a PDF slip of the context.
170    """
171    grok.context(INigeriaApplicantOnlinePayment)
172    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac')
173    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
174    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
175
176class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage):
177    """Captcha'd registration page for applicants.
178    """
179
180    #def _redirect(self, email, password, applicant_id):
181    #    # Forward email and credentials to landing page.
182    #    self.redirect(self.url(self.context, 'registration_complete',
183    #        data = dict(email=email, password=password,
184    #        applicant_id=applicant_id)))
185    #    return
Note: See TracBrowser for help on using the repository browser.