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

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

Start customization of application forms.

  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1## $Id: browser.py 10298 2013-06-16 08:39:43Z 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
48
49class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
50    """A display view for applicant data.
51    """
52
53    @property
54    def form_fields(self):
55        if self.target is not None and self.target.startswith('pg'):
56            form_fields = grok.AutoFields(ICustomPGApplicant)
57            for field in PG_OMIT_DISPLAY_FIELDS:
58                form_fields = form_fields.omit(field)
59        else:
60            form_fields = grok.AutoFields(ICustomUGApplicant)
61            for field in UG_OMIT_DISPLAY_FIELDS:
62                form_fields = form_fields.omit(field)
63        form_fields['perm_address'].custom_widget = BytesDisplayWidget
64        form_fields['notice'].custom_widget = BytesDisplayWidget
65        if not getattr(self.context, 'student_id'):
66            form_fields = form_fields.omit('student_id')
67        if not getattr(self.context, 'screening_score'):
68            form_fields = form_fields.omit('screening_score')
69        if not getattr(self.context, 'screening_venue'):
70            form_fields = form_fields.omit('screening_venue')
71        if not getattr(self.context, 'screening_date'):
72            form_fields = form_fields.omit('screening_date')
73        return form_fields
74
75class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
76
77    note = '''
78
79The applicant has acknowledged that, if discovered at any time that she/he
80does not possess any of the qualifications which she/he claims she/he has obtained,
81she/he will be expelled from the University and shall not be re-admitted for the same
82or any other programme, even if she/he has upgraded her/his previous qualifications
83or possess additional qualifications.'''
84
85    @property
86    def form_fields(self):
87        if self.target is not None and self.target.startswith('pg'):
88            form_fields = grok.AutoFields(ICustomPGApplicant)
89            for field in PG_OMIT_PDF_FIELDS:
90                form_fields = form_fields.omit(field)
91        else:
92            form_fields = grok.AutoFields(ICustomUGApplicant)
93            for field in UG_OMIT_PDF_FIELDS:
94                form_fields = form_fields.omit(field)
95        if not getattr(self.context, 'student_id'):
96            form_fields = form_fields.omit('student_id')
97        if not getattr(self.context, 'screening_score'):
98            form_fields = form_fields.omit('screening_score')
99        if not getattr(self.context, 'screening_venue'):
100            form_fields = form_fields.omit('screening_venue')
101        if not getattr(self.context, 'screening_date'):
102            form_fields = form_fields.omit('screening_date')
103        return form_fields
104
105class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
106    """A full edit view for applicant data.
107    """
108
109    @property
110    def form_fields(self):
111        if self.target is not None and self.target.startswith('pg'):
112            form_fields = grok.AutoFields(ICustomPGApplicant)
113            for field in PG_OMIT_MANAGE_FIELDS:
114                form_fields = form_fields.omit(field)
115        else:
116            form_fields = grok.AutoFields(ICustomUGApplicant)
117            for field in UG_OMIT_MANAGE_FIELDS:
118                form_fields = form_fields.omit(field)
119        form_fields['student_id'].for_display = True
120        form_fields['applicant_id'].for_display = True
121        return form_fields
122
123class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
124    """An applicant-centered 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(ICustomPGApplicantEdit)
131            for field in PG_OMIT_EDIT_FIELDS:
132                form_fields = form_fields.omit(field)
133        else:
134            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
135            for field in UG_OMIT_EDIT_FIELDS:
136                form_fields = form_fields.omit(field)
137        form_fields['applicant_id'].for_display = True
138        form_fields['reg_number'].for_display = True
139        return form_fields
Note: See TracBrowser for help on using the repository browser.