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

Last change on this file since 11684 was 11291, checked in by uli, 11 years ago

Merge changes from henrik-diazo-themed back into trunk.

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