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

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

Use target property.

  • Property svn:keywords set to Id
File size: 10.3 KB
RevLine 
[8926]1## $Id: browser.py 10223 2013-05-24 07:37:21Z 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
[9054]24from zope.formlib.textwidgets import BytesDisplayWidget
[8926]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,
[9049]41    INigeriaApplicantOnlinePayment,IPUTMEApplicantEdit,
[9054]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    )
[8926]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
[9050]76class NigeriaApplicantDisplayFormPage(ApplicantDisplayFormPage):
77    """A display view for applicant data.
78    """
[8926]79
[9050]80    @property
81    def form_fields(self):
[10223]82        if self.target is not None and self.target.startswith('pg'):
[9050]83            form_fields = grok.AutoFields(INigeriaPGApplicant)
84            for field in PG_OMIT_DISPLAY_FIELDS:
85                form_fields = form_fields.omit(field)
[10223]86        elif self.target is not None and self.target.startswith('putme'):
[9050]87            form_fields = grok.AutoFields(INigeriaUGApplicant)
88            for field in PUTME_OMIT_DISPLAY_FIELDS:
89                form_fields = form_fields.omit(field)
[10223]90        elif self.target is not None and self.target.startswith('pude'):
[9054]91            form_fields = grok.AutoFields(INigeriaUGApplicant)
92            for field in PUDE_OMIT_DISPLAY_FIELDS:
93                form_fields = form_fields.omit(field)
[9050]94        else:
95            form_fields = grok.AutoFields(INigeriaUGApplicant)
96            for field in UG_OMIT_DISPLAY_FIELDS:
97                form_fields = form_fields.omit(field)
[9072]98        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
[9054]99        form_fields['notice'].custom_widget = BytesDisplayWidget
[9076]100        if not getattr(self.context, 'student_id'):
101            form_fields = form_fields.omit('student_id')
102        if not getattr(self.context, 'screening_score'):
103            form_fields = form_fields.omit('screening_score')
104        if not getattr(self.context, 'screening_venue'):
105            form_fields = form_fields.omit('screening_venue')
106        if not getattr(self.context, 'screening_date'):
107            form_fields = form_fields.omit('screening_date')
[9050]108        return form_fields
109
[8926]110class NigeriaPDFApplicationSlip(PDFApplicationSlip):
111
112    def _reduced_slip(self):
113        return getattr(self.context, 'result_uploaded', False)
114
[9076]115    #@property
116    #def note(self):
[10223]117    #    if self.target is not None and not self.target.startswith('pg') \
[9076]118    #        and not self._reduced_slip():
119    #        return _(u'<br /><br /><br />'
120    #                  'Comfirm your exam venue 72 hours to the exam.')
121    #    return
[8926]122
123    @property
124    def form_fields(self):
[10223]125        if self.target is not None and self.target.startswith('pg'):
[8926]126            form_fields = grok.AutoFields(INigeriaPGApplicant)
127            for field in PG_OMIT_PDF_FIELDS:
128                form_fields = form_fields.omit(field)
[10223]129        elif self.target is not None and self.target.startswith('putme'):
[8926]130            form_fields = grok.AutoFields(INigeriaUGApplicant)
131            if self._reduced_slip():
[9049]132                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
[8926]133                    form_fields = form_fields.omit(field)
134            else:
[9049]135                for field in PUTME_OMIT_PDF_FIELDS:
[8926]136                    form_fields = form_fields.omit(field)
[10223]137        elif self.target is not None and self.target.startswith('pude'):
[9054]138            form_fields = grok.AutoFields(INigeriaUGApplicant)
139            if self._reduced_slip():
140                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
141                    form_fields = form_fields.omit(field)
142            else:
143                for field in PUDE_OMIT_PDF_FIELDS:
144                    form_fields = form_fields.omit(field)
[9049]145        else:
146            form_fields = grok.AutoFields(INigeriaUGApplicant)
147            for field in UG_OMIT_PDF_FIELDS:
148                form_fields = form_fields.omit(field)
[8926]149        if not getattr(self.context, 'student_id'):
150            form_fields = form_fields.omit('student_id')
[9076]151        if not getattr(self.context, 'screening_score'):
152            form_fields = form_fields.omit('screening_score')
153        if not getattr(self.context, 'screening_venue'):
154            form_fields = form_fields.omit('screening_venue')
155        if not getattr(self.context, 'screening_date'):
156            form_fields = form_fields.omit('screening_date')
[8926]157        return form_fields
158
159class NigeriaApplicantManageFormPage(ApplicantManageFormPage):
160    """A full edit view for applicant data.
161    """
162   
163    @property
164    def form_fields(self):
[10223]165        if self.target is not None and self.target.startswith('pg'):
[8926]166            form_fields = grok.AutoFields(INigeriaPGApplicant)
167            for field in PG_OMIT_MANAGE_FIELDS:
168                form_fields = form_fields.omit(field)
[10223]169        elif self.target is not None and self.target.startswith('putme'):
[9049]170            form_fields = grok.AutoFields(INigeriaUGApplicant)
171            for field in PUTME_OMIT_MANAGE_FIELDS:
172                form_fields = form_fields.omit(field)
[10223]173        elif self.target is not None and self.target.startswith('pude'):
[9054]174            form_fields = grok.AutoFields(INigeriaUGApplicant)
175            for field in PUDE_OMIT_MANAGE_FIELDS:
176                form_fields = form_fields.omit(field)
[8926]177        else:
178            form_fields = grok.AutoFields(INigeriaUGApplicant)
179            for field in UG_OMIT_MANAGE_FIELDS:
180                form_fields = form_fields.omit(field)
181        form_fields['student_id'].for_display = True
182        form_fields['applicant_id'].for_display = True
183        return form_fields
184
185class NigeriaApplicantEditFormPage(ApplicantEditFormPage):
186    """An applicant-centered edit view for applicant data.
187    """
188
189    @property
190    def form_fields(self):
[10223]191        if self.target is not None and self.target.startswith('pg'):
[8926]192            form_fields = grok.AutoFields(INigeriaPGApplicantEdit)
193            for field in PG_OMIT_EDIT_FIELDS:
194                form_fields = form_fields.omit(field)
[10223]195        elif self.target is not None and self.target.startswith('putme'):
[8926]196            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
197            for field in PUTME_OMIT_EDIT_FIELDS:
198                form_fields = form_fields.omit(field)
[10223]199        elif self.target is not None and self.target.startswith('pude'):
[9482]200            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
[9054]201            for field in PUDE_OMIT_EDIT_FIELDS:
202                form_fields = form_fields.omit(field)
[8926]203        else:
204            form_fields = grok.AutoFields(INigeriaUGApplicantEdit)
205            for field in UG_OMIT_EDIT_FIELDS:
206                form_fields = form_fields.omit(field)
207        form_fields['applicant_id'].for_display = True
208        form_fields['reg_number'].for_display = True
209        return form_fields
210
211class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
212    """ Page to view an online payment ticket
213    """
214    grok.context(INigeriaApplicantOnlinePayment)
[9985]215    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit('ac',
216        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8926]217    form_fields[
218        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
219    form_fields[
220        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
221
222class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
223    """Deliver a PDF slip of the context.
224    """
225    grok.context(INigeriaApplicantOnlinePayment)
[9985]226    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit(
227        'ac', 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8926]228    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
229    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
230
231class NigeriaApplicantRegistrationPage(ApplicantRegistrationPage):
232    """Captcha'd registration page for applicants.
233    """
234
235    #def _redirect(self, email, password, applicant_id):
236    #    # Forward email and credentials to landing page.
237    #    self.redirect(self.url(self.context, 'registration_complete',
238    #        data = dict(email=email, password=password,
239    #        applicant_id=applicant_id)))
240    #    return
Note: See TracBrowser for help on using the repository browser.