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

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

Implement transcript application.

  • Property svn:keywords set to Id
File size: 15.4 KB
Line 
1## $Id: browser.py 16142 2020-07-03 07:11:31Z 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, queryUtility
23from zope.catalog.interfaces import ICatalog
24from zope.formlib.textwidgets import BytesDisplayWidget
25from waeup.kofa.interfaces import (
26    IExtFileStore, IFileStoreNameChooser)
27from waeup.kofa.utils.helpers import string_from_bytes, file_size, now
28from waeup.kofa.applicants.browser import (
29    ApplicantRegistrationPage, ApplicantsContainerPage, AdditionalFile,
30    RefereeReportAddFormPage, ExportPDFReportSlipPage, ExportPDFReportSlipPage2,
31    RefereeReportDisplayFormPage)
32from waeup.kofa.applicants.interfaces import (
33    ISpecialApplicant, IApplicantsContainer, AppCatCertificateSource)
34from kofacustom.nigeria.applicants.browser import (
35    NigeriaApplicantDisplayFormPage,
36    NigeriaApplicantManageFormPage,
37    NigeriaApplicantEditFormPage,
38    NigeriaPDFApplicationSlip)
39from waeup.kofa.widgets.datewidget import (
40    FriendlyDateDisplayWidget,
41    FriendlyDatetimeDisplayWidget)
42from kofacustom.nigeria.applicants.interfaces import (
43    OMIT_DISPLAY_FIELDS,
44    #UG_OMIT_DISPLAY_FIELDS,
45    #UG_OMIT_PDF_FIELDS,
46    #UG_OMIT_MANAGE_FIELDS,
47    #UG_OMIT_EDIT_FIELDS,
48    #PG_OMIT_DISPLAY_FIELDS,
49    #PG_OMIT_PDF_FIELDS,
50    #PG_OMIT_MANAGE_FIELDS,
51    #PG_OMIT_EDIT_FIELDS,
52    )
53from kofacustom.iuokada.applicants.interfaces import (
54    ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant,
55    ICustomPGApplicantEdit, ICustomUGApplicantEdit,
56    ICustomApplicantOnlinePayment, ICustomApplicantRefereeReport,
57    ITranscriptApplicant
58    )
59from kofacustom.iuokada.interfaces import MessageFactory as _
60
61MAX_FILE_UPLOAD_SIZE = 1024 * 500
62
63# UG students are all undergraduate students.
64UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
65    #'jamb_subjects_list',
66    'programme_type',)
67UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',)
68UG_OMIT_MANAGE_FIELDS = (
69    'special_application',
70    #'jamb_subjects_list',
71    'programme_type',
72    'course1',
73    'course2',)
74UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
75    'student_id',
76    'notice',
77    'screening_score',
78    'screening_venue',
79    'screening_date',
80    #'jamb_age',
81    #'jamb_subjects',
82    #'jamb_score',
83    #'jamb_reg_number',
84    'aggregate',
85    )
86
87# PG has its own interface
88PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
89    'employer',
90    'emp_position',
91    'emp_start',
92    'emp_end',
93    'emp_reason',
94    'employer2',
95    'emp2_position',
96    'emp2_start',
97    'emp2_end',
98    'emp2_reason',
99    )
100PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + ('phone',)
101PG_OMIT_MANAGE_FIELDS = (
102    'special_application',
103    'employer',
104    'emp_position',
105    'emp_start',
106    'emp_end',
107    'emp_reason',
108    'employer2',
109    'emp2_position',
110    'emp2_start',
111    'emp2_end',
112    'emp2_reason',
113    'course1',
114    'course2',
115    )
116PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + PG_OMIT_DISPLAY_FIELDS + (
117    'student_id',
118    'notice',
119    'screening_score',
120    'screening_venue',
121    'screening_date',)
122
123TRANS_OMIT_FIELDS = ('locked', 'suspended', 'applicant_id',)
124
125TRANS_SHORT_OMIT_FIELDS = TRANS_OMIT_FIELDS + (
126    'date_of_birth',
127    'sex',
128    'nationality',
129    'entry_mode',
130    'entry_session',
131    'end_session',
132    'course_studied',
133    'course_changed',
134    'change_level',
135    )
136
137class CustomApplicantsContainerPage(ApplicantsContainerPage):
138    """The standard view for regular applicant containers.
139    """
140
141    @property
142    def form_fields(self):
143        form_fields = grok.AutoFields(IApplicantsContainer).omit(
144            'title', 'description')
145        if self.request.principal.id == 'zope.anybody':
146            form_fields = form_fields.omit(
147                'code', 'prefix', 'year', 'mode', 'hidden',
148                'strict_deadline', 'application_category',
149                'application_slip_notice',
150                'application_fee', 'with_picture',
151                'startdate', 'enddate')
152        return form_fields
153
154class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
155    """A display view for applicant data.
156    """
157
158    @property
159    def form_fields(self):
160        if self.target is not None and self.target == 'transfull':
161            form_fields = grok.AutoFields(ITranscriptApplicant)
162            for field in TRANS_OMIT_FIELDS:
163                form_fields = form_fields.omit(field)
164            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
165            form_fields['perm_address'].custom_widget = BytesDisplayWidget
166            return form_fields
167        if self.target is not None and self.target == 'transshort':
168            form_fields = grok.AutoFields(ITranscriptApplicant)
169            for field in TRANS_SHORT_OMIT_FIELDS:
170                form_fields = form_fields.omit(field)
171            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
172            form_fields['perm_address'].custom_widget = BytesDisplayWidget
173            return form_fields
174        if self.target is not None and self.target.startswith('pg'):
175            form_fields = grok.AutoFields(ICustomPGApplicant)
176            for field in PG_OMIT_DISPLAY_FIELDS:
177                form_fields = form_fields.omit(field)
178        else:
179            form_fields = grok.AutoFields(ICustomUGApplicant)
180            for field in UG_OMIT_DISPLAY_FIELDS:
181                form_fields = form_fields.omit(field)
182        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
183        form_fields['notice'].custom_widget = BytesDisplayWidget
184        if not getattr(self.context, 'student_id'):
185            form_fields = form_fields.omit('student_id')
186        if not getattr(self.context, 'screening_score'):
187            form_fields = form_fields.omit('screening_score')
188        if not getattr(self.context, 'screening_venue') or self._not_paid():
189            form_fields = form_fields.omit('screening_venue')
190        if not getattr(self.context, 'screening_date') or self._not_paid():
191            form_fields = form_fields.omit('screening_date')
192        return form_fields
193
194class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
195    """A full edit view for applicant data.
196    """
197
198    def getCerts(self, coursex):
199        yield(dict(code='', title='--', selected=''))
200        appcatcertificatesource = AppCatCertificateSource().factory
201        for cert in appcatcertificatesource.getValues(self.context):
202            selected = ''
203            course = getattr(self.context, coursex)
204            if course is not None and course.code == cert.code:
205                selected = 'selected'
206            title = appcatcertificatesource.getTitle(self.context, cert)
207            yield(dict(code=cert.code, title=title, selected=selected))
208
209    def saveCourses(self, changed_fields):
210        """In custom packages we needed to customize the certificate
211        select widget. We just save course1 and course2 if these customized
212        fields appear in the form.
213        """
214        form = self.request.form
215        course1 = form.get('custom.course1', None)
216        course2 = form.get('custom.course2', None)
217        cat = queryUtility(ICatalog, name='certificates_catalog')
218        if course1:
219            results = list(
220                cat.searchResults(code=(course1, course1)))
221            self.context.course1 = results[0]
222            changed_fields.append('course1')
223        if course2:
224            results = list(
225                cat.searchResults(code=(course2, course2)))
226            self.context.course2 = results[0]
227            changed_fields.append('course2')
228        return changed_fields
229
230    @property
231    def display_refereereports(self):
232        if self.context.refereereports:
233            return True
234        return False
235
236    @property
237    def form_fields(self):
238        if self.target is not None and self.target == 'transfull':
239            form_fields = grok.AutoFields(ITranscriptApplicant)
240            for field in TRANS_OMIT_FIELDS:
241                form_fields = form_fields.omit(field)
242            return form_fields
243        if self.target is not None and self.target == 'transshort':
244            form_fields = grok.AutoFields(ITranscriptApplicant)
245            for field in TRANS_SHORT_OMIT_FIELDS:
246                form_fields = form_fields.omit(field)
247            return form_fields
248        if self.target is not None and self.target.startswith('pg'):
249            form_fields = grok.AutoFields(ICustomPGApplicant)
250            for field in PG_OMIT_MANAGE_FIELDS:
251                form_fields = form_fields.omit(field)
252        else:
253            form_fields = grok.AutoFields(ICustomUGApplicant)
254            for field in UG_OMIT_MANAGE_FIELDS:
255                form_fields = form_fields.omit(field)
256        form_fields['student_id'].for_display = True
257        form_fields['applicant_id'].for_display = True
258        return form_fields
259
260class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
261    """An applicant-centered edit view for applicant data.
262    """
263
264    def getCerts(self, coursex):
265        yield(dict(code='', title='--', selected=''))
266        appcatcertificatesource = AppCatCertificateSource().factory
267        for cert in appcatcertificatesource.getValues(self.context):
268            selected = ''
269            course = getattr(self.context, coursex)
270            if course is not None and course.code == cert.code:
271                selected = 'selected'
272            title = appcatcertificatesource.getTitle(self.context, cert)
273            yield(dict(code=cert.code, title=title, selected=selected))
274
275    def saveCourses(self):
276        """In custom packages we needed to customize the certificate
277        select widget. We just save course1 and course2 if these customized
278        fields appear in the form.
279        """
280        form = self.request.form
281        course1 = form.get('custom.course1', None)
282        course2 = form.get('custom.course2', None)
283        cat = queryUtility(ICatalog, name='certificates_catalog')
284        if course1:
285            results = list(
286                cat.searchResults(code=(course1, course1)))
287            self.context.course1 = results[0]
288        if course2:
289            results = list(
290                cat.searchResults(code=(course2, course2)))
291            self.context.course2 = results[0]
292        return
293
294    def display_fileupload(self, filename):
295        if filename[1] == 'res_stat.pdf':
296            if self.context.subtype != 'transfer':
297                return False
298        if filename[1] == 'jamb.pdf' \
299            and self.target is not None \
300            and self.target.startswith('pg'):
301            return False
302        if filename[1] == 'nysc.pdf' \
303            and self.target is not None \
304            and not self.target.startswith('pg'):
305            return False
306        return True
307
308    def dataNotComplete(self, data):
309        store = getUtility(IExtFileStore)
310        if self.context.__parent__.with_picture:
311            store = getUtility(IExtFileStore)
312            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
313                return _('No passport picture uploaded.')
314        if self.context.subtype == 'transfer' \
315            and self.context.__parent__.code!= 'ug2020' \
316            and not store.getFileByContext(self.context, attr=u'res_stat.pdf'):
317            return _('No statement of result pdf file uploaded.')
318        return False
319
320    @property
321    def form_fields(self):
322        if self.target is not None and self.target == 'transfull':
323            form_fields = grok.AutoFields(ITranscriptApplicant)
324            for field in TRANS_OMIT_FIELDS:
325                form_fields = form_fields.omit(field)
326            return form_fields
327        if self.target is not None and self.target == 'transshort':
328            form_fields = grok.AutoFields(ITranscriptApplicant)
329            for field in TRANS_SHORT_OMIT_FIELDS:
330                form_fields = form_fields.omit(field)
331            return form_fields
332        if self.target is not None and self.target.startswith('pg'):
333            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
334            for field in PG_OMIT_EDIT_FIELDS:
335                form_fields = form_fields.omit(field)
336        else:
337            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
338            for field in UG_OMIT_EDIT_FIELDS:
339                form_fields = form_fields.omit(field)
340        form_fields['applicant_id'].for_display = True
341        form_fields['reg_number'].for_display = True
342        return form_fields
343
344class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
345
346    @property
347    def form_fields(self):
348        if self.target is not None and self.target.startswith('pg'):
349            form_fields = grok.AutoFields(ICustomPGApplicant)
350            for field in PG_OMIT_PDF_FIELDS:
351                form_fields = form_fields.omit(field)
352        else:
353            form_fields = grok.AutoFields(ICustomUGApplicant)
354            for field in UG_OMIT_PDF_FIELDS:
355                form_fields = form_fields.omit(field)
356        if not getattr(self.context, 'student_id'):
357            form_fields = form_fields.omit('student_id')
358        if not getattr(self.context, 'screening_score'):
359            form_fields = form_fields.omit('screening_score')
360        if not getattr(self.context, 'screening_venue'):
361            form_fields = form_fields.omit('screening_venue')
362        if not getattr(self.context, 'screening_date'):
363            form_fields = form_fields.omit('screening_date')
364        return form_fields
365
366class RefereeReportAddFormPage(RefereeReportAddFormPage):
367    """Add-form to add an referee report. This form
368    is protected by a mandate.
369    """
370    form_fields = grok.AutoFields(
371        ICustomApplicantRefereeReport).omit('creation_date')
372
373class CustomRefereeReportDisplayFormPage(RefereeReportDisplayFormPage):
374    """A display view for referee reports.
375    """
376    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
377    form_fields[
378        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
379
380
381class CustomExportPDFReportSlipPage(ExportPDFReportSlipPage):
382    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
383    form_fields[
384        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
385
386class CustomExportPDFReportSlipPage2(ExportPDFReportSlipPage2):
387    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
388    form_fields[
389        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
390
391class ResultStatement(AdditionalFile):
392    grok.name('res_stat.pdf')
393
394class JAMBResult(AdditionalFile):
395    grok.name('jamb.pdf')
396
397class FirstSitting(AdditionalFile):
398    grok.name('fst_sit_scan.pdf')
399
400class SecondSitting(AdditionalFile):
401    grok.name('scd_sit_scan.pdf')
402
403class HighQual(AdditionalFile):
404    grok.name('hq_scan.pdf')
405
406class AdvancedLevelResult(AdditionalFile):
407    grok.name('alr_scan.pdf')
408
409class NYSCCertificate(AdditionalFile):
410    grok.name('nysc.pdf')
Note: See TracBrowser for help on using the repository browser.