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

Last change on this file since 17723 was 17723, checked in by Henrik Bettermann, 6 months ago

Reduce number of students per school.

  • Property svn:keywords set to Id
File size: 10.5 KB
Line 
1## $Id: browser.py 17723 2024-03-24 06:25:32Z 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
30from waeup.kofa.applicants.workflow import (
31    SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED)
32
33from kofacustom.nigeria.applicants.browser import (
34    NigeriaExportPDFPaymentSlipPage, NigeriaApplicantManageFormPage,
35    NigeriaApplicantDisplayFormPage, NigeriaApplicantEditFormPage)
36
37from waeup.fceokene.interfaces import MessageFactory as _
38
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 (
46    ICustomUGApplicant, ICustomUGApplicantEdit,
47    BEC_OMIT_DISPLAY_FIELDS,
48    BEC_OMIT_PDF_FIELDS,
49    BEC_OMIT_MANAGE_FIELDS,
50    BEC_OMIT_EDIT_FIELDS,
51    ITPURegistration,
52    IUTPRegistration
53    )
54
55UG_OMIT_EDIT_FIELDS = [
56    value for value in UG_OMIT_EDIT_FIELDS
57        if not value in ('jamb_subjects', 'jamb_score', 'jamb_reg_number')]
58
59class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
60    """A display view for applicant data.
61    """
62
63    @property
64    def form_fields(self):
65        target = getattr(self.context.__parent__, 'prefix', None)
66        if target == 'tpu':
67            form_fields = grok.AutoFields(ITPURegistration).omit(
68                'locked', 'suspended')
69            return form_fields
70        if target == 'utp':
71            form_fields = grok.AutoFields(IUTPRegistration).omit(
72                'locked', 'suspended',)
73            return form_fields
74        form_fields = grok.AutoFields(ICustomUGApplicant)
75        if target is not None and target.startswith('bec'):
76            for field in BEC_OMIT_DISPLAY_FIELDS:
77                form_fields = form_fields.omit(field)
78        else:
79            form_fields = grok.AutoFields(ICustomUGApplicant)
80            for field in UG_OMIT_DISPLAY_FIELDS:
81                form_fields = form_fields.omit(field)
82        form_fields['notice'].custom_widget = BytesDisplayWidget
83        form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget
84        if not getattr(self.context, 'student_id'):
85            form_fields = form_fields.omit('student_id')
86        if not getattr(self.context, 'screening_score'):
87            form_fields = form_fields.omit('screening_score')
88        if not getattr(self.context, 'screening_venue'):
89            form_fields = form_fields.omit('screening_venue')
90        if not getattr(self.context, 'screening_date'):
91            form_fields = form_fields.omit('screening_date')
92        return form_fields
93
94class CustomPDFApplicationSlip(PDFApplicationSlip):
95
96    def _reduced_slip(self):
97        return getattr(self.context, 'result_uploaded', False)
98
99    def _getPDFCreator(self):
100        if 'putme' in self.target or 'pude' in self.target:
101            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
102        return getUtility(IPDFCreator)
103
104    @property
105    def title(self):
106        container_title = self.context.__parent__.title
107        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
108        ar_translation = translate(_('Application Record'),
109            'waeup.kofa', target_language=portal_language)
110        if 'putme' in self.target or 'pude' in self.target:
111            return 'IN AFFILIATION WITH UNIVERSITY OF IBADAN - %s %s %s' % (
112                container_title, ar_translation,
113                self.context.application_number)
114        return '%s - %s %s' % (container_title,
115            ar_translation, self.context.application_number)
116
117
118    @property
119    def form_fields(self):
120        target = getattr(self.context.__parent__, 'prefix', None)
121        if target == 'tpu':
122            form_fields = grok.AutoFields(ITPURegistration).omit(
123                'locked', 'suspended')
124            return form_fields
125        if target == 'utp':
126            form_fields = grok.AutoFields(IUTPRegistration).omit(
127                'locked', 'suspended')
128            return form_fields
129        form_fields = grok.AutoFields(ICustomUGApplicant)
130        if target is not None and target.startswith('bec'):
131            for field in BEC_OMIT_PDF_FIELDS:
132                form_fields = form_fields.omit(field)
133        else:
134            form_fields = grok.AutoFields(ICustomUGApplicant)
135            for field in UG_OMIT_PDF_FIELDS:
136                form_fields = form_fields.omit(field)
137        if not getattr(self.context, 'student_id'):
138            form_fields = form_fields.omit('student_id')
139        if not getattr(self.context, 'screening_score'):
140            form_fields = form_fields.omit('screening_score')
141        if not getattr(self.context, 'screening_venue'):
142            form_fields = form_fields.omit('screening_venue')
143        if not getattr(self.context, 'screening_date'):
144            form_fields = form_fields.omit('screening_date')
145        return form_fields
146
147class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
148    """A full edit view for applicant data.
149    """
150   
151    @property
152    def form_fields(self):
153        target = getattr(self.context.__parent__, 'prefix', None)
154        if target == 'tpu':
155            form_fields = grok.AutoFields(ITPURegistration)
156            form_fields['applicant_id'].for_display = True
157            return form_fields
158        if target == 'utp':
159            form_fields = grok.AutoFields(IUTPRegistration)
160            form_fields['applicant_id'].for_display = True
161            return form_fields
162        form_fields = grok.AutoFields(ICustomUGApplicant)
163        if target is not None and target.startswith('bec'):
164            for field in BEC_OMIT_MANAGE_FIELDS:
165                form_fields = form_fields.omit(field)
166        else:
167            for field in UG_OMIT_MANAGE_FIELDS:
168                form_fields = form_fields.omit(field)
169        form_fields['student_id'].for_display = True
170        form_fields['applicant_id'].for_display = True
171        return form_fields
172
173class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
174    """An applicant-centered edit view for applicant data.
175    """
176
177    @property
178    def form_fields(self):
179        target = getattr(self.context.__parent__, 'prefix', None)
180        if target == 'tpu':
181            form_fields = grok.AutoFields(ITPURegistration).omit(
182                'locked', 'suspended')
183            form_fields['applicant_id'].for_display = True
184            form_fields['reg_number'].for_display = True
185            form_fields['firstname'].for_display = True
186            form_fields['middlename'].for_display = True
187            form_fields['lastname'].for_display = True
188            form_fields['lga'].for_display = True
189            form_fields['matric_number'].for_display = True
190            form_fields['subj_comb'].field.required = True
191            form_fields['school_tpu'].field.required = True
192            return form_fields
193        if target == 'utp':
194            form_fields = grok.AutoFields(IUTPRegistration).omit(
195                'locked', 'suspended')
196            form_fields['applicant_id'].for_display = True
197            form_fields['reg_number'].for_display = True
198            form_fields['firstname'].for_display = True
199            form_fields['middlename'].for_display = True
200            form_fields['lastname'].for_display = True
201            form_fields['lga'].for_display = True
202            form_fields['matric_number'].for_display = True
203            form_fields['subj_comb'].field.required = True
204            form_fields['school_utp'].field.required = True
205            return form_fields
206        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
207        if target is not None and target.startswith('bec'):
208            for field in BEC_OMIT_EDIT_FIELDS:
209                form_fields = form_fields.omit(field)
210        else:
211            for field in UG_OMIT_EDIT_FIELDS:
212                form_fields = form_fields.omit(field)
213        form_fields['applicant_id'].for_display = True
214        form_fields['reg_number'].for_display = True
215        return form_fields
216
217    def _students_per_school_exceeded(self, data):
218        container = self.context.__parent__
219        counter_school = 0
220        counter_subj_per_school = 0
221        target = getattr(container, 'prefix', None)
222        if target == 'tpu':
223            school = 'school_tpu'
224            max_schools = 5
225            max_subj_per_school = 1
226        else:
227            max_schools = 7
228            max_subj_per_school = 2
229            school = 'school_utp'
230        for appl in container.values():
231            if appl != self.context \
232                and appl.state in (SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED):
233                if getattr(appl, school) == data.get(school):
234                    counter_school += 1
235                    if appl.subj_comb == data.get('subj_comb'):
236                        counter_subj_per_school += 1
237                    if counter_subj_per_school == max_subj_per_school:
238                        return True
239                if counter_school == max_schools:
240                    return True
241        return False
242
243    def dataNotComplete(self, data):
244        target = getattr(self.context.__parent__, 'prefix', None)
245        if target in ('tpu', 'utp'):
246            if self._students_per_school_exceeded(data):
247                return ("1st Choice School: "
248                        "Maximum number of applications per school exceeded. "
249                        "Please select another first choice school.")
250        super(CustomApplicantEditFormPage, self).dataNotComplete(data)
251        return
Note: See TracBrowser for help on using the repository browser.