source: main/waeup.aaue/trunk/src/waeup/aaue/applicants/browser.py @ 13719

Last change on this file since 13719 was 13679, checked in by Henrik Bettermann, 9 years ago

Add emplayment history fields.

Define omit fields for ptee application.

  • Property svn:keywords set to Id
File size: 12.0 KB
Line 
1## $Id: browser.py 13679 2016-02-11 13:23:15Z 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 waeup.kofa.interfaces import (
24    IExtFileStore, IFileStoreNameChooser)
25from zope.formlib.textwidgets import BytesDisplayWidget
26from waeup.kofa.utils.helpers import string_from_bytes, file_size
27from waeup.kofa.applicants.browser import ApplicantCheckStatusPage
28from waeup.kofa.applicants.viewlets import PDFActionButton
29from waeup.aaue.interfaces import MessageFactory as _
30from kofacustom.nigeria.applicants.browser import (
31    NigeriaApplicantDisplayFormPage,
32    NigeriaApplicantManageFormPage,
33    NigeriaApplicantEditFormPage,
34    NigeriaPDFApplicationSlip,
35    NigeriaApplicantRegistrationPage,
36    NigeriaExportPDFPaymentSlipPage,
37    )
38from kofacustom.nigeria.applicants.interfaces import OMIT_DISPLAY_FIELDS
39from waeup.aaue.applicants.interfaces import (
40    ICustomUGApplicant,
41    ICustomUGApplicantEdit,
42    ITranscriptApplicant
43    )
44
45UG_OMIT_FIELDS = (
46      'hq_type', 'hq_fname', 'hq_matric_no',
47      'hq_degree', 'hq_school', 'hq_session', 'hq_disc',
48      'hq_type2', 'hq_fname2', 'hq_matric_no2',
49      'hq_degree2', 'hq_school2', 'hq_session2', 'hq_disc2',
50      'hq_type3', 'hq_fname3', 'hq_matric_no3',
51      'hq_degree3', 'hq_school3', 'hq_session3', 'hq_disc3',
52      'nysc_year',
53      'nysc_location',
54      'nysc_lga',
55      'employer',
56      'emp_position',
57      'emp_start',
58      'emp_end',
59      'emp_reason',
60      'employer2',
61      'emp2_position',
62      'emp2_start',
63      'emp2_end',
64      'emp2_reason',
65      'former_matric',
66      )
67UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
68    'jamb_subjects_list',) + UG_OMIT_FIELDS
69UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + UG_OMIT_FIELDS + (
70      'reg_number','alr_fname', 'alr_no', 'alr_date',
71      'alr_results', 'notice')
72UG_OMIT_MANAGE_FIELDS = (
73    'special_application','jamb_subjects_list',) + UG_OMIT_FIELDS
74UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
75    'student_id',
76    'notice',
77    'jamb_age',
78    'jamb_subjects',
79    'jamb_score',
80    'jamb_reg_number',
81    'aggregate',
82    )
83
84#UG_OMIT_PDF_FIELDS = tuple([
85#    element for element in UG_OMIT_PDF_FIELDS if not element == 'phone'])
86
87#UG_OMIT_PDF_FIELDS += (
88#      'reg_number','alr_fname', 'alr_no', 'alr_date',
89#      'alr_results', 'notice'
90#      )
91
92PG_OMIT_FIELDS = (
93    'fst_sit_fname',
94    'fst_sit_no',
95    'fst_sit_date',
96    'fst_sit_type',
97    'fst_sit_results',
98    'scd_sit_fname',
99    'scd_sit_no',
100    'scd_sit_date',
101    'scd_sit_type',
102    'scd_sit_results',
103    'programme_type',
104    'jamb_age',
105    'jamb_subjects',
106    'jamb_score',
107    'jamb_reg_number',
108    'aggregate'
109    )
110PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
111    'jamb_subjects_list',) + PG_OMIT_FIELDS
112PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + PG_OMIT_FIELDS + (
113      'reg_number','alr_fname', 'alr_no', 'alr_date',
114      'alr_results', 'notice',
115      'nysc_year',
116      'nysc_location',
117      'nysc_lga',
118      'employer',
119      'emp_position',
120      'emp_start',
121      'emp_end',
122      'emp_reason',
123      'employer2',
124      'emp2_position',
125      'emp2_start',
126      'emp2_end',
127      'emp2_reason',
128      'former_matric',
129      )
130PG_OMIT_MANAGE_FIELDS = (
131    'special_application','jamb_subjects_list',) + PG_OMIT_FIELDS
132PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
133    'student_id',
134    'notice',
135    )
136
137PTEE_OMIT_FIELDS = (
138    'programme_type',
139    'jamb_age',
140    'jamb_subjects',
141    'jamb_score',
142    'jamb_reg_number',
143    'aggregate'
144    )
145PTEE_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
146    'jamb_subjects_list',) + PTEE_OMIT_FIELDS
147PTEE_OMIT_PDF_FIELDS = PTEE_OMIT_DISPLAY_FIELDS + PTEE_OMIT_FIELDS + (
148      'reg_number','alr_fname', 'alr_no', 'alr_date',
149      'alr_results', 'notice',
150      'nysc_year',
151      'nysc_location',
152      'nysc_lga',
153      'employer',
154      'emp_position',
155      'emp_start',
156      'emp_end',
157      'emp_reason',
158      'employer2',
159      'emp2_position',
160      'emp2_start',
161      'emp2_end',
162      'emp2_reason',
163      'former_matric',
164    )
165PTEE_OMIT_MANAGE_FIELDS = (
166    'special_application','jamb_subjects_list',) + PTEE_OMIT_FIELDS
167PTEE_OMIT_EDIT_FIELDS = PTEE_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
168    'student_id',
169    'notice',
170    )
171
172class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
173    """A display view for applicant data.
174    """
175
176    @property
177    def form_fields(self):
178        if self.target is not None and self.target == 'trans':
179            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
180                'locked', 'suspended')
181            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
182            form_fields['perm_address'].custom_widget = BytesDisplayWidget
183            return form_fields
184        # AAUE is using the same interface for all regular applications.
185        form_fields = grok.AutoFields(ICustomUGApplicant)
186        if self.target is not None and self.target.startswith('pg'):
187            for field in PG_OMIT_DISPLAY_FIELDS:
188                form_fields = form_fields.omit(field)
189        elif self.target is not None and self.target.startswith('ptee'):
190            for field in PTEE_OMIT_DISPLAY_FIELDS:
191                form_fields = form_fields.omit(field)
192        else:
193            for field in UG_OMIT_DISPLAY_FIELDS:
194                form_fields = form_fields.omit(field)
195        form_fields['perm_address'].custom_widget = BytesDisplayWidget
196        form_fields['notice'].custom_widget = BytesDisplayWidget
197        if not getattr(self.context, 'student_id'):
198            form_fields = form_fields.omit('student_id')
199        if not getattr(self.context, 'screening_score'):
200            form_fields = form_fields.omit('screening_score')
201        if not getattr(self.context, 'screening_venue'):
202            form_fields = form_fields.omit('screening_venue')
203        if not getattr(self.context, 'screening_date'):
204            form_fields = form_fields.omit('screening_date')
205        return form_fields
206
207class CustomPDFActionButton(PDFActionButton):
208
209    @property
210    def target_url(self):
211        if self.context.state in ('initialized', 'started', 'paid') \
212            or self.context.special or self.view.target == 'trans':
213            return
214        return self.view.url(self.view.context, self.target)
215
216
217class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
218
219    column_two_fields = ('applicant_id', 'reg_number',
220        'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth')
221    #two_columns_design_fields = [
222    #    'fst_sit_fname', 'fst_sit_no', 'fst_sit_date',
223    #    'fst_sit_type', 'fst_sit_results',
224    #    'scd_sit_fname', 'scd_sit_no', 'scd_sit_date',
225    #    'scd_sit_type', 'scd_sit_results']
226
227    @property
228    def note(self):
229        if self.context.sex == 'm':
230            pronoun = 'he'
231        else:
232            pronoun = 'she'
233        return '''
234The applicant has acknowledged that, if discovered at any time that %s does not possess
235any of the qualifications which %s claims %s has obtained, %s will be expelled from the
236University not be re-admitted for the same or any other programme, even if %s has
237upgraded previous and shall qualifications or possess additional qualifications.
238''' % (
239    pronoun, pronoun, pronoun, pronoun, pronoun)
240
241    @property
242    def form_fields(self):
243        # AAUE is using the same interface for all regular applications.
244        form_fields = grok.AutoFields(ICustomUGApplicant)
245        if self.target is not None and self.target.startswith('pg'):
246            for field in PG_OMIT_PDF_FIELDS:
247                form_fields = form_fields.omit(field)
248        elif self.target is not None and self.target.startswith('ptee'):
249            for field in PTEE_OMIT_PDF_FIELDS:
250                form_fields = form_fields.omit(field)
251        else:
252            for field in UG_OMIT_PDF_FIELDS:
253                form_fields = form_fields.omit(field)
254        if not getattr(self.context, 'student_id'):
255            form_fields = form_fields.omit('student_id')
256        if not getattr(self.context, 'screening_score'):
257            form_fields = form_fields.omit('screening_score')
258        if not getattr(self.context, 'screening_venue'):
259            form_fields = form_fields.omit('screening_venue')
260        if not getattr(self.context, 'screening_date'):
261            form_fields = form_fields.omit('screening_date')
262        return form_fields
263
264class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
265    """A full edit view for applicant data.
266    """
267
268    @property
269    def form_fields(self):
270        if self.target is not None and self.target == 'trans':
271            form_fields = grok.AutoFields(ITranscriptApplicant)
272            form_fields['applicant_id'].for_display = True
273            return form_fields
274        # AAUE is using the same interface for all regular applications.
275        form_fields = grok.AutoFields(ICustomUGApplicant)
276        if self.target is not None and self.target.startswith('pg'):
277            for field in PG_OMIT_MANAGE_FIELDS:
278                form_fields = form_fields.omit(field)
279        elif self.target is not None and self.target.startswith('ptee'):
280            for field in PTEE_OMIT_MANAGE_FIELDS:
281                form_fields = form_fields.omit(field)
282        else:
283            for field in UG_OMIT_MANAGE_FIELDS:
284                form_fields = form_fields.omit(field)
285        form_fields['student_id'].for_display = True
286        form_fields['applicant_id'].for_display = True
287        return form_fields
288
289class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
290    """An applicant-centered edit view for applicant data.
291    """
292
293    grok.template('applicanteditpage')
294
295    @property
296    def form_fields(self):
297        if self.target is not None and self.target == 'trans':
298            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
299                'locked', 'suspended')
300            form_fields['applicant_id'].for_display = True
301            return form_fields
302        # AAUE is using the same interface for all regular applications.
303        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
304        if self.target is not None and self.target.startswith('pg'):
305            for field in PG_OMIT_EDIT_FIELDS:
306                form_fields = form_fields.omit(field)
307        elif self.target is not None and self.target.startswith('ptee'):
308            for field in PTEE_OMIT_EDIT_FIELDS:
309                form_fields = form_fields.omit(field)
310        else:
311            for field in UG_OMIT_EDIT_FIELDS:
312                form_fields = form_fields.omit(field)
313        form_fields['applicant_id'].for_display = True
314        form_fields['reg_number'].for_display = True
315        return form_fields
316
317class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage):
318    """Captcha'd registration page for applicants.
319    """
320
321    def _redirect(self, email, password, applicant_id):
322        # Forward email and credentials to landing page.
323        self.redirect(self.url(self.context, 'registration_complete',
324            data = dict(email=email, password=password,
325            applicant_id=applicant_id)))
326        return
327
328class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
329
330    @property
331    def payment_slip_download_warning(self):
332        return ''
333
334class CustomApplicantCheckStatusPage(ApplicantCheckStatusPage):
335    """Captcha'd status checking page for applicants.
336    """
337    grok.template('applicantcheckstatus')
Note: See TracBrowser for help on using the repository browser.