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

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

Changes requested in ticket #232 (fire brigade approach).

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