source: main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/browser.py @ 14121

Last change on this file since 14121 was 13877, checked in by Henrik Bettermann, 8 years ago

Add components for TPU registration.

  • Property svn:keywords set to Id
File size: 7.8 KB
Line 
1## $Id: browser.py 13877 2016-06-04 18:31:00Z 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.applicants.viewlets import (
26    PaymentReceiptActionButton, PDFActionButton)
27from waeup.kofa.applicants.pdf import PDFApplicationSlip
28from waeup.kofa.interfaces import IKofaUtils
29from waeup.kofa.browser.interfaces import IPDFCreator
30
31from kofacustom.nigeria.applicants.browser import (
32    NigeriaExportPDFPaymentSlipPage, NigeriaApplicantManageFormPage,
33    NigeriaApplicantDisplayFormPage, NigeriaApplicantEditFormPage)
34
35from waeup.fceokene.interfaces import MessageFactory as _
36
37from kofacustom.nigeria.applicants.interfaces import (
38    UG_OMIT_DISPLAY_FIELDS,
39    UG_OMIT_PDF_FIELDS,
40    UG_OMIT_MANAGE_FIELDS,
41    UG_OMIT_EDIT_FIELDS
42    )
43from waeup.fceokene.applicants.interfaces import (
44    ICustomUGApplicant, ICustomUGApplicantEdit,
45    BEC_OMIT_DISPLAY_FIELDS,
46    BEC_OMIT_PDF_FIELDS,
47    BEC_OMIT_MANAGE_FIELDS,
48    BEC_OMIT_EDIT_FIELDS,
49    ITPURegistration
50    )
51
52UG_OMIT_EDIT_FIELDS = [
53    value for value in UG_OMIT_EDIT_FIELDS
54        if not value in ('jamb_subjects', 'jamb_score', 'jamb_reg_number')]
55
56class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
57    """A display view for applicant data.
58    """
59
60    @property
61    def form_fields(self):
62        target = getattr(self.context.__parent__, 'prefix', None)
63        if target == 'tpu':
64            form_fields = grok.AutoFields(ITPURegistration).omit(
65                'locked', 'suspended')
66            return form_fields
67        form_fields = grok.AutoFields(ICustomUGApplicant)
68        if target is not None and target.startswith('bec'):
69            for field in BEC_OMIT_DISPLAY_FIELDS:
70                form_fields = form_fields.omit(field)
71        else:
72            form_fields = grok.AutoFields(ICustomUGApplicant)
73            for field in UG_OMIT_DISPLAY_FIELDS:
74                form_fields = form_fields.omit(field)
75        form_fields['notice'].custom_widget = BytesDisplayWidget
76        form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget
77        if not getattr(self.context, 'student_id'):
78            form_fields = form_fields.omit('student_id')
79        if not getattr(self.context, 'screening_score'):
80            form_fields = form_fields.omit('screening_score')
81        if not getattr(self.context, 'screening_venue'):
82            form_fields = form_fields.omit('screening_venue')
83        if not getattr(self.context, 'screening_date'):
84            form_fields = form_fields.omit('screening_date')
85        return form_fields
86
87class CustomPDFApplicationSlip(PDFApplicationSlip):
88
89    def _reduced_slip(self):
90        return getattr(self.context, 'result_uploaded', False)
91
92    def _getPDFCreator(self):
93        if 'putme' in self.target or 'pude' in self.target:
94            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
95        return getUtility(IPDFCreator)
96
97    @property
98    def title(self):
99        container_title = self.context.__parent__.title
100        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
101        ar_translation = translate(_('Application Record'),
102            'waeup.kofa', target_language=portal_language)
103        if 'putme' in self.target or 'pude' in self.target:
104            return 'IN AFFILIATION WITH UNIVERSITY OF IBADAN - %s %s %s' % (
105                container_title, ar_translation,
106                self.context.application_number)
107        return '%s - %s %s' % (container_title,
108            ar_translation, self.context.application_number)
109
110
111    @property
112    def form_fields(self):
113        target = getattr(self.context.__parent__, 'prefix', None)
114        if target == 'tpu':
115            form_fields = grok.AutoFields(ITPURegistration).omit(
116                'locked', 'suspended')
117            return form_fields
118        form_fields = grok.AutoFields(ICustomUGApplicant)
119        if target is not None and target.startswith('bec'):
120            for field in BEC_OMIT_PDF_FIELDS:
121                form_fields = form_fields.omit(field)
122        else:
123            form_fields = grok.AutoFields(ICustomUGApplicant)
124            for field in UG_OMIT_PDF_FIELDS:
125                form_fields = form_fields.omit(field)
126        if not getattr(self.context, 'student_id'):
127            form_fields = form_fields.omit('student_id')
128        if not getattr(self.context, 'screening_score'):
129            form_fields = form_fields.omit('screening_score')
130        if not getattr(self.context, 'screening_venue'):
131            form_fields = form_fields.omit('screening_venue')
132        if not getattr(self.context, 'screening_date'):
133            form_fields = form_fields.omit('screening_date')
134        return form_fields
135
136class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
137    """Deliver a PDF slip of the context.
138    """
139
140    note = '''
141
142
143The total authorized amount includes an Interswitch transaction charge of 150 Nairas.
144'''
145
146class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
147    """A full edit view for applicant data.
148    """
149   
150    @property
151    def form_fields(self):
152        target = getattr(self.context.__parent__, 'prefix', None)
153        if target == 'tpu':
154            form_fields = grok.AutoFields(ITPURegistration)
155            form_fields['applicant_id'].for_display = True
156            return form_fields
157        form_fields = grok.AutoFields(ICustomUGApplicant)
158        if target is not None and target.startswith('bec'):
159            for field in BEC_OMIT_MANAGE_FIELDS:
160                form_fields = form_fields.omit(field)
161        else:
162            for field in UG_OMIT_MANAGE_FIELDS:
163                form_fields = form_fields.omit(field)
164        form_fields['student_id'].for_display = True
165        form_fields['applicant_id'].for_display = True
166        return form_fields
167
168class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
169    """An applicant-centered edit view for applicant data.
170    """
171
172    @property
173    def form_fields(self):
174        target = getattr(self.context.__parent__, 'prefix', None)
175        if target == 'tpu':
176            form_fields = grok.AutoFields(ITPURegistration).omit(
177                'locked', 'suspended')
178            form_fields['applicant_id'].for_display = True
179            form_fields['reg_number'].for_display = True
180            form_fields['firstname'].for_display = True
181            form_fields['middlename'].for_display = True
182            form_fields['lastname'].for_display = True
183            form_fields['lga'].for_display = True
184            form_fields['matric_number'].for_display = True
185            return form_fields
186        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
187        if target is not None and target.startswith('bec'):
188            for field in BEC_OMIT_EDIT_FIELDS:
189                form_fields = form_fields.omit(field)
190        else:
191            for field in UG_OMIT_EDIT_FIELDS:
192                form_fields = form_fields.omit(field)
193        form_fields['applicant_id'].for_display = True
194        form_fields['reg_number'].for_display = True
195        return form_fields
Note: See TracBrowser for help on using the repository browser.