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

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

Include "Employment History" on Post-Graduate Print out form.

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