source: main/waeup.sirp/branches/ulif-images/src/waeup/sirp/jambtables/browser.py @ 9819

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

Commit local changes (work inprogress)

File size: 7.8 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
[5530]26from zope.formlib.widgets import FileWidget
[5273]27from waeup.sirp.browser import (
28    WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage,
29    WAeUPDisplayFormPage, NullValidator)
[5442]30from waeup.sirp.browser.pages import LoginPage
[5320]31from waeup.sirp.interfaces import IWAeUPObject
[5273]32from waeup.sirp.jambtables import JAMBDataTable
[5325]33from waeup.sirp.jambtables.util import get_applicant_data
[5453]34from waeup.sirp.jambtables.interfaces import (
[5484]35    IApplicant, IApplicantContainer, IApplicantPrincipal, IApplicantPDEEditData)
[5530]36from waeup.sirp.widgets.passportwidget import (
37    PassportWidget, PassportDisplayWidget
38    )
[5273]39#from zope.formlib.objectwidget import ObjectWidget
40from zope.formlib.sequencewidget import ListSequenceWidget, SequenceDisplayWidget
41from zope.formlib.widget import CustomWidgetFactory
42from waeup.sirp.jambtables.applicants import ResultEntry
[5303]43from waeup.sirp.widgets.objectwidget import (
[5301]44    WAeUPObjectWidget, WAeUPObjectDisplayWidget)
[5303]45from waeup.sirp.widgets.multilistwidget import (
[5273]46    MultiListWidget, MultiListDisplayWidget)
[5530]47from waeup.sirp.image.browser.widget import (
48    ThumbnailWidget, EncodingImageFileWidget,
49    )
[5320]50
[5273]51results_widget = CustomWidgetFactory(
[5301]52    WAeUPObjectWidget, ResultEntry)
[5273]53
54results_display_widget = CustomWidgetFactory(
[5301]55    WAeUPObjectDisplayWidget, ResultEntry)
[5273]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
[5530]84    form_fields['passport'].custom_widget = EncodingImageFileWidget
[5273]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)
[5453]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
[5273]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
[5530]108    #form_fields['passport'].custom_widget = PassportDisplayWidget
109    form_fields['passport'].custom_widget = ThumbnailWidget
[5273]110    label = 'Applicant'
111    title = 'Applicant'
112    pnav = 1
113
114class EditApplicant(WAeUPEditFormPage):
115    grok.context(IApplicant)
116    grok.name('edit')
[5484]117    form_fields = grok.AutoFields(IApplicantPDEEditData)
[5530]118    #form_fields['passport'].custom_widget = FileWidget
119    #form_fields['passport'].custom_widget = PassportWidget
120    form_fields['passport'].custom_widget = EncodingImageFileWidget
[5488]121    grok.template('form_edit_pde')
[5484]122
[5530]123    def update(self):
124        super(EditApplicant, self).update()
125        print self.request.form
126        return
127   
[5484]128    @property
129    def label(self):
130        # XXX: Use current/upcoming session
131        return 'Apply for Post UDE Screening Test (2009/2010)'
[5273]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
[5484]141    @grok.action('Final Submit')
142    def finalsubmit(self, **data):
[5273]143        self.applyData(self.context, **data)
[5484]144        self.context._p_changed = True
145        # XXX: Lock the form for editing...
[5273]146        return
147
[5442]148class Login_PDE(LoginPage):
[5320]149    grok.context(IWAeUPObject)
150    grok.name('login_pde')
151
152    title = 'PDE Login'
153    pnav = 1
154
[5453]155    def update(self):
[5320]156        """Validate credentials and redirect or show error.
157
[5453]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.
[5320]164        """
[5453]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():
[5320]174                return
[5453]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')
[5320]181            return
[5453]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'))
[5320]189        return
190
191    def getCurrentSession(self):
192        """Get the current session.
193
194        XXX: This should be computed or retrieved from elsewhere.
[5453]195
196        `session` here means an academic session, not a browser
197        session.
[5320]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``.
[5325]218
219        See
220        :func:`waeup.sirp.jambtables.util.get_applicant_data`
221        for details.
[5320]222        """
[5325]223        return get_applicant_data(reg_no, ac)
Note: See TracBrowser for help on using the repository browser.