source: main/waeup.sirp/trunk/src/waeup/sirp/jambtables/browser.py @ 5486

Last change on this file since 5486 was 5484, checked in by uli, 14 years ago

Let the PDE apply/edit page more look like the original.

File size: 7.1 KB
Line 
1##
2## browser.py
3## Login : <uli@pu.smp.net>
4## Started on  Sun Jun 27 11:03:10 2010 Uli Fouquet
5## $Id$
6##
7## Copyright (C) 2010 Uli Fouquet
8## This program is free software; you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation; either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21##
22"""UI components for JAMB tables.
23"""
24import grok
25
26from waeup.sirp.browser import (
27    WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage,
28    WAeUPDisplayFormPage, NullValidator)
29from waeup.sirp.browser.pages import LoginPage
30from waeup.sirp.interfaces import IWAeUPObject
31from waeup.sirp.jambtables import JAMBDataTable
32from waeup.sirp.jambtables.util import get_applicant_data
33from waeup.sirp.jambtables.interfaces import (
34    IApplicant, IApplicantContainer, IApplicantPrincipal, IApplicantPDEEditData)
35                                             
36
37#from zope.formlib.objectwidget import ObjectWidget
38from zope.formlib.sequencewidget import ListSequenceWidget, SequenceDisplayWidget
39from zope.formlib.widget import CustomWidgetFactory
40from waeup.sirp.jambtables.applicants import ResultEntry
41from waeup.sirp.widgets.objectwidget import (
42    WAeUPObjectWidget, WAeUPObjectDisplayWidget)
43from waeup.sirp.widgets.multilistwidget import (
44    MultiListWidget, MultiListDisplayWidget)
45
46results_widget = CustomWidgetFactory(
47    WAeUPObjectWidget, ResultEntry)
48
49results_display_widget = CustomWidgetFactory(
50    WAeUPObjectDisplayWidget, ResultEntry)
51
52#list_results_widget = CustomWidgetFactory(
53#    ListSequenceWidget, subwidget=results_widget)
54
55list_results_widget = CustomWidgetFactory(
56    MultiListWidget, subwidget=results_widget)
57
58list_results_display_widget = CustomWidgetFactory(
59    MultiListDisplayWidget, subwidget=results_display_widget)
60
61class ApplicationsPage(WAeUPPage):
62    grok.context(IApplicantContainer)
63    grok.name('index')
64    title = 'Applications'
65    pnav = 1
66   
67    def getApplications(self):
68        """Get a list of all stored applications.
69        """
70        for key, val in self.context.items():
71            url = self.url(val)
72            yield(dict(url=url, name=key))
73
74class AddApplicant(WAeUPAddFormPage):
75    grok.context(IApplicantContainer)
76    grok.name('add')
77    form_fields = grok.AutoFields(IApplicant)
78    form_fields['fst_sit_results'].custom_widget = list_results_widget
79    label = 'Add Applicant'
80    title = 'Add Applicant'
81    pnav = 1
82
83    @grok.action('Add applicant')
84    def addApplicant(self, **data):
85        from waeup.sirp.jambtables.applicants import Applicant
86        applicant = Applicant()
87        self.applyData(applicant, **data)
88        # XXX: temporarily disabled.
89        #self.context[applicant.reg_no] = applicant
90        try:
91            self.context[applicant.access_code] = applicant
92        except KeyError:
93            self.flash('The given access code is already in use!')
94            return
95        self.redirect(self.url(self.context))
96
97class DisplayApplicant(WAeUPDisplayFormPage):
98    grok.context(IApplicant)
99    grok.name('index')
100    form_fields = grok.AutoFields(IApplicant)
101    form_fields['fst_sit_results'].custom_widget = list_results_display_widget
102    label = 'Applicant'
103    title = 'Applicant'
104    pnav = 1
105
106class EditApplicant(WAeUPEditFormPage):
107    grok.context(IApplicant)
108    grok.name('edit')
109    form_fields = grok.AutoFields(IApplicantPDEEditData)
110
111    @property
112    def label(self):
113        # XXX: Use current/upcoming session
114        return 'Apply for Post UDE Screening Test (2009/2010)'
115    title = 'Edit Application'
116    pnav = 1
117
118    @grok.action('Save')
119    def save(self, **data):
120        self.applyData(self.context, **data)
121        self.context._p_changed = True
122        return
123
124    @grok.action('Final Submit')
125    def finalsubmit(self, **data):
126        self.applyData(self.context, **data)
127        self.context._p_changed = True
128        # XXX: Lock the form for editing...
129        return
130
131class Login_PDE(LoginPage):
132    grok.context(IWAeUPObject)
133    grok.name('login_pde')
134
135    title = 'PDE Login'
136    pnav = 1
137
138    def update(self):
139        """Validate credentials and redirect or show error.
140
141        The real validation is done by an pluggable authentication
142        utility (PAU). Here we only check, whether correct credentials
143        were entered by looking up the principal status of the
144        request: If the user authenticated successfully, we get an
145        applicant principal. Otherwise we get the unauthenticated
146        principal.
147        """
148        formfields = ['form.ac_number', 'form.jamb_reg_no',
149                      'form.ac_series', 'form.prefix',]
150
151        self.reg_no = self.request.form.get('form.jamb_reg_no', '')
152        self.ac_series = self.request.form.get('form.ac_series', '')
153        self.ac_number = self.request.form.get('form.ac_number', '')
154
155        for required_field in formfields:
156            if required_field not in self.request.form.keys():
157                return
158        self.reg_no = self.request.form['form.jamb_reg_no']
159        self.ac_series = self.request.form['form.ac_series']
160        self.ac_number = self.request.form['form.ac_number']
161        principal = self.request.principal
162        if not IApplicantPrincipal.providedBy(principal):
163            self.flash('You entered invalid credentials')
164            return
165        if hasattr(principal, 'reg_no'):
166            if not principal.reg_no is None:
167               
168                site = grok.getSite()
169                applications = site['applications']
170                application = applications[principal.reg_no]
171                self.redirect(self.url(application, '@@edit'))
172        return
173
174    def getCurrentSession(self):
175        """Get the current session.
176
177        XXX: This should be computed or retrieved from elsewhere.
178
179        `session` here means an academic session, not a browser
180        session.
181        """
182        return u'2010/2011'
183
184    def getDeadline(self):
185        """Get application submission deadline.
186
187        XXX: This should be computed or retrieved from elsewhere.
188        """
189        return u"""Application submission deadline is at Midnight on Friday,
190                   01. October 2010. No application will be treated
191                   after the deadline."""
192
193    def getApplicantData(self, reg_no, ac):
194        """Validate credentials and return applicant data.
195
196        Returns tuple ``(<APPLICANT_ENTRY>, <ACCESSCODE>) on
197        successful validation and ``None`` else.
198
199        We expect a JAMB registration number and an access code in
200        format ``PUDE-XXX-XXXXXXXXXX``.
201
202        See
203        :func:`waeup.sirp.jambtables.util.get_applicant_data`
204        for details.
205        """
206        return get_applicant_data(reg_no, ac)
Note: See TracBrowser for help on using the repository browser.