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

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

Add programme_type to PTEE application forms.

  • Property svn:keywords set to Id
File size: 12.0 KB
Line 
1## $Id: browser.py 13722 2016-02-22 16:31:43Z 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    'jamb_age',
139    'jamb_subjects',
140    'jamb_score',
141    'jamb_reg_number',
142    'aggregate'
143    )
144PTEE_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
145    'jamb_subjects_list',) + PTEE_OMIT_FIELDS
146PTEE_OMIT_PDF_FIELDS = PTEE_OMIT_DISPLAY_FIELDS + PTEE_OMIT_FIELDS + (
147      'reg_number','alr_fname', 'alr_no', 'alr_date',
148      'alr_results', 'notice',
149      'nysc_year',
150      'nysc_location',
151      'nysc_lga',
152      'employer',
153      'emp_position',
154      'emp_start',
155      'emp_end',
156      'emp_reason',
157      'employer2',
158      'emp2_position',
159      'emp2_start',
160      'emp2_end',
161      'emp2_reason',
162      'former_matric',
163    )
164PTEE_OMIT_MANAGE_FIELDS = (
165    'special_application','jamb_subjects_list',) + PTEE_OMIT_FIELDS
166PTEE_OMIT_EDIT_FIELDS = PTEE_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
167    'student_id',
168    'notice',
169    )
170
171class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
172    """A display view for applicant data.
173    """
174
175    @property
176    def form_fields(self):
177        if self.target is not None and self.target == 'trans':
178            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
179                'locked', 'suspended')
180            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
181            form_fields['perm_address'].custom_widget = BytesDisplayWidget
182            return form_fields
183        # AAUE is using the same interface for all regular applications.
184        form_fields = grok.AutoFields(ICustomUGApplicant)
185        if self.target is not None and self.target.startswith('pg'):
186            for field in PG_OMIT_DISPLAY_FIELDS:
187                form_fields = form_fields.omit(field)
188        elif self.target is not None and self.target.startswith('ptee'):
189            for field in PTEE_OMIT_DISPLAY_FIELDS:
190                form_fields = form_fields.omit(field)
191        else:
192            for field in UG_OMIT_DISPLAY_FIELDS:
193                form_fields = form_fields.omit(field)
194        form_fields['perm_address'].custom_widget = BytesDisplayWidget
195        form_fields['notice'].custom_widget = BytesDisplayWidget
196        if not getattr(self.context, 'student_id'):
197            form_fields = form_fields.omit('student_id')
198        if not getattr(self.context, 'screening_score'):
199            form_fields = form_fields.omit('screening_score')
200        if not getattr(self.context, 'screening_venue'):
201            form_fields = form_fields.omit('screening_venue')
202        if not getattr(self.context, 'screening_date'):
203            form_fields = form_fields.omit('screening_date')
204        return form_fields
205
206class CustomPDFActionButton(PDFActionButton):
207
208    @property
209    def target_url(self):
210        if self.context.state in ('initialized', 'started', 'paid') \
211            or self.context.special or self.view.target == 'trans':
212            return
213        return self.view.url(self.view.context, self.target)
214
215
216class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
217
218    column_two_fields = ('applicant_id', 'reg_number',
219        'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth')
220    #two_columns_design_fields = [
221    #    'fst_sit_fname', 'fst_sit_no', 'fst_sit_date',
222    #    'fst_sit_type', 'fst_sit_results',
223    #    'scd_sit_fname', 'scd_sit_no', 'scd_sit_date',
224    #    'scd_sit_type', 'scd_sit_results']
225
226    @property
227    def note(self):
228        if self.context.sex == 'm':
229            pronoun = 'he'
230        else:
231            pronoun = 'she'
232        return '''
233The applicant has acknowledged that, if discovered at any time that %s does not possess
234any of the qualifications which %s claims %s has obtained, %s will be expelled from the
235University not be re-admitted for the same or any other programme, even if %s has
236upgraded previous and shall qualifications or possess additional qualifications.
237''' % (
238    pronoun, pronoun, pronoun, pronoun, pronoun)
239
240    @property
241    def form_fields(self):
242        # AAUE is using the same interface for all regular applications.
243        form_fields = grok.AutoFields(ICustomUGApplicant)
244        if self.target is not None and self.target.startswith('pg'):
245            for field in PG_OMIT_PDF_FIELDS:
246                form_fields = form_fields.omit(field)
247        elif self.target is not None and self.target.startswith('ptee'):
248            for field in PTEE_OMIT_PDF_FIELDS:
249                form_fields = form_fields.omit(field)
250        else:
251            for field in UG_OMIT_PDF_FIELDS:
252                form_fields = form_fields.omit(field)
253        if not getattr(self.context, 'student_id'):
254            form_fields = form_fields.omit('student_id')
255        if not getattr(self.context, 'screening_score'):
256            form_fields = form_fields.omit('screening_score')
257        if not getattr(self.context, 'screening_venue'):
258            form_fields = form_fields.omit('screening_venue')
259        if not getattr(self.context, 'screening_date'):
260            form_fields = form_fields.omit('screening_date')
261        return form_fields
262
263class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
264    """A full edit view for applicant data.
265    """
266
267    @property
268    def form_fields(self):
269        if self.target is not None and self.target == 'trans':
270            form_fields = grok.AutoFields(ITranscriptApplicant)
271            form_fields['applicant_id'].for_display = True
272            return form_fields
273        # AAUE is using the same interface for all regular applications.
274        form_fields = grok.AutoFields(ICustomUGApplicant)
275        if self.target is not None and self.target.startswith('pg'):
276            for field in PG_OMIT_MANAGE_FIELDS:
277                form_fields = form_fields.omit(field)
278        elif self.target is not None and self.target.startswith('ptee'):
279            for field in PTEE_OMIT_MANAGE_FIELDS:
280                form_fields = form_fields.omit(field)
281        else:
282            for field in UG_OMIT_MANAGE_FIELDS:
283                form_fields = form_fields.omit(field)
284        form_fields['student_id'].for_display = True
285        form_fields['applicant_id'].for_display = True
286        return form_fields
287
288class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
289    """An applicant-centered edit view for applicant data.
290    """
291
292    grok.template('applicanteditpage')
293
294    @property
295    def form_fields(self):
296        if self.target is not None and self.target == 'trans':
297            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
298                'locked', 'suspended')
299            form_fields['applicant_id'].for_display = True
300            return form_fields
301        # AAUE is using the same interface for all regular applications.
302        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
303        if self.target is not None and self.target.startswith('pg'):
304            for field in PG_OMIT_EDIT_FIELDS:
305                form_fields = form_fields.omit(field)
306        elif self.target is not None and self.target.startswith('ptee'):
307            for field in PTEE_OMIT_EDIT_FIELDS:
308                form_fields = form_fields.omit(field)
309        else:
310            for field in UG_OMIT_EDIT_FIELDS:
311                form_fields = form_fields.omit(field)
312        form_fields['applicant_id'].for_display = True
313        form_fields['reg_number'].for_display = True
314        return form_fields
315
316class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage):
317    """Captcha'd registration page for applicants.
318    """
319
320    def _redirect(self, email, password, applicant_id):
321        # Forward email and credentials to landing page.
322        self.redirect(self.url(self.context, 'registration_complete',
323            data = dict(email=email, password=password,
324            applicant_id=applicant_id)))
325        return
326
327class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
328
329    @property
330    def payment_slip_download_warning(self):
331        return ''
332
333class CustomApplicantCheckStatusPage(ApplicantCheckStatusPage):
334    """Captcha'd status checking page for applicants.
335    """
336    grok.template('applicantcheckstatus')
Note: See TracBrowser for help on using the repository browser.