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

Last change on this file since 16281 was 15961, checked in by Henrik Bettermann, 5 years ago

Remove Interswitch surcharge notice.

  • Property svn:keywords set to Id
File size: 8.6 KB
RevLine 
[9463]1## $Id: browser.py 15961 2020-01-27 13:03:41Z 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
[10570]28from waeup.kofa.interfaces import IKofaUtils
29from waeup.kofa.browser.interfaces import IPDFCreator
[14499]30from waeup.kofa.applicants.workflow import (
31    SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED)
[10529]32
33from kofacustom.nigeria.applicants.browser import (
34    NigeriaExportPDFPaymentSlipPage, NigeriaApplicantManageFormPage,
35    NigeriaApplicantDisplayFormPage, NigeriaApplicantEditFormPage)
36
[10570]37from waeup.fceokene.interfaces import MessageFactory as _
38
[9463]39from kofacustom.nigeria.applicants.interfaces import (
40    UG_OMIT_DISPLAY_FIELDS,
41    UG_OMIT_PDF_FIELDS,
42    UG_OMIT_MANAGE_FIELDS,
43    UG_OMIT_EDIT_FIELDS
44    )
45from waeup.fceokene.applicants.interfaces import (
[9481]46    ICustomUGApplicant, ICustomUGApplicantEdit,
[9463]47    BEC_OMIT_DISPLAY_FIELDS,
48    BEC_OMIT_PDF_FIELDS,
49    BEC_OMIT_MANAGE_FIELDS,
[13877]50    BEC_OMIT_EDIT_FIELDS,
51    ITPURegistration
[9463]52    )
53
[10533]54UG_OMIT_EDIT_FIELDS = [
55    value for value in UG_OMIT_EDIT_FIELDS
[13238]56        if not value in ('jamb_subjects', 'jamb_score', 'jamb_reg_number')]
[10533]57
[10529]58class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
[9463]59    """A display view for applicant data.
60    """
61
62    @property
63    def form_fields(self):
64        target = getattr(self.context.__parent__, 'prefix', None)
[13877]65        if target == 'tpu':
66            form_fields = grok.AutoFields(ITPURegistration).omit(
67                'locked', 'suspended')
68            return form_fields
[9463]69        form_fields = grok.AutoFields(ICustomUGApplicant)
70        if target is not None and target.startswith('bec'):
71            for field in BEC_OMIT_DISPLAY_FIELDS:
72                form_fields = form_fields.omit(field)
73        else:
74            form_fields = grok.AutoFields(ICustomUGApplicant)
75            for field in UG_OMIT_DISPLAY_FIELDS:
76                form_fields = form_fields.omit(field)
77        form_fields['notice'].custom_widget = BytesDisplayWidget
[10533]78        form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget
[9463]79        if not getattr(self.context, 'student_id'):
80            form_fields = form_fields.omit('student_id')
81        if not getattr(self.context, 'screening_score'):
82            form_fields = form_fields.omit('screening_score')
83        if not getattr(self.context, 'screening_venue'):
84            form_fields = form_fields.omit('screening_venue')
85        if not getattr(self.context, 'screening_date'):
86            form_fields = form_fields.omit('screening_date')
87        return form_fields
88
89class CustomPDFApplicationSlip(PDFApplicationSlip):
90
91    def _reduced_slip(self):
92        return getattr(self.context, 'result_uploaded', False)
93
[10570]94    def _getPDFCreator(self):
95        if 'putme' in self.target or 'pude' in self.target:
96            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
97        return getUtility(IPDFCreator)
98
[9463]99    @property
[10570]100    def title(self):
101        container_title = self.context.__parent__.title
102        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
103        ar_translation = translate(_('Application Record'),
104            'waeup.kofa', target_language=portal_language)
105        if 'putme' in self.target or 'pude' in self.target:
106            return 'IN AFFILIATION WITH UNIVERSITY OF IBADAN - %s %s %s' % (
107                container_title, ar_translation,
108                self.context.application_number)
109        return '%s - %s %s' % (container_title,
110            ar_translation, self.context.application_number)
111
112
113    @property
[9463]114    def form_fields(self):
115        target = getattr(self.context.__parent__, 'prefix', None)
[13877]116        if target == 'tpu':
117            form_fields = grok.AutoFields(ITPURegistration).omit(
118                'locked', 'suspended')
119            return form_fields
[9463]120        form_fields = grok.AutoFields(ICustomUGApplicant)
121        if target is not None and target.startswith('bec'):
122            for field in BEC_OMIT_PDF_FIELDS:
123                form_fields = form_fields.omit(field)
124        else:
125            form_fields = grok.AutoFields(ICustomUGApplicant)
126            for field in UG_OMIT_PDF_FIELDS:
127                form_fields = form_fields.omit(field)
128        if not getattr(self.context, 'student_id'):
129            form_fields = form_fields.omit('student_id')
130        if not getattr(self.context, 'screening_score'):
131            form_fields = form_fields.omit('screening_score')
132        if not getattr(self.context, 'screening_venue'):
133            form_fields = form_fields.omit('screening_venue')
134        if not getattr(self.context, 'screening_date'):
135            form_fields = form_fields.omit('screening_date')
136        return form_fields
137
[10529]138class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
[9463]139    """A full edit view for applicant data.
140    """
141   
142    @property
143    def form_fields(self):
144        target = getattr(self.context.__parent__, 'prefix', None)
[13877]145        if target == 'tpu':
146            form_fields = grok.AutoFields(ITPURegistration)
147            form_fields['applicant_id'].for_display = True
148            return form_fields
[9463]149        form_fields = grok.AutoFields(ICustomUGApplicant)
150        if target is not None and target.startswith('bec'):
151            for field in BEC_OMIT_MANAGE_FIELDS:
152                form_fields = form_fields.omit(field)
153        else:
154            for field in UG_OMIT_MANAGE_FIELDS:
155                form_fields = form_fields.omit(field)
156        form_fields['student_id'].for_display = True
157        form_fields['applicant_id'].for_display = True
158        return form_fields
159
[10529]160class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
[9463]161    """An applicant-centered edit view for applicant data.
162    """
163
164    @property
165    def form_fields(self):
166        target = getattr(self.context.__parent__, 'prefix', None)
[13877]167        if target == 'tpu':
168            form_fields = grok.AutoFields(ITPURegistration).omit(
169                'locked', 'suspended')
170            form_fields['applicant_id'].for_display = True
171            form_fields['reg_number'].for_display = True
172            form_fields['firstname'].for_display = True
173            form_fields['middlename'].for_display = True
174            form_fields['lastname'].for_display = True
175            form_fields['lga'].for_display = True
176            form_fields['matric_number'].for_display = True
177            return form_fields
[9481]178        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
[9463]179        if target is not None and target.startswith('bec'):
180            for field in BEC_OMIT_EDIT_FIELDS:
181                form_fields = form_fields.omit(field)
182        else:
183            for field in UG_OMIT_EDIT_FIELDS:
184                form_fields = form_fields.omit(field)
185        form_fields['applicant_id'].for_display = True
186        form_fields['reg_number'].for_display = True
[14499]187        return form_fields
188
[15635]189    def _student_per_school_exceeded(self, data):
[14499]190        container = self.context.__parent__
191        counter = 0
[15635]192        for appl in container.values():
193            if appl.state in (SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED) \
194                and (appl.school1 == self.context.school1 \
195                     or appl.school1 == data.get('school1')):
196                counter += 1
197                if counter == 10:
198                    return True
[14499]199        return False
200
[15635]201    def dataNotComplete(self, data):
[15641]202        target = getattr(self.context.__parent__, 'prefix', None)
203        if target == 'tpu':
204            if self._student_per_school_exceeded(data):
205                return ("1st Choice TPZ and School: "
206                        "Maximum number of applications per school exceeded. "
207                        "Please select another first choice school.")
[15635]208        super(CustomApplicantEditFormPage, self).dataNotComplete(data)
[14499]209        return
Note: See TracBrowser for help on using the repository browser.