source: main/waeup.uniben/trunk/src/waeup/uniben/applicants/browser.py @ 8938

Last change on this file since 8938 was 8928, checked in by Henrik Bettermann, 13 years ago

Start using components and interfaces in kofacustom.nigeria. Unfortunately, this does not reduce the code in waeup.uniben very much, only because we are still using an old LGAs dictionary.

Move applicants tests into 'tests' package.

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