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

Last change on this file since 17931 was 17748, checked in by Henrik Bettermann, 5 months ago

Also ApplicantRegistrationPage? must be customized.

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