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

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

Fix more imports.

File size: 7.8 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 import JAMBDataTable
33from waeup.sirp.applicants.jambtables.util import get_applicant_data
34from waeup.sirp.applicants.jambtables.interfaces import (
35    IApplicant, IApplicantContainer, IApplicantPrincipal, IApplicantPDEEditData)
36from waeup.sirp.widgets.passportwidget import (
37    PassportWidget, PassportDisplayWidget
38    )
39#from zope.formlib.objectwidget import ObjectWidget
40from zope.formlib.sequencewidget import ListSequenceWidget, SequenceDisplayWidget
41from zope.formlib.widget import CustomWidgetFactory
42from waeup.sirp.applicants.jambtables.applicants import ResultEntry
43from waeup.sirp.widgets.objectwidget import (
44    WAeUPObjectWidget, WAeUPObjectDisplayWidget)
45from waeup.sirp.widgets.multilistwidget import (
46    MultiListWidget, MultiListDisplayWidget)
47from waeup.sirp.image.browser.widget import (
48    ThumbnailWidget, EncodingImageFileWidget,
49    )
50
51results_widget = CustomWidgetFactory(
52    WAeUPObjectWidget, ResultEntry)
53
54results_display_widget = CustomWidgetFactory(
55    WAeUPObjectDisplayWidget, ResultEntry)
56
57#list_results_widget = CustomWidgetFactory(
58#    ListSequenceWidget, subwidget=results_widget)
59
60list_results_widget = CustomWidgetFactory(
61    MultiListWidget, subwidget=results_widget)
62
63list_results_display_widget = CustomWidgetFactory(
64    MultiListDisplayWidget, subwidget=results_display_widget)
65
66class ApplicationsPage(WAeUPPage):
67    grok.context(IApplicantContainer)
68    grok.name('index')
69    title = 'Applications'
70    pnav = 1
71   
72    def getApplications(self):
73        """Get a list of all stored applications.
74        """
75        for key, val in self.context.items():
76            url = self.url(val)
77            yield(dict(url=url, name=key))
78
79class AddApplicant(WAeUPAddFormPage):
80    grok.context(IApplicantContainer)
81    grok.name('add')
82    form_fields = grok.AutoFields(IApplicant)
83    form_fields['fst_sit_results'].custom_widget = list_results_widget
84    form_fields['passport'].custom_widget = EncodingImageFileWidget
85    label = 'Add Applicant'
86    title = 'Add Applicant'
87    pnav = 1
88
89    @grok.action('Add applicant')
90    def addApplicant(self, **data):
91        from waeup.sirp.jambtables.applicants import Applicant
92        applicant = Applicant()
93        self.applyData(applicant, **data)
94        # XXX: temporarily disabled.
95        #self.context[applicant.reg_no] = applicant
96        try:
97            self.context[applicant.access_code] = applicant
98        except KeyError:
99            self.flash('The given access code is already in use!')
100            return
101        self.redirect(self.url(self.context))
102
103class DisplayApplicant(WAeUPDisplayFormPage):
104    grok.context(IApplicant)
105    grok.name('index')
106    form_fields = grok.AutoFields(IApplicant)
107    form_fields['fst_sit_results'].custom_widget = list_results_display_widget
108    #form_fields['passport'].custom_widget = PassportDisplayWidget
109    form_fields['passport'].custom_widget = ThumbnailWidget
110    label = 'Applicant'
111    title = 'Applicant'
112    pnav = 1
113
114class EditApplicant(WAeUPEditFormPage):
115    grok.context(IApplicant)
116    grok.name('edit')
117    form_fields = grok.AutoFields(IApplicantPDEEditData)
118    #form_fields['passport'].custom_widget = FileWidget
119    #form_fields['passport'].custom_widget = PassportWidget
120    form_fields['passport'].custom_widget = EncodingImageFileWidget
121    grok.template('form_edit_pde')
122
123    def update(self):
124        super(EditApplicant, self).update()
125        print self.request.form
126        return
127   
128    @property
129    def label(self):
130        # XXX: Use current/upcoming session
131        return 'Apply for Post UDE Screening Test (2009/2010)'
132    title = 'Edit Application'
133    pnav = 1
134
135    @grok.action('Save')
136    def save(self, **data):
137        self.applyData(self.context, **data)
138        self.context._p_changed = True
139        return
140
141    @grok.action('Final Submit')
142    def finalsubmit(self, **data):
143        self.applyData(self.context, **data)
144        self.context._p_changed = True
145        # XXX: Lock the form for editing...
146        return
147
148class Login_PDE(LoginPage):
149    grok.context(IWAeUPObject)
150    grok.name('login_pde')
151
152    title = 'PDE Login'
153    pnav = 1
154
155    def update(self):
156        """Validate credentials and redirect or show error.
157
158        The real validation is done by an pluggable authentication
159        utility (PAU). Here we only check, whether correct credentials
160        were entered by looking up the principal status of the
161        request: If the user authenticated successfully, we get an
162        applicant principal. Otherwise we get the unauthenticated
163        principal.
164        """
165        formfields = ['form.ac_number', 'form.jamb_reg_no',
166                      'form.ac_series', 'form.prefix',]
167
168        self.reg_no = self.request.form.get('form.jamb_reg_no', '')
169        self.ac_series = self.request.form.get('form.ac_series', '')
170        self.ac_number = self.request.form.get('form.ac_number', '')
171
172        for required_field in formfields:
173            if required_field not in self.request.form.keys():
174                return
175        self.reg_no = self.request.form['form.jamb_reg_no']
176        self.ac_series = self.request.form['form.ac_series']
177        self.ac_number = self.request.form['form.ac_number']
178        principal = self.request.principal
179        if not IApplicantPrincipal.providedBy(principal):
180            self.flash('You entered invalid credentials')
181            return
182        if hasattr(principal, 'reg_no'):
183            if not principal.reg_no is None:
184               
185                site = grok.getSite()
186                applications = site['applications']
187                application = applications[principal.reg_no]
188                self.redirect(self.url(application, '@@edit'))
189        return
190
191    def getCurrentSession(self):
192        """Get the current session.
193
194        XXX: This should be computed or retrieved from elsewhere.
195
196        `session` here means an academic session, not a browser
197        session.
198        """
199        return u'2010/2011'
200
201    def getDeadline(self):
202        """Get application submission deadline.
203
204        XXX: This should be computed or retrieved from elsewhere.
205        """
206        return u"""Application submission deadline is at Midnight on Friday,
207                   01. October 2010. No application will be treated
208                   after the deadline."""
209
210    def getApplicantData(self, reg_no, ac):
211        """Validate credentials and return applicant data.
212
213        Returns tuple ``(<APPLICANT_ENTRY>, <ACCESSCODE>) on
214        successful validation and ``None`` else.
215
216        We expect a JAMB registration number and an access code in
217        format ``PUDE-XXX-XXXXXXXXXX``.
218
219        See
220        :func:`waeup.sirp.jambtables.util.get_applicant_data`
221        for details.
222        """
223        return get_applicant_data(reg_no, ac)
Note: See TracBrowser for help on using the repository browser.