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

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

Reenable ApplicantsRoot? index page and add page/viewlet for adding
applicant containers.

File size: 6.6 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.component import getUtility, getAllUtilitiesRegisteredFor
27from zope.formlib.widgets import FileWidget
28from waeup.sirp.browser import (
29    WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage,
30    WAeUPDisplayFormPage, NullValidator)
31from waeup.sirp.browser.pages import LoginPage
32from waeup.sirp.interfaces import IWAeUPObject
33from waeup.sirp.browser.viewlets import AddActionButton
34from waeup.sirp.applicants import get_applicant_data, ResultEntry
35from waeup.sirp.applicants.interfaces import (
36    IApplicant, IApplicantPrincipal, IApplicantPDEEditData,
37    IApplicantsRoot, IApplicantsContainer, IApplicantContainerProvider,
38    )
39from waeup.sirp.widgets.passportwidget import (
40    PassportWidget, PassportDisplayWidget
41    )
42#from zope.formlib.objectwidget import ObjectWidget
43from zope.formlib.sequencewidget import ListSequenceWidget, SequenceDisplayWidget
44from zope.formlib.widget import CustomWidgetFactory
45from waeup.sirp.widgets.objectwidget import (
46    WAeUPObjectWidget, WAeUPObjectDisplayWidget)
47from waeup.sirp.widgets.multilistwidget import (
48    MultiListWidget, MultiListDisplayWidget)
49from waeup.sirp.image.browser.widget import (
50    ThumbnailWidget, EncodingImageFileWidget,
51    )
52
53results_widget = CustomWidgetFactory(
54    WAeUPObjectWidget, ResultEntry)
55
56results_display_widget = CustomWidgetFactory(
57    WAeUPObjectDisplayWidget, ResultEntry)
58
59#list_results_widget = CustomWidgetFactory(
60#    ListSequenceWidget, subwidget=results_widget)
61
62list_results_widget = CustomWidgetFactory(
63    MultiListWidget, subwidget=results_widget)
64
65list_results_display_widget = CustomWidgetFactory(
66    MultiListDisplayWidget, subwidget=results_display_widget)
67
68class ApplicationsPage(WAeUPPage):
69    grok.context(IApplicantsRoot)
70    grok.name('index')
71    title = 'Applicants'
72    pnav = 1
73   
74    def getApplications(self):
75        """Get a list of all stored applicant containers.
76        """
77        for key, val in self.context.items():
78            url = self.url(val)
79            yield(dict(url=url, name=key))
80
81class AddApplicantsContainerActionButton(AddActionButton):
82    grok.context(IApplicantsRoot)
83    grok.view(ApplicationsPage)
84    text = 'Add applicants container'
85
86class AddApplicantsContainer(WAeUPPage):
87    grok.context(IApplicantsRoot)
88    grok.name('add')
89    grok.template('addcontainer')
90    title = 'Add applicants container'
91    pnav = 1
92
93    def update(self, providername=None, name=None, ADD=None, CANCEL=None):
94        if CANCEL is not None:
95            self.redirect(self.url(self.context))
96            return
97        if ADD is None:
98            return
99        if not name:
100            self.flash('Error: you must give a name')
101            return
102        if name in self.context.keys():
103            self.flash('A container of the given name already exists')
104            return
105        # Add new applicants container...
106        provider = getUtility(IApplicantContainerProvider,
107                              name=providername)
108        container = provider.factory()
109        self.context[name] = container
110        self.flash('Added "%s".' % name)
111        self.redirect(self.url(self.context))
112        return
113       
114    def getContainerProviders(self):
115
116        providers = getAllUtilitiesRegisteredFor(IApplicantContainerProvider)
117        result = [
118            {'name': getattr(x, 'grokcore.component.directive.name'),
119             'provider': x}
120             for x in providers
121            ]
122        return result
123       
124#class AddApplicant(WAeUPAddFormPage):
125#    grok.context(IApplicantContainer)
126#    grok.name('add')
127#    form_fields = grok.AutoFields(IApplicant)
128#    form_fields['fst_sit_results'].custom_widget = list_results_widget
129#    form_fields['passport'].custom_widget = EncodingImageFileWidget
130#    label = 'Add Applicant'
131#    title = 'Add Applicant'
132#    pnav = 1
133#
134#    @grok.action('Add applicant')
135#    def addApplicant(self, **data):
136#        from waeup.sirp.jambtables.applicants import Applicant
137#        applicant = Applicant()
138#        self.applyData(applicant, **data)
139#        # XXX: temporarily disabled.
140#        #self.context[applicant.reg_no] = applicant
141#        try:
142#            self.context[applicant.access_code] = applicant
143#        except KeyError:
144#            self.flash('The given access code is already in use!')
145#            return
146#        self.redirect(self.url(self.context))
147
148class DisplayApplicant(WAeUPDisplayFormPage):
149    grok.context(IApplicant)
150    grok.name('index')
151    form_fields = grok.AutoFields(IApplicant)
152    form_fields['fst_sit_results'].custom_widget = list_results_display_widget
153    #form_fields['passport'].custom_widget = PassportDisplayWidget
154    form_fields['passport'].custom_widget = ThumbnailWidget
155    label = 'Applicant'
156    title = 'Applicant'
157    pnav = 1
158
159class EditApplicant(WAeUPEditFormPage):
160    grok.context(IApplicant)
161    grok.name('edit')
162    form_fields = grok.AutoFields(IApplicantPDEEditData)
163    #form_fields['passport'].custom_widget = FileWidget
164    #form_fields['passport'].custom_widget = PassportWidget
165    form_fields['passport'].custom_widget = EncodingImageFileWidget
166    grok.template('form_edit_pde')
167
168    def update(self):
169        super(EditApplicant, self).update()
170        print self.request.form
171        return
172   
173    @property
174    def label(self):
175        # XXX: Use current/upcoming session
176        return 'Apply for Post UDE Screening Test (2009/2010)'
177    title = 'Edit Application'
178    pnav = 1
179
180    @grok.action('Save')
181    def save(self, **data):
182        self.applyData(self.context, **data)
183        self.context._p_changed = True
184        return
185
186    @grok.action('Final Submit')
187    def finalsubmit(self, **data):
188        self.applyData(self.context, **data)
189        self.context._p_changed = True
190        # XXX: Lock the form for editing...
191        return
Note: See TracBrowser for help on using the repository browser.