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

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

Customize referee reports.

  • Property svn:keywords set to Id
File size: 10.5 KB
Line 
1## $Id: browser.py 16062 2020-04-20 08:40:41Z 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)
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 display_refereereports(self):
165        if self.context.refereereports:
166            return True
167        return False
168
169    @property
170    def form_fields(self):
171        if self.target is not None and self.target.startswith('pg'):
172            form_fields = grok.AutoFields(ICustomPGApplicant)
173            for field in PG_OMIT_MANAGE_FIELDS:
174                form_fields = form_fields.omit(field)
175        else:
176            form_fields = grok.AutoFields(ICustomUGApplicant)
177            for field in UG_OMIT_MANAGE_FIELDS:
178                form_fields = form_fields.omit(field)
179        form_fields['student_id'].for_display = True
180        form_fields['applicant_id'].for_display = True
181        return form_fields
182
183class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
184    """An applicant-centered edit view for applicant data.
185    """
186
187    def display_fileupload(self, filename):
188        if filename[1] == 'res_stat.pdf':
189            if self.context.subtype != 'transfer':
190                return False
191        if filename[1] == 'jamb.pdf' \
192            and self.target is not None \
193            and self.target.startswith('pg'):
194            return False
195        if filename[1] == 'nysc.pdf' \
196            and self.target is not None \
197            and not self.target.startswith('pg'):
198            return False
199        return True
200
201    def dataNotComplete(self, data):
202        store = getUtility(IExtFileStore)
203        if self.context.__parent__.with_picture:
204            store = getUtility(IExtFileStore)
205            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
206                return _('No passport picture uploaded.')
207            if not self.request.form.get('confirm_passport', False):
208                return _('Passport picture confirmation box not ticked.')
209        if self.context.subtype == 'transfer' and \
210            not store.getFileByContext(self.context, attr=u'res_stat.pdf'):
211            return _('No statement of result pdf file uploaded.')
212        return False
213
214    @property
215    def form_fields(self):
216        if self.target is not None and self.target.startswith('pg'):
217            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
218            for field in PG_OMIT_EDIT_FIELDS:
219                form_fields = form_fields.omit(field)
220        else:
221            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
222            for field in UG_OMIT_EDIT_FIELDS:
223                form_fields = form_fields.omit(field)
224        form_fields['applicant_id'].for_display = True
225        form_fields['reg_number'].for_display = True
226        return form_fields
227
228class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
229
230    @property
231    def form_fields(self):
232        if self.target is not None and self.target.startswith('pg'):
233            form_fields = grok.AutoFields(ICustomPGApplicant)
234            for field in PG_OMIT_PDF_FIELDS:
235                form_fields = form_fields.omit(field)
236        else:
237            form_fields = grok.AutoFields(ICustomUGApplicant)
238            for field in UG_OMIT_PDF_FIELDS:
239                form_fields = form_fields.omit(field)
240        if not getattr(self.context, 'student_id'):
241            form_fields = form_fields.omit('student_id')
242        if not getattr(self.context, 'screening_score'):
243            form_fields = form_fields.omit('screening_score')
244        if not getattr(self.context, 'screening_venue'):
245            form_fields = form_fields.omit('screening_venue')
246        if not getattr(self.context, 'screening_date'):
247            form_fields = form_fields.omit('screening_date')
248        return form_fields
249
250class RefereeReportAddFormPage(RefereeReportAddFormPage):
251    """Add-form to add an referee report. This form
252    is protected by a mandate.
253    """
254    form_fields = grok.AutoFields(
255        ICustomApplicantRefereeReport).omit('creation_date')
256
257class CustomRefereeReportDisplayFormPage(RefereeReportDisplayFormPage):
258    """A display view for referee reports.
259    """
260    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
261    form_fields[
262        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
263
264
265class CustomExportPDFReportSlipPage(ExportPDFReportSlipPage):
266    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
267    form_fields[
268        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
269
270class CustomExportPDFReportSlipPage2(ExportPDFReportSlipPage2):
271    form_fields = grok.AutoFields(ICustomApplicantRefereeReport)
272    form_fields[
273        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
274
275class ResultStatement(AdditionalFile):
276    grok.name('res_stat.pdf')
277
278class JAMBResult(AdditionalFile):
279    grok.name('jamb.pdf')
280
281class FirstSitting(AdditionalFile):
282    grok.name('fst_sit_scan.pdf')
283
284class SecondSitting(AdditionalFile):
285    grok.name('scd_sit_scan.pdf')
286
287class HighQual(AdditionalFile):
288    grok.name('hq_scan.pdf')
289
290class AdvancedLevelResult(AdditionalFile):
291    grok.name('alr_scan.pdf')
292
293class NYSCCertificate(AdditionalFile):
294    grok.name('nysc.pdf')
Note: See TracBrowser for help on using the repository browser.