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

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

Use new function from util.

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