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

Last change on this file since 11932 was 11755, checked in by Henrik Bettermann, 10 years ago

Customize payment_slip_download_warning. Application payment tickets can be downloaded without submitting the form.

  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
1## $Id: browser.py 11755 2014-07-09 05:43:16Z 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.aaue.interfaces import MessageFactory as _
28from kofacustom.nigeria.applicants.browser import (
29    NigeriaApplicantDisplayFormPage,
30    NigeriaApplicantManageFormPage,
31    NigeriaApplicantEditFormPage,
32    NigeriaPDFApplicationSlip,
33    NigeriaApplicantRegistrationPage,
34    NigeriaExportPDFPaymentSlipPage,
35    UG_OMIT_DISPLAY_FIELDS,
36    UG_OMIT_PDF_FIELDS,
37    UG_OMIT_MANAGE_FIELDS,
38    UG_OMIT_EDIT_FIELDS)
39from waeup.aaue.applicants.interfaces import (
40    ICustomApplicant,
41    ICustomUGApplicant,
42    ICustomUGApplicantEdit
43    )
44
45UG_OMIT_PDF_FIELDS = tuple([
46    element for element in UG_OMIT_PDF_FIELDS if not element == 'phone'])
47UG_OMIT_PDF_FIELDS += ('reg_number','alr_fname', 'alr_no', 'alr_date',
48    'alr_results', 'notice')
49
50FP_OMIT_FIELDS = ('hq_type', 'hq_fname', 'hq_matric_no',
51     'hq_degree', 'hq_school', 'hq_session', 'hq_disc')
52FP_OMIT_DISPLAY_FIELDS = UG_OMIT_DISPLAY_FIELDS + FP_OMIT_FIELDS
53FP_OMIT_PDF_FIELDS = UG_OMIT_PDF_FIELDS + FP_OMIT_FIELDS
54FP_OMIT_MANAGE_FIELDS = UG_OMIT_MANAGE_FIELDS + FP_OMIT_FIELDS
55FP_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + FP_OMIT_FIELDS
56
57class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
58    """A display view for applicant data.
59    """
60
61    @property
62    def form_fields(self):
63        form_fields = grok.AutoFields(ICustomUGApplicant)
64        if self.target is not None and self.target.startswith('fp'):
65            for field in FP_OMIT_DISPLAY_FIELDS:
66                form_fields = form_fields.omit(field)
67        else:
68            for field in UG_OMIT_DISPLAY_FIELDS:
69                form_fields = form_fields.omit(field)
70        form_fields['perm_address'].custom_widget = BytesDisplayWidget
71        form_fields['notice'].custom_widget = BytesDisplayWidget
72        if not getattr(self.context, 'student_id'):
73            form_fields = form_fields.omit('student_id')
74        if not getattr(self.context, 'screening_score'):
75            form_fields = form_fields.omit('screening_score')
76        if not getattr(self.context, 'screening_venue'):
77            form_fields = form_fields.omit('screening_venue')
78        if not getattr(self.context, 'screening_date'):
79            form_fields = form_fields.omit('screening_date')
80        return form_fields
81
82class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
83
84    column_two_fields = ('applicant_id', 'reg_number',
85        'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth')
86    two_columns_design_fields = [
87        'fst_sit_fname', 'fst_sit_no', 'fst_sit_date',
88        'fst_sit_type', 'fst_sit_results',
89        'scd_sit_fname', 'scd_sit_no', 'scd_sit_date',
90        'scd_sit_type', 'scd_sit_results']
91
92    @property
93    def note(self):
94        if self.context.sex == 'm':
95            pronoun = 'he'
96        else:
97            pronoun = 'she'
98        return '''
99The applicant has acknowledged that, if discovered at any time that %s does not possess
100any of the qualifications which %s claims %s has obtained, %s will be expelled from the
101University not be re-admitted for the same or any other programme, even if %s has
102upgraded previous and shall qualifications or possess additional qualifications.
103''' % (
104    pronoun, pronoun, pronoun, pronoun, pronoun)
105
106    @property
107    def form_fields(self):
108        form_fields = grok.AutoFields(ICustomUGApplicant)
109        if self.target is not None and self.target.startswith('fp'):
110            for field in FP_OMIT_PDF_FIELDS:
111                form_fields = form_fields.omit(field)
112        else:
113            for field in UG_OMIT_PDF_FIELDS:
114                form_fields = form_fields.omit(field)
115        if not getattr(self.context, 'student_id'):
116            form_fields = form_fields.omit('student_id')
117        if not getattr(self.context, 'screening_score'):
118            form_fields = form_fields.omit('screening_score')
119        if not getattr(self.context, 'screening_venue'):
120            form_fields = form_fields.omit('screening_venue')
121        if not getattr(self.context, 'screening_date'):
122            form_fields = form_fields.omit('screening_date')
123        return form_fields
124
125class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
126    """A full edit view for applicant data.
127    """
128
129    @property
130    def form_fields(self):
131        form_fields = grok.AutoFields(ICustomUGApplicant)
132        if self.target is not None and self.target.startswith('fp'):
133            for field in FP_OMIT_MANAGE_FIELDS:
134                form_fields = form_fields.omit(field)
135        else:
136            for field in UG_OMIT_MANAGE_FIELDS:
137                form_fields = form_fields.omit(field)
138        form_fields['student_id'].for_display = True
139        form_fields['applicant_id'].for_display = True
140        return form_fields
141
142class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
143    """An applicant-centered edit view for applicant data.
144    """
145
146    @property
147    def form_fields(self):
148        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
149        if self.target is not None and self.target.startswith('fp'):
150            for field in FP_OMIT_EDIT_FIELDS:
151                form_fields = form_fields.omit(field)
152        else:
153            for field in UG_OMIT_EDIT_FIELDS:
154                form_fields = form_fields.omit(field)
155        form_fields['applicant_id'].for_display = True
156        form_fields['reg_number'].for_display = True
157        return form_fields
158
159class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage):
160    """Captcha'd registration page for applicants.
161    """
162
163    def _redirect(self, email, password, applicant_id):
164        # Forward email and credentials to landing page.
165        self.redirect(self.url(self.context, 'registration_complete',
166            data = dict(email=email, password=password,
167            applicant_id=applicant_id)))
168        return
169
170class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
171
172    @property
173    def payment_slip_download_warning(self):
174        return ''
Note: See TracBrowser for help on using the repository browser.