source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/browser.py @ 16070

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

Certificate filter box (for demonstration purposes!!!)

  • Property svn:keywords set to Id
File size: 10.8 KB
Line 
1## $Id: browser.py 16070 2020-04-24 06:59:45Z 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
21import os
22from zope.component import getUtility
23from zope.formlib.textwidgets import BytesDisplayWidget
24from waeup.kofa.interfaces import (
25    IExtFileStore, IFileStoreNameChooser)
26from waeup.kofa.utils.helpers import string_from_bytes, file_size, now
27from waeup.kofa.applicants.browser import (
28    ApplicantRegistrationPage, ApplicantsContainerPage, AdditionalFile,
29    RefereeReportAddFormPage, ExportPDFReportSlipPage, ExportPDFReportSlipPage2,
30    RefereeReportDisplayFormPage)
31from waeup.kofa.applicants.interfaces import (
32    ISpecialApplicant, IApplicantsContainer, AppCatCertificateSource)
33from kofacustom.nigeria.applicants.browser import (
34    NigeriaApplicantDisplayFormPage,
35    NigeriaApplicantManageFormPage,
36    NigeriaApplicantEditFormPage,
37    NigeriaPDFApplicationSlip)
38from waeup.kofa.widgets.datewidget import (
39    FriendlyDateDisplayWidget,
40    FriendlyDatetimeDisplayWidget)
41from kofacustom.nigeria.applicants.interfaces import (
42    OMIT_DISPLAY_FIELDS,
43    #UG_OMIT_DISPLAY_FIELDS,
44    #UG_OMIT_PDF_FIELDS,
45    #UG_OMIT_MANAGE_FIELDS,
46    #UG_OMIT_EDIT_FIELDS,
47    #PG_OMIT_DISPLAY_FIELDS,
48    #PG_OMIT_PDF_FIELDS,
49    #PG_OMIT_MANAGE_FIELDS,
50    #PG_OMIT_EDIT_FIELDS,
51    )
52from kofacustom.iuokada.applicants.interfaces import (
53    ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant,
54    ICustomPGApplicantEdit, ICustomUGApplicantEdit,
55    ICustomApplicantOnlinePayment, ICustomApplicantRefereeReport
56    )
57from kofacustom.iuokada.interfaces import MessageFactory as _
58
59MAX_FILE_UPLOAD_SIZE = 1024 * 500
60
61# UG students are all undergraduate students.
62UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
63    #'jamb_subjects_list',
64    'programme_type',)
65UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',)
66UG_OMIT_MANAGE_FIELDS = (
67    'special_application',
68    #'jamb_subjects_list',
69    'programme_type')
70UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
71    'student_id',
72    'notice',
73    'screening_score',
74    'screening_venue',
75    'screening_date',
76    #'jamb_age',
77    #'jamb_subjects',
78    #'jamb_score',
79    #'jamb_reg_number',
80    'aggregate')
81
82# PG has its own interface
83PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
84    'employer',
85    'emp_position',
86    'emp_start',
87    'emp_end',
88    'emp_reason',
89    'employer2',
90    'emp2_position',
91    'emp2_start',
92    'emp2_end',
93    'emp2_reason',
94    )
95PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + ('phone',)
96PG_OMIT_MANAGE_FIELDS = (
97    'special_application',
98    'employer',
99    'emp_position',
100    'emp_start',
101    'emp_end',
102    'emp_reason',
103    'employer2',
104    'emp2_position',
105    'emp2_start',
106    'emp2_end',
107    'emp2_reason',
108    )
109PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + PG_OMIT_DISPLAY_FIELDS + (
110    'student_id',
111    'notice',
112    'screening_score',
113    'screening_venue',
114    'screening_date',)
115
116class CustomApplicantsContainerPage(ApplicantsContainerPage):
117    """The standard view for regular applicant containers.
118    """
119
120    @property
121    def form_fields(self):
122        form_fields = grok.AutoFields(IApplicantsContainer).omit(
123            'title', 'description')
124        if self.request.principal.id == 'zope.anybody':
125            form_fields = form_fields.omit(
126                'code', 'prefix', 'year', 'mode', 'hidden',
127                'strict_deadline', 'application_category',
128                'application_slip_notice',
129                'application_fee', 'with_picture',
130                'startdate', 'enddate')
131        return form_fields
132
133class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
134    """A display view for applicant data.
135    """
136
137    @property
138    def form_fields(self):
139        if self.target is not None and self.target.startswith('pg'):
140            form_fields = grok.AutoFields(ICustomPGApplicant)
141            for field in PG_OMIT_DISPLAY_FIELDS:
142                form_fields = form_fields.omit(field)
143        else:
144            form_fields = grok.AutoFields(ICustomUGApplicant)
145            for field in UG_OMIT_DISPLAY_FIELDS:
146                form_fields = form_fields.omit(field)
147        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
148        form_fields['notice'].custom_widget = BytesDisplayWidget
149        if not getattr(self.context, 'student_id'):
150            form_fields = form_fields.omit('student_id')
151        if not getattr(self.context, 'screening_score'):
152            form_fields = form_fields.omit('screening_score')
153        if not getattr(self.context, 'screening_venue') or self._not_paid():
154            form_fields = form_fields.omit('screening_venue')
155        if not getattr(self.context, 'screening_date') or self._not_paid():
156            form_fields = form_fields.omit('screening_date')
157        return form_fields
158
159class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
160    """A full edit view for applicant data.
161    """
162
163    @property
164    def certs(self):
165        appcatcertificatesource = AppCatCertificateSource().factory
166        for code in appcatcertificatesource.getValues(self.context):
167            title = appcatcertificatesource.getTitle(self.context, code)
168            yield(code, title)
169
170    @property
171    def display_refereereports(self):
172        if self.context.refereereports:
173            return True
174        return False
175
176    @property
177    def form_fields(self):
178        if self.target is not None and self.target.startswith('pg'):
179            form_fields = grok.AutoFields(ICustomPGApplicant)
180            for field in PG_OMIT_MANAGE_FIELDS:
181                form_fields = form_fields.omit(field)
182        else:
183            form_fields = grok.AutoFields(ICustomUGApplicant)
184            for field in UG_OMIT_MANAGE_FIELDS:
185                form_fields = form_fields.omit(field)
186        form_fields['student_id'].for_display = True
187        form_fields['applicant_id'].for_display = True
188        return form_fields
189
190class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
191    """An applicant-centered edit view for applicant data.
192    """
193
194    grok.template('applicanteditpage')
195
196    def display_fileupload(self, filename):
197        if filename[1] == 'res_stat.pdf':
198            if self.context.subtype != 'transfer':
199                return False
200        if filename[1] == 'jamb.pdf' \
201            and self.target is not None \
202            and self.target.startswith('pg'):
203            return False
204        if filename[1] == 'nysc.pdf' \
205            and self.target is not None \
206            and not self.target.startswith('pg'):
207            return False
208        return True
209
210    def dataNotComplete(self, data):
211        store = getUtility(IExtFileStore)
212        if self.context.__parent__.with_picture:
213            store = getUtility(IExtFileStore)
214            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
215                return _('No passport picture uploaded.')
216            if not self.request.form.get('confirm_passport', False):
217                return _('Passport picture confirmation box not ticked.')
218        if self.context.subtype == 'transfer' and \
219            not store.getFileByContext(self.context, attr=u'res_stat.pdf'):
220            return _('No statement of result pdf file uploaded.')
221        return False
222
223    @property
224    def form_fields(self):
225        if self.target is not None and self.target.startswith('pg'):
226            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
227            for field in PG_OMIT_EDIT_FIELDS:
228                form_fields = form_fields.omit(field)
229        else:
230            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
231            for field in UG_OMIT_EDIT_FIELDS:
232                form_fields = form_fields.omit(field)
233        form_fields['applicant_id'].for_display = True
234        form_fields['reg_number'].for_display = True
235        return form_fields
236
237class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
238
239    @property
240    def form_fields(self):
241        if self.target is not None and self.target.startswith('pg'):
242            form_fields = grok.AutoFields(ICustomPGApplicant)
243            for field in PG_OMIT_PDF_FIELDS:
244                form_fields = form_fields.omit(field)
245        else:
246            form_fields = grok.AutoFields(ICustomUGApplicant)
247            for field in UG_OMIT_PDF_FIELDS:
248                form_fields = form_fields.omit(field)
249        if not getattr(self.context, 'student_id'):
250            form_fields = form_fields.omit('student_id')
251        if not getattr(self.context, 'screening_score'):
252            form_fields = form_fields.omit('screening_score')
253        if not getattr(self.context, 'screening_venue'):
254            form_fields = form_fields.omit('screening_venue')
255        if not getattr(self.context, 'screening_date'):
256            form_fields = form_fields.omit('screening_date')
257        return form_fields
258
259class RefereeReportAddFormPage(RefereeReportAddFormPage):
260    """Add-form to add an referee report. This form
261    is protected by a mandate.
262    """
263    form_fields = grok.AutoFields(
264        ICustomApplicantRefereeReport).omit('creation_date')
265
266class CustomRefereeReportDisplayFormPage(RefereeReportDisplayFormPage):
267    """A display view for referee reports.
268    """
269    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
270    form_fields[
271        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
272
273
274class CustomExportPDFReportSlipPage(ExportPDFReportSlipPage):
275    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
276    form_fields[
277        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
278
279class CustomExportPDFReportSlipPage2(ExportPDFReportSlipPage2):
280    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
281    form_fields[
282        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
283
284class ResultStatement(AdditionalFile):
285    grok.name('res_stat.pdf')
286
287class JAMBResult(AdditionalFile):
288    grok.name('jamb.pdf')
289
290class FirstSitting(AdditionalFile):
291    grok.name('fst_sit_scan.pdf')
292
293class SecondSitting(AdditionalFile):
294    grok.name('scd_sit_scan.pdf')
295
296class HighQual(AdditionalFile):
297    grok.name('hq_scan.pdf')
298
299class AdvancedLevelResult(AdditionalFile):
300    grok.name('alr_scan.pdf')
301
302class NYSCCertificate(AdditionalFile):
303    grok.name('nysc.pdf')
Note: See TracBrowser for help on using the repository browser.