source: main/waeup.uniben/trunk/src/waeup/uniben/applicants/browser.py @ 8107

Last change on this file since 8107 was 8090, checked in by Henrik Bettermann, 13 years ago

Use customized PhoneWidget? in all application forms.

  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1## $Id: browser.py 8090 2012-04-10 09:17:02Z 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
21from waeup.kofa.widgets.datewidget import (
22    FriendlyDateWidget, FriendlyDateDisplayWidget,
23    FriendlyDatetimeDisplayWidget)
24from waeup.uniben.widgets.phonewidget import PhoneWidget
25from waeup.kofa.applicants.interfaces import (
26    IApplicantRegisterUpdate, IApplicant, IApplicantEdit)
27from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
28    OnlinePaymentCallbackPage, ExportPDFPage,
29    ApplicantManageFormPage, ApplicantEditFormPage,
30    ApplicantRegistrationPage, ApplicantAddFormPage)
31from waeup.kofa.applicants.viewlets import RequestCallbackActionButton
32from waeup.kofa.applicants.pdf import PDFApplicationSlip
33from waeup.uniben.applicants.interfaces import (
34    IPGApplicant, IUGApplicant, IPGApplicantEdit, IUGApplicantEdit)
35from waeup.uniben.interfaces import MessageFactory as _
36
37class RequestCallbackActionButton(RequestCallbackActionButton):
38    """ Do not display the base package callback button in custom pages.
39    """
40    @property
41    def target_url(self):
42        return ''
43
44class OnlinePaymentCallbackPage(OnlinePaymentCallbackPage):
45    """ Neutralize callback simulation view
46    """
47    def update(self):
48        return
49
50class PDFApplicationSlip(PDFApplicationSlip):
51
52    @property
53    def form_fields(self):
54        target = getattr(self.context.__parent__, 'prefix', None)
55        if target is not None and target.startswith('pg'):
56            form_fields = grok.AutoFields(IPGApplicant).omit(
57                'locked', 'course_admitted')
58        else:
59            form_fields = grok.AutoFields(IUGApplicant).omit(
60                'locked', 'course_admitted')
61        form_fields[
62            'date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le')
63        return form_fields
64
65class ApplicantAddFormPage(ApplicantAddFormPage):
66    """Add-form to add an applicant.
67    """
68    form_fields = grok.AutoFields(IApplicant).select(
69        'firstname', 'middlename', 'lastname',
70        'email', 'phone')
71    form_fields['phone'].custom_widget = PhoneWidget
72
73class ApplicantDisplayFormPage(ApplicantDisplayFormPage):
74    """A display view for applicant data.
75    """
76
77    @property
78    def form_fields(self):
79        target = getattr(self.context.__parent__, 'prefix', None)
80        if target is not None and target.startswith('pg'):
81            form_fields = grok.AutoFields(IPGApplicant).omit(
82                'locked', 'course_admitted', 'password')
83        else:
84            form_fields = grok.AutoFields(IUGApplicant).omit(
85                'locked', 'course_admitted', 'password')
86        form_fields[
87            'date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le')
88        return form_fields
89
90class ApplicantManageFormPage(ApplicantManageFormPage):
91    """A full edit view for applicant data.
92    """
93   
94    @property
95    def form_fields(self):
96        target = getattr(self.context.__parent__, 'prefix', None)
97        if target is not None and target.startswith('pg'):
98            form_fields = grok.AutoFields(IPGApplicant)
99            form_fields[
100                'emp_start'].custom_widget = FriendlyDateWidget('le-year')
101            form_fields[
102                'emp_end'].custom_widget = FriendlyDateWidget('le-year')
103            form_fields[
104                'emp2_start'].custom_widget = FriendlyDateWidget('le-year')
105            form_fields[
106                'emp2_end'].custom_widget = FriendlyDateWidget('le-year')
107        else:
108            form_fields = grok.AutoFields(IUGApplicant)
109        form_fields[
110            'date_of_birth'].custom_widget = FriendlyDateWidget('le-year')
111        form_fields['phone'].custom_widget = PhoneWidget
112        form_fields['student_id'].for_display = True
113        form_fields['applicant_id'].for_display = True
114        return form_fields
115
116class ApplicantEditFormPage(ApplicantEditFormPage):
117    """An applicant-centered edit view for applicant data.
118    """
119
120    @property
121    def form_fields(self):
122        target = getattr(self.context.__parent__, 'prefix', None)
123        if target is not None and target.startswith('pg'):
124            form_fields = grok.AutoFields(IPGApplicantEdit).omit(
125                'locked', 'course_admitted', 'student_id',
126                'screening_score', 'screening_venue'
127                )
128            form_fields[
129                'emp_start'].custom_widget = FriendlyDateWidget('le-year')
130            form_fields[
131                'emp_end'].custom_widget = FriendlyDateWidget('le-year')
132            form_fields[
133                'emp2_start'].custom_widget = FriendlyDateWidget('le-year')
134            form_fields[
135                'emp2_end'].custom_widget = FriendlyDateWidget('le-year')
136        else:
137            form_fields = grok.AutoFields(IUGApplicantEdit).omit(
138                'locked', 'course_admitted', 'student_id',
139                'screening_score'
140                )
141        form_fields[
142            'date_of_birth'].custom_widget = FriendlyDateWidget('le-year')
143        form_fields['phone'].custom_widget = PhoneWidget
144        form_fields['applicant_id'].for_display = True
145        form_fields['reg_number'].for_display = True
146        return form_fields
147
148class ApplicantRegistrationPage(ApplicantRegistrationPage):
149    """Captcha'd registration page for applicants.
150    """
151
152    @property
153    def form_fields(self):
154        form_fields = None
155        if self.context.mode == 'create':
156            form_fields = grok.AutoFields(IApplicantEdit).select(
157                'firstname', 'middlename', 'lastname', 'email', 'phone')
158            form_fields['phone'].custom_widget = PhoneWidget
159        elif self.context.mode == 'update':
160            form_fields = grok.AutoFields(IApplicantRegisterUpdate).select(
161                'firstname','reg_number','email')
162        return form_fields
Note: See TracBrowser for help on using the repository browser.