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

Last change on this file since 10897 was 10897, checked in by Henrik Bettermann, 11 years ago

Adjust line breaks.

  • Property svn:keywords set to Id
File size: 6.3 KB
Line 
1## $Id: browser.py 10897 2014-01-12 21:53:22Z 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    UG_OMIT_DISPLAY_FIELDS,
34    UG_OMIT_PDF_FIELDS,
35    UG_OMIT_MANAGE_FIELDS,
36    UG_OMIT_EDIT_FIELDS,
37    PG_OMIT_DISPLAY_FIELDS,
38    PG_OMIT_PDF_FIELDS,
39    PG_OMIT_MANAGE_FIELDS,
40    PG_OMIT_EDIT_FIELDS)
41from waeup.aaue.applicants.interfaces import (
42    ICustomApplicant,
43    ICustomUGApplicant,
44    ICustomPGApplicant,
45    ICustomPGApplicantEdit,
46    ICustomUGApplicantEdit)
47
48UG_OMIT_PDF_FIELDS = [
49    element for element in UG_OMIT_PDF_FIELDS if not element == 'phone']
50UG_OMIT_PDF_FIELDS += ('reg_number','alr_fname', 'alr_no', 'alr_date',
51    'alr_results', 'notice')
52
53class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
54    """A display view for applicant data.
55    """
56
57    @property
58    def form_fields(self):
59        if self.target is not None and self.target.startswith('pg'):
60            form_fields = grok.AutoFields(ICustomPGApplicant)
61            for field in PG_OMIT_DISPLAY_FIELDS:
62                form_fields = form_fields.omit(field)
63        else:
64            form_fields = grok.AutoFields(ICustomUGApplicant)
65            for field in UG_OMIT_DISPLAY_FIELDS:
66                form_fields = form_fields.omit(field)
67        form_fields['perm_address'].custom_widget = BytesDisplayWidget
68        form_fields['notice'].custom_widget = BytesDisplayWidget
69        if not getattr(self.context, 'student_id'):
70            form_fields = form_fields.omit('student_id')
71        if not getattr(self.context, 'screening_score'):
72            form_fields = form_fields.omit('screening_score')
73        if not getattr(self.context, 'screening_venue'):
74            form_fields = form_fields.omit('screening_venue')
75        if not getattr(self.context, 'screening_date'):
76            form_fields = form_fields.omit('screening_date')
77        return form_fields
78
79class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
80
81    column_two_fields = ('applicant_id', 'reg_number',
82        'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth')
83    two_columns_design_fields = [
84        'fst_sit_fname', 'fst_sit_no', 'fst_sit_date',
85        'fst_sit_type', 'fst_sit_results',
86        'scd_sit_fname', 'scd_sit_no', 'scd_sit_date',
87        'scd_sit_type', 'scd_sit_results']
88
89    @property
90    def note(self):
91        if self.context.sex == 'm':
92            pronoun = 'he'
93        else:
94            pronoun = 'she'
95        return '''
96The applicant has acknowledged that, if discovered at any time that %s does not possess
97any of the qualifications which %s claims %s has obtained, %s will be expelled from the
98University not be re-admitted for the same or any other programme, even if %s has
99upgraded previous and shall qualifications or possess additional qualifications.
100''' % (
101    pronoun, pronoun, pronoun, pronoun, pronoun)
102
103    @property
104    def form_fields(self):
105        if self.target is not None and self.target.startswith('pg'):
106            form_fields = grok.AutoFields(ICustomPGApplicant)
107            for field in PG_OMIT_PDF_FIELDS:
108                form_fields = form_fields.omit(field)
109        else:
110            form_fields = grok.AutoFields(ICustomUGApplicant)
111            for field in UG_OMIT_PDF_FIELDS:
112                form_fields = form_fields.omit(field)
113        if not getattr(self.context, 'student_id'):
114            form_fields = form_fields.omit('student_id')
115        if not getattr(self.context, 'screening_score'):
116            form_fields = form_fields.omit('screening_score')
117        if not getattr(self.context, 'screening_venue'):
118            form_fields = form_fields.omit('screening_venue')
119        if not getattr(self.context, 'screening_date'):
120            form_fields = form_fields.omit('screening_date')
121        return form_fields
122
123class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
124    """A full edit view for applicant data.
125    """
126
127    @property
128    def form_fields(self):
129        if self.target is not None and self.target.startswith('pg'):
130            form_fields = grok.AutoFields(ICustomPGApplicant)
131            for field in PG_OMIT_MANAGE_FIELDS:
132                form_fields = form_fields.omit(field)
133        else:
134            form_fields = grok.AutoFields(ICustomUGApplicant)
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):
147        if self.target is not None and self.target.startswith('pg'):
148            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
149            for field in PG_OMIT_EDIT_FIELDS:
150                form_fields = form_fields.omit(field)
151        else:
152            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
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
Note: See TracBrowser for help on using the repository browser.