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

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

Sort certificates.

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