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

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

Make login_pde a login page.

File size: 6.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 IApplicant, IApplicantContainer
34
35#from zope.formlib.objectwidget import ObjectWidget
36from zope.formlib.sequencewidget import ListSequenceWidget, SequenceDisplayWidget
37from zope.formlib.widget import CustomWidgetFactory
38from waeup.sirp.jambtables.applicants import ResultEntry
39from waeup.sirp.widgets.objectwidget import (
40    WAeUPObjectWidget, WAeUPObjectDisplayWidget)
41from waeup.sirp.widgets.multilistwidget import (
42    MultiListWidget, MultiListDisplayWidget)
43
44results_widget = CustomWidgetFactory(
45    WAeUPObjectWidget, ResultEntry)
46
47results_display_widget = CustomWidgetFactory(
48    WAeUPObjectDisplayWidget, ResultEntry)
49
50#list_results_widget = CustomWidgetFactory(
51#    ListSequenceWidget, subwidget=results_widget)
52
53list_results_widget = CustomWidgetFactory(
54    MultiListWidget, subwidget=results_widget)
55
56list_results_display_widget = CustomWidgetFactory(
57    MultiListDisplayWidget, subwidget=results_display_widget)
58
59class ApplicationsPage(WAeUPPage):
60    grok.context(IApplicantContainer)
61    grok.name('index')
62    title = 'Applications'
63    pnav = 1
64   
65    def getApplications(self):
66        """Get a list of all stored applications.
67        """
68        for key, val in self.context.items():
69            url = self.url(val)
70            yield(dict(url=url, name=key))
71
72class AddApplicant(WAeUPAddFormPage):
73    grok.context(IApplicantContainer)
74    grok.name('add')
75    form_fields = grok.AutoFields(IApplicant)
76    form_fields['fst_sit_results'].custom_widget = list_results_widget
77    label = 'Add Applicant'
78    title = 'Add Applicant'
79    pnav = 1
80
81    @grok.action('Add applicant')
82    def addApplicant(self, **data):
83        from waeup.sirp.jambtables.applicants import Applicant
84        applicant = Applicant()
85        self.applyData(applicant, **data)
86        self.context[applicant.reg_no] = applicant
87        self.redirect(self.url(self.context))
88
89class DisplayApplicant(WAeUPDisplayFormPage):
90    grok.context(IApplicant)
91    grok.name('index')
92    form_fields = grok.AutoFields(IApplicant)
93    form_fields['fst_sit_results'].custom_widget = list_results_display_widget
94    label = 'Applicant'
95    title = 'Applicant'
96    pnav = 1
97
98class EditApplicant(WAeUPEditFormPage):
99    grok.context(IApplicant)
100    grok.name('edit')
101    form_fields = grok.AutoFields(IApplicant)
102    form_fields['fst_sit_results'].custom_widget = list_results_widget
103    label = 'Edit Application'
104    title = 'Edit Application'
105    pnav = 1
106
107    @grok.action('Save')
108    def save(self, **data):
109        print "DATA: ", data
110        self.applyData(self.context, **data)
111        print "ENTRY: ", self.context.fst_sit_results
112        self.context._p_changed = True
113        return
114
115    @grok.action('Save and return')
116    def saveAndReturn(self, **data):
117        self.applyData(self.context, **data)
118        self.redirect(self.url(self.context))
119        return
120
121    @grok.action('Cancel', validator=NullValidator)
122    def cancel(self, **data):
123        self.redirect(self.url(self.context))
124        return
125
126class Login_PDE(LoginPage):
127    grok.context(IWAeUPObject)
128    grok.name('login_pde')
129
130    title = 'PDE Login'
131    pnav = 1
132
133    def update(self, reg_no=None, ac_series=None, ac_number=None):
134        """Validate credentials and redirect or show error.
135
136        XXX: log things happening here
137        XXX: consider real login procedure with single applicant user.
138        """
139        self.reg_no = reg_no
140        self.ac_series = ac_series
141        self.ac_number = ac_number
142        for param in [reg_no, ac_series, ac_number]:
143            if param is None:
144                return
145        ac = "PUDE-%s-%s" % (ac_series, ac_number)
146        data = self.getApplicantData(reg_no, ac)
147        if data is None:
148            self.flash('Invalid data entered')
149            return
150        applicant_data, access_code = data
151        app_page = self.url(applicant_data, '@@edit')
152        # XXX: Invalidate ACCESS_CODE
153        self.redirect(app_page)
154        return
155
156    def getCurrentSession(self):
157        """Get the current session.
158
159        XXX: This should be computed or retrieved from elsewhere.
160        """
161        return u'2010/2011'
162
163    def getDeadline(self):
164        """Get application submission deadline.
165
166        XXX: This should be computed or retrieved from elsewhere.
167        """
168        return u"""Application submission deadline is at Midnight on Friday,
169                   01. October 2010. No application will be treated
170                   after the deadline."""
171
172    def getApplicantData(self, reg_no, ac):
173        """Validate credentials and return applicant data.
174
175        Returns tuple ``(<APPLICANT_ENTRY>, <ACCESSCODE>) on
176        successful validation and ``None`` else.
177
178        We expect a JAMB registration number and an access code in
179        format ``PUDE-XXX-XXXXXXXXXX``.
180
181        See
182        :func:`waeup.sirp.jambtables.util.get_applicant_data`
183        for details.
184        """
185        return get_applicant_data(reg_no, ac)
Note: See TracBrowser for help on using the repository browser.