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

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

Remove views not specific for jambtables and respective page templates.

File size: 5.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 zope.formlib.widgets import FileWidget
27from waeup.sirp.browser import (
28    WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage,
29    WAeUPDisplayFormPage, NullValidator)
30from waeup.sirp.browser.pages import LoginPage
31from waeup.sirp.interfaces import IWAeUPObject
32from waeup.sirp.applicants.jambtables.util import get_applicant_data
33from waeup.sirp.applicants.interfaces import (
34    IApplicant, IApplicantPrincipal, IApplicantPDEEditData)
35from waeup.sirp.widgets.passportwidget import (
36    PassportWidget, PassportDisplayWidget
37    )
38#from zope.formlib.objectwidget import ObjectWidget
39from zope.formlib.sequencewidget import ListSequenceWidget, SequenceDisplayWidget
40from zope.formlib.widget import CustomWidgetFactory
41from waeup.sirp.applicants import ResultEntry
42from waeup.sirp.widgets.objectwidget import (
43    WAeUPObjectWidget, WAeUPObjectDisplayWidget)
44from waeup.sirp.widgets.multilistwidget import (
45    MultiListWidget, MultiListDisplayWidget)
46from waeup.sirp.image.browser.widget import (
47    ThumbnailWidget, EncodingImageFileWidget,
48    )
49
50results_widget = CustomWidgetFactory(
51    WAeUPObjectWidget, ResultEntry)
52
53results_display_widget = CustomWidgetFactory(
54    WAeUPObjectDisplayWidget, ResultEntry)
55
56#list_results_widget = CustomWidgetFactory(
57#    ListSequenceWidget, subwidget=results_widget)
58
59list_results_widget = CustomWidgetFactory(
60    MultiListWidget, subwidget=results_widget)
61
62list_results_display_widget = CustomWidgetFactory(
63    MultiListDisplayWidget, subwidget=results_display_widget)
64
65class Login_PDE(LoginPage):
66    grok.context(IWAeUPObject)
67    grok.name('login_pde')
68
69    title = 'PDE Login'
70    pnav = 1
71
72    def update(self):
73        """Validate credentials and redirect or show error.
74
75        The real validation is done by an pluggable authentication
76        utility (PAU). Here we only check, whether correct credentials
77        were entered by looking up the principal status of the
78        request: If the user authenticated successfully, we get an
79        applicant principal. Otherwise we get the unauthenticated
80        principal.
81        """
82        formfields = ['form.ac_number', 'form.jamb_reg_no',
83                      'form.ac_series', 'form.prefix',]
84
85        self.reg_no = self.request.form.get('form.jamb_reg_no', '')
86        self.ac_series = self.request.form.get('form.ac_series', '')
87        self.ac_number = self.request.form.get('form.ac_number', '')
88
89        for required_field in formfields:
90            if required_field not in self.request.form.keys():
91                return
92        self.reg_no = self.request.form['form.jamb_reg_no']
93        self.ac_series = self.request.form['form.ac_series']
94        self.ac_number = self.request.form['form.ac_number']
95        principal = self.request.principal
96        if not IApplicantPrincipal.providedBy(principal):
97            self.flash('You entered invalid credentials')
98            return
99        if hasattr(principal, 'reg_no'):
100            if not principal.reg_no is None:
101               
102                site = grok.getSite()
103                applications = site['applications']
104                application = applications[principal.reg_no]
105                self.redirect(self.url(application, '@@edit'))
106        return
107
108    def getCurrentSession(self):
109        """Get the current session.
110
111        XXX: This should be computed or retrieved from elsewhere.
112
113        `session` here means an academic session, not a browser
114        session.
115        """
116        return u'2010/2011'
117
118    def getDeadline(self):
119        """Get application submission deadline.
120
121        XXX: This should be computed or retrieved from elsewhere.
122        """
123        return u"""Application submission deadline is at Midnight on Friday,
124                   01. October 2010. No application will be treated
125                   after the deadline."""
126
127    def getApplicantData(self, reg_no, ac):
128        """Validate credentials and return applicant data.
129
130        Returns tuple ``(<APPLICANT_ENTRY>, <ACCESSCODE>) on
131        successful validation and ``None`` else.
132
133        We expect a JAMB registration number and an access code in
134        format ``PUDE-XXX-XXXXXXXXXX``.
135
136        See
137        :func:`waeup.sirp.jambtables.util.get_applicant_data`
138        for details.
139        """
140        return get_applicant_data(reg_no, ac)
Note: See TracBrowser for help on using the repository browser.