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

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

Confirmation check box must be available in template.

  • Property svn:keywords set to Id
File size: 10.8 KB
Line 
1## $Id: browser.py 13547 2015-12-17 06:12:49Z 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      )
53UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
54    'jamb_subjects_list',) + UG_OMIT_FIELDS
55UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + UG_OMIT_FIELDS + (
56      'reg_number','alr_fname', 'alr_no', 'alr_date',
57      'alr_results', 'notice')
58UG_OMIT_MANAGE_FIELDS = (
59    'special_application','jamb_subjects_list',) + UG_OMIT_FIELDS
60UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
61    'student_id',
62    'notice',
63    'jamb_age',
64    'jamb_subjects',
65    'jamb_score',
66    'jamb_reg_number',
67    'aggregate')
68
69#UG_OMIT_PDF_FIELDS = tuple([
70#    element for element in UG_OMIT_PDF_FIELDS if not element == 'phone'])
71
72#UG_OMIT_PDF_FIELDS += (
73#      'reg_number','alr_fname', 'alr_no', 'alr_date',
74#      'alr_results', 'notice'
75#      )
76
77FP_OMIT_DISPLAY_FIELDS = UG_OMIT_DISPLAY_FIELDS + UG_OMIT_FIELDS
78FP_OMIT_PDF_FIELDS = UG_OMIT_PDF_FIELDS + UG_OMIT_FIELDS
79FP_OMIT_MANAGE_FIELDS = UG_OMIT_MANAGE_FIELDS + UG_OMIT_FIELDS
80FP_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + UG_OMIT_FIELDS
81
82PG_OMIT_FIELDS = (
83    'fst_sit_fname',
84    'fst_sit_no',
85    'fst_sit_date',
86    'fst_sit_type',
87    'fst_sit_results',
88    'scd_sit_fname',
89    'scd_sit_no',
90    'scd_sit_date',
91    'scd_sit_type',
92    'scd_sit_results',
93    'programme_type',
94    'jamb_age',
95    'jamb_subjects',
96    'jamb_score',
97    'jamb_reg_number',
98    'aggregate'
99    )
100PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
101    'jamb_subjects_list',) + PG_OMIT_FIELDS
102PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + PG_OMIT_FIELDS + (
103      'reg_number','alr_fname', 'alr_no', 'alr_date',
104      'alr_results', 'notice')
105PG_OMIT_MANAGE_FIELDS = (
106    'special_application','jamb_subjects_list',) + PG_OMIT_FIELDS
107PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
108    'student_id',
109    'notice',
110    )
111
112class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
113    """A display view for applicant data.
114    """
115
116    @property
117    def form_fields(self):
118        if self.target is not None and self.target == 'trans':
119            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
120                'locked', 'suspended')
121            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
122            form_fields['perm_address'].custom_widget = BytesDisplayWidget
123            return form_fields
124        # AAUE is using the same interface for all regular applications.
125        form_fields = grok.AutoFields(ICustomUGApplicant)
126        if self.target is not None and self.target.startswith('pg'):
127            for field in PG_OMIT_DISPLAY_FIELDS:
128                form_fields = form_fields.omit(field)
129        elif self.target is not None and self.target.startswith('fp'):
130            for field in FP_OMIT_DISPLAY_FIELDS:
131                form_fields = form_fields.omit(field)
132        else:
133            for field in UG_OMIT_DISPLAY_FIELDS:
134                form_fields = form_fields.omit(field)
135        form_fields['perm_address'].custom_widget = BytesDisplayWidget
136        form_fields['notice'].custom_widget = BytesDisplayWidget
137        if not getattr(self.context, 'student_id'):
138            form_fields = form_fields.omit('student_id')
139        if not getattr(self.context, 'screening_score'):
140            form_fields = form_fields.omit('screening_score')
141        if not getattr(self.context, 'screening_venue'):
142            form_fields = form_fields.omit('screening_venue')
143        if not getattr(self.context, 'screening_date'):
144            form_fields = form_fields.omit('screening_date')
145        return form_fields
146
147class CustomPDFActionButton(PDFActionButton):
148
149    @property
150    def target_url(self):
151        if self.context.state in ('initialized', 'started', 'paid') \
152            or self.context.special or self.view.target == 'trans':
153            return
154        return self.view.url(self.view.context, self.target)
155
156
157class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
158
159    column_two_fields = ('applicant_id', 'reg_number',
160        'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth')
161    two_columns_design_fields = [
162        'fst_sit_fname', 'fst_sit_no', 'fst_sit_date',
163        'fst_sit_type', 'fst_sit_results',
164        'scd_sit_fname', 'scd_sit_no', 'scd_sit_date',
165        'scd_sit_type', 'scd_sit_results']
166
167    @property
168    def note(self):
169        if self.context.sex == 'm':
170            pronoun = 'he'
171        else:
172            pronoun = 'she'
173        return '''
174The applicant has acknowledged that, if discovered at any time that %s does not possess
175any of the qualifications which %s claims %s has obtained, %s will be expelled from the
176University not be re-admitted for the same or any other programme, even if %s has
177upgraded previous and shall qualifications or possess additional qualifications.
178''' % (
179    pronoun, pronoun, pronoun, pronoun, pronoun)
180
181    @property
182    def form_fields(self):
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_PDF_FIELDS:
187                form_fields = form_fields.omit(field)
188        elif self.target is not None and self.target.startswith('fp'):
189            for field in FP_OMIT_PDF_FIELDS:
190                form_fields = form_fields.omit(field)
191        else:
192            for field in UG_OMIT_PDF_FIELDS:
193                form_fields = form_fields.omit(field)
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 CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
205    """A full edit view for applicant data.
206    """
207
208    @property
209    def form_fields(self):
210        if self.target is not None and self.target == 'trans':
211            form_fields = grok.AutoFields(ITranscriptApplicant)
212            form_fields['applicant_id'].for_display = True
213            return form_fields
214        # AAUE is using the same interface for all regular applications.
215        form_fields = grok.AutoFields(ICustomUGApplicant)
216        if self.target is not None and self.target.startswith('pg'):
217            for field in PG_OMIT_MANAGE_FIELDS:
218                form_fields = form_fields.omit(field)
219        elif self.target is not None and self.target.startswith('fp'):
220            for field in FP_OMIT_MANAGE_FIELDS:
221                form_fields = form_fields.omit(field)
222        else:
223            for field in UG_OMIT_MANAGE_FIELDS:
224                form_fields = form_fields.omit(field)
225        form_fields['student_id'].for_display = True
226        form_fields['applicant_id'].for_display = True
227        return form_fields
228
229class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
230    """An applicant-centered edit view for applicant data.
231    """
232
233    grok.template('applicanteditpage')
234
235    @property
236    def form_fields(self):
237        if self.target is not None and self.target == 'trans':
238            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
239                'locked', 'suspended')
240            form_fields['applicant_id'].for_display = True
241            return form_fields
242        # AAUE is using the same interface for all regular applications.
243        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
244        if self.target is not None and self.target.startswith('pg'):
245            for field in PG_OMIT_EDIT_FIELDS:
246                form_fields = form_fields.omit(field)
247        elif self.target is not None and self.target.startswith('fp'):
248            for field in FP_OMIT_EDIT_FIELDS:
249                form_fields = form_fields.omit(field)
250        else:
251            for field in UG_OMIT_EDIT_FIELDS:
252                form_fields = form_fields.omit(field)
253        form_fields['applicant_id'].for_display = True
254        form_fields['reg_number'].for_display = True
255        return form_fields
256
257class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage):
258    """Captcha'd registration page for applicants.
259    """
260
261    def _redirect(self, email, password, applicant_id):
262        # Forward email and credentials to landing page.
263        self.redirect(self.url(self.context, 'registration_complete',
264            data = dict(email=email, password=password,
265            applicant_id=applicant_id)))
266        return
267
268class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
269
270    @property
271    def payment_slip_download_warning(self):
272        return ''
273
274class CustomApplicantCheckStatusPage(ApplicantCheckStatusPage):
275    """Captcha'd status checking page for applicants.
276    """
277    grok.template('applicantcheckstatus')
Note: See TracBrowser for help on using the repository browser.