source: main/waeup.sirp/branches/ulif-fasttables/src/waeup/sirp/jambtables/browser.py @ 5320

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

Add login page for PUDE applicants.

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