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

Last change on this file since 18304 was 18304, checked in by Henrik Bettermann, 3 months ago

Update zones and schools.

  • Property svn:keywords set to Id
File size: 12.6 KB
Line 
1    ## $Id: browser.py 18304 2026-08-24 06:46:48Z 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.browser import ApplicantAddFormPage
28from waeup.kofa.applicants.pdf import PDFApplicationSlip
29from waeup.kofa.interfaces import IKofaUtils
30from waeup.kofa.browser.interfaces import IPDFCreator
31from waeup.kofa.applicants.workflow import (
32    SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED)
33
34from kofacustom.nigeria.applicants.browser import (
35    NigeriaExportPDFPaymentSlipPage, NigeriaApplicantManageFormPage,
36    NigeriaApplicantDisplayFormPage, NigeriaApplicantEditFormPage,
37    NigeriaApplicantRegistrationPage)
38
39from waeup.fceokene.interfaces import MessageFactory as _
40
41from kofacustom.nigeria.applicants.interfaces import (
42    UG_OMIT_DISPLAY_FIELDS,
43    UG_OMIT_PDF_FIELDS,
44    UG_OMIT_MANAGE_FIELDS,
45    UG_OMIT_EDIT_FIELDS
46    )
47from waeup.fceokene.applicants.interfaces import (
48    ICustomApplicant,
49    ICustomUGApplicant,
50    ICustomUGApplicantEdit,
51    ICustomApplicantRegisterUpdate,
52    BEC_OMIT_DISPLAY_FIELDS,
53    BEC_OMIT_PDF_FIELDS,
54    BEC_OMIT_MANAGE_FIELDS,
55    BEC_OMIT_EDIT_FIELDS,
56    ITPURegistration,
57    IUTPRegistration
58    )
59
60UG_OMIT_EDIT_FIELDS = [
61    value for value in UG_OMIT_EDIT_FIELDS
62        if not value in ('jamb_subjects', 'jamb_score', 'jamb_reg_number')]
63
64class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
65    """A display view for applicant data.
66    """
67
68    @property
69    def form_fields(self):
70        target = getattr(self.context.__parent__, 'prefix', None)
71        if target == 'tpu':
72            form_fields = grok.AutoFields(ITPURegistration).omit(
73                'locked', 'suspended')
74            return form_fields
75        if target == 'utp':
76            form_fields = grok.AutoFields(IUTPRegistration).omit(
77                'locked', 'suspended',)
78            return form_fields
79        form_fields = grok.AutoFields(ICustomUGApplicant)
80        if target is not None and target.startswith('bec'):
81            for field in BEC_OMIT_DISPLAY_FIELDS:
82                form_fields = form_fields.omit(field)
83        else:
84            form_fields = grok.AutoFields(ICustomUGApplicant)
85            for field in UG_OMIT_DISPLAY_FIELDS:
86                form_fields = form_fields.omit(field)
87        form_fields['notice'].custom_widget = BytesDisplayWidget
88        form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget
89        if not getattr(self.context, 'student_id'):
90            form_fields = form_fields.omit('student_id')
91        if not getattr(self.context, 'screening_score'):
92            form_fields = form_fields.omit('screening_score')
93        if not getattr(self.context, 'screening_venue'):
94            form_fields = form_fields.omit('screening_venue')
95        if not getattr(self.context, 'screening_date'):
96            form_fields = form_fields.omit('screening_date')
97        return form_fields
98
99class CustomPDFApplicationSlip(PDFApplicationSlip):
100
101    def _reduced_slip(self):
102        return getattr(self.context, 'result_uploaded', False)
103
104    def _getPDFCreator(self):
105        if 'putme' in self.target or 'pude' in self.target:
106            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
107        return getUtility(IPDFCreator)
108
109    @property
110    def title(self):
111        container_title = self.context.__parent__.title
112        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
113        ar_translation = translate(_('Application Record'),
114            'waeup.kofa', target_language=portal_language)
115        if 'putme' in self.target or 'pude' in self.target:
116            return 'IN AFFILIATION WITH UNIVERSITY OF IBADAN - %s %s %s' % (
117                container_title, ar_translation,
118                self.context.application_number)
119        return '%s - %s %s' % (container_title,
120            ar_translation, self.context.application_number)
121
122
123    @property
124    def form_fields(self):
125        target = getattr(self.context.__parent__, 'prefix', None)
126        if target == 'tpu':
127            form_fields = grok.AutoFields(ITPURegistration).omit(
128                'locked', 'suspended')
129            return form_fields
130        if target == 'utp':
131            form_fields = grok.AutoFields(IUTPRegistration).omit(
132                'locked', 'suspended')
133            return form_fields
134        form_fields = grok.AutoFields(ICustomUGApplicant)
135        if target is not None and target.startswith('bec'):
136            for field in BEC_OMIT_PDF_FIELDS:
137                form_fields = form_fields.omit(field)
138        else:
139            form_fields = grok.AutoFields(ICustomUGApplicant)
140            for field in UG_OMIT_PDF_FIELDS:
141                form_fields = form_fields.omit(field)
142        if not getattr(self.context, 'student_id'):
143            form_fields = form_fields.omit('student_id')
144        if not getattr(self.context, 'screening_score'):
145            form_fields = form_fields.omit('screening_score')
146        if not getattr(self.context, 'screening_venue'):
147            form_fields = form_fields.omit('screening_venue')
148        if not getattr(self.context, 'screening_date'):
149            form_fields = form_fields.omit('screening_date')
150        return form_fields
151
152class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
153    """A full edit view for applicant data.
154    """
155   
156    @property
157    def form_fields(self):
158        target = getattr(self.context.__parent__, 'prefix', None)
159        if target == 'tpu':
160            form_fields = grok.AutoFields(ITPURegistration)
161            form_fields['applicant_id'].for_display = True
162            return form_fields
163        if target == 'utp':
164            form_fields = grok.AutoFields(IUTPRegistration)
165            form_fields['applicant_id'].for_display = True
166            return form_fields
167        form_fields = grok.AutoFields(ICustomUGApplicant)
168        if target is not None and target.startswith('bec'):
169            for field in BEC_OMIT_MANAGE_FIELDS:
170                form_fields = form_fields.omit(field)
171        else:
172            for field in UG_OMIT_MANAGE_FIELDS:
173                form_fields = form_fields.omit(field)
174        form_fields['student_id'].for_display = True
175        form_fields['applicant_id'].for_display = True
176        return form_fields
177
178class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
179    """An applicant-centered edit view for applicant data.
180    """
181
182    @property
183    def form_fields(self):
184        target = getattr(self.context.__parent__, 'prefix', None)
185        if target == 'tpu':
186            form_fields = grok.AutoFields(ITPURegistration).omit(
187                'locked', 'suspended')
188            form_fields['applicant_id'].for_display = True
189            form_fields['reg_number'].for_display = True
190            form_fields['firstname'].for_display = True
191            form_fields['middlename'].for_display = True
192            form_fields['lastname'].for_display = True
193            form_fields['lga'].for_display = True
194            form_fields['matric_number'].for_display = True
195            form_fields['subj_comb'].field.required = True
196            #form_fields['school_tpu'].field.required = True
197            form_fields['zone_tpu'].field.required = True
198            return form_fields
199        if target == 'utp':
200            form_fields = grok.AutoFields(IUTPRegistration).omit(
201                'locked', 'suspended')
202            form_fields['applicant_id'].for_display = True
203            form_fields['reg_number'].for_display = True
204            form_fields['firstname'].for_display = True
205            form_fields['middlename'].for_display = True
206            form_fields['lastname'].for_display = True
207            form_fields['lga'].for_display = True
208            form_fields['matric_number'].for_display = True
209            form_fields['subj_comb'].field.required = True
210            form_fields['school_utp'].field.required = True
211            return form_fields
212        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
213        if target is not None and target.startswith('bec'):
214            for field in BEC_OMIT_EDIT_FIELDS:
215                form_fields = form_fields.omit(field)
216        else:
217            for field in UG_OMIT_EDIT_FIELDS:
218                form_fields = form_fields.omit(field)
219        form_fields['applicant_id'].for_display = True
220        form_fields['reg_number'].for_display = True
221        return form_fields
222
223    def _students_per_school_exceeded(self, data):
224        container = self.context.__parent__
225        counter_school = 0
226        counter_subj_per_school = 0
227        target = getattr(container, 'prefix', None)
228        if target == 'tpu':
229            school = 'school_tpu'
230            max_schools = 5
231            max_subj_per_school = 1
232        else:
233            max_schools = 7
234            max_subj_per_school = 2
235            school = 'school_utp'
236        for appl in container.values():
237            if appl != self.context \
238                and appl.state in (SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED):
239                if getattr(appl, school) == data.get(school):
240                    counter_school += 1
241                    if appl.subj_comb == data.get('subj_comb'):
242                        counter_subj_per_school += 1
243                    if counter_subj_per_school == max_subj_per_school:
244                        return True
245                if counter_school == max_schools:
246                    return True
247        return False
248
249    MAX_ZONE = {
250        'z1': 411,
251        'z2': 88,
252        'z3': 58,
253        'z4': 81,
254        'z5': 8,
255        'z6': 29,
256        'z7': 88,
257        'z8': 112,
258        'z9': 0,
259        'z10': 88,
260        'z11': 161,
261        'z12': 19,
262        'z13': 0,
263        'z14': 0,
264        'z15': 21,
265        }
266
267    def _students_per_zone_exceeded(self, data):
268        container = self.context.__parent__
269        counter_zone = 0
270        for appl in container.values():
271            zone = data.get('zone_tpu').split('_')[0]
272            max_zone = self.MAX_ZONE[zone]
273            if appl != self.context \
274                and appl.state in (SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED):
275                if getattr(appl, 'zone_tpu').split(
276                    '_')[0] == data.get('zone_tpu').split('_')[0]:
277                    counter_zone += 1
278                if counter_zone == max_zone:
279                    return True
280        return False
281
282    def dataNotComplete(self, data):
283        target = getattr(self.context.__parent__, 'prefix', None)
284        if target in ('utp',):
285            if self._students_per_school_exceeded(data):
286                return ("1st Choice School: "
287                        "Maximum number of applications per school exceeded. "
288                        "Please select another first choice school.")
289        if target in ('tpu',):
290            if self._students_per_zone_exceeded(data):
291                return ("1st Choice School Zone: "
292                        "Maximum number of applications per zone exceeded. "
293                        "Please select another first choice school.")
294        super(CustomApplicantEditFormPage, self).dataNotComplete(data)
295        return
296
297class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage):
298
299    @property
300    def form_fields(self):
301        form_fields = None
302        if self.context.mode == 'update':
303            form_fields = grok.AutoFields(ICustomApplicantRegisterUpdate).select(
304                'lastname','reg_number','email')
305        else: #if self.context.mode == 'create':
306            form_fields = grok.AutoFields(ICustomUGApplicantEdit).select(
307                'firstname', 'middlename', 'lastname', 'email', 'phone')
308        return form_fields
309
310class CustomApplicantAddFormPage(ApplicantAddFormPage):
311    """Add-form to add an applicant.
312    """
313    form_fields = grok.AutoFields(ICustomApplicant).select(
314        'firstname', 'middlename', 'lastname',
315        'email', 'phone')
Note: See TracBrowser for help on using the repository browser.