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

Last change on this file since 17431 was 17359, checked in by Henrik Bettermann, 22 months ago

Set required field for teaching practice in CustomApplicantEditFormPage?.

  • Property svn:keywords set to Id
File size: 10.5 KB
RevLine 
[9463]1## $Id: browser.py 17359 2023-03-21 22:31:54Z 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,
[16918]51    ITPURegistration,
52    IUTPRegistration
[9463]53    )
54
[10533]55UG_OMIT_EDIT_FIELDS = [
56    value for value in UG_OMIT_EDIT_FIELDS
[13238]57        if not value in ('jamb_subjects', 'jamb_score', 'jamb_reg_number')]
[10533]58
[10529]59class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
[9463]60    """A display view for applicant data.
61    """
62
63    @property
64    def form_fields(self):
65        target = getattr(self.context.__parent__, 'prefix', None)
[13877]66        if target == 'tpu':
67            form_fields = grok.AutoFields(ITPURegistration).omit(
68                'locked', 'suspended')
69            return form_fields
[16918]70        if target == 'utp':
71            form_fields = grok.AutoFields(IUTPRegistration).omit(
72                'locked', 'suspended',)
73            return form_fields
[9463]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
[10533]83        form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget
[9463]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
[10570]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
[9463]104    @property
[10570]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
[9463]119    def form_fields(self):
120        target = getattr(self.context.__parent__, 'prefix', None)
[13877]121        if target == 'tpu':
122            form_fields = grok.AutoFields(ITPURegistration).omit(
123                'locked', 'suspended')
124            return form_fields
[16918]125        if target == 'utp':
126            form_fields = grok.AutoFields(IUTPRegistration).omit(
127                'locked', 'suspended')
128            return form_fields
[9463]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
[10529]147class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
[9463]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)
[13877]154        if target == 'tpu':
155            form_fields = grok.AutoFields(ITPURegistration)
156            form_fields['applicant_id'].for_display = True
157            return form_fields
[16918]158        if target == 'utp':
159            form_fields = grok.AutoFields(IUTPRegistration)
160            form_fields['applicant_id'].for_display = True
161            return form_fields
[9463]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
[10529]173class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
[9463]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)
[13877]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
[17359]190            form_fields['subj_comb'].field.required = True
191            form_fields['school_tpu'].field.required = True
[13877]192            return form_fields
[16918]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
[17359]203            form_fields['subj_comb'].field.required = True
204            form_fields['school_utp'].field.required = True
[16918]205            return form_fields
[9481]206        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
[9463]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
[14499]215        return form_fields
216
[16918]217    def _students_per_school_exceeded(self, data):
[14499]218        container = self.context.__parent__
[16931]219        counter_school = 0
220        counter_subj_per_school = 0
[16925]221        target = getattr(container, 'prefix', None)
222        if target == 'tpu':
[16926]223            school = 'school_tpu'
[16931]224            max_schools = 10
225            max_subj_per_school = 1
[16925]226        else:
[16931]227            max_schools = 7
228            max_subj_per_school = 2
[16926]229            school = 'school_utp'
[15635]230        for appl in container.values():
[16863]231            if appl != self.context \
232                and appl.state in (SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED):
[16926]233                if getattr(appl, school) == data.get(school):
[16931]234                    counter_school += 1
[16863]235                    if appl.subj_comb == data.get('subj_comb'):
[16931]236                        counter_subj_per_school += 1
237                    if counter_subj_per_school == max_subj_per_school:
[16848]238                        return True
[16931]239                if counter_school == max_schools:
[15635]240                    return True
[14499]241        return False
242
[15635]243    def dataNotComplete(self, data):
[15641]244        target = getattr(self.context.__parent__, 'prefix', None)
[16918]245        if target in ('tpu', 'utp'):
246            if self._students_per_school_exceeded(data):
247                return ("1st Choice School: "
[15641]248                        "Maximum number of applications per school exceeded. "
249                        "Please select another first choice school.")
[15635]250        super(CustomApplicantEditFormPage, self).dataNotComplete(data)
[14499]251        return
Note: See TracBrowser for help on using the repository browser.