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

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

Fix changed dotted paths of widgets.

File size: 4.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.jambtables import JAMBDataTable
30from waeup.sirp.jambtables.interfaces import IApplicant, IApplicantContainer
31
32#from zope.formlib.objectwidget import ObjectWidget
33from zope.formlib.sequencewidget import ListSequenceWidget, SequenceDisplayWidget
34from zope.formlib.widget import CustomWidgetFactory
35from waeup.sirp.jambtables.applicants import ResultEntry
36from waeup.sirp.widgets.objectwidget import (
37    WAeUPObjectWidget, WAeUPObjectDisplayWidget)
38from waeup.sirp.widgets.multilistwidget import (
39    MultiListWidget, MultiListDisplayWidget)
40results_widget = CustomWidgetFactory(
41    WAeUPObjectWidget, ResultEntry)
42
43results_display_widget = CustomWidgetFactory(
44    WAeUPObjectDisplayWidget, ResultEntry)
45
46#list_results_widget = CustomWidgetFactory(
47#    ListSequenceWidget, subwidget=results_widget)
48
49list_results_widget = CustomWidgetFactory(
50    MultiListWidget, subwidget=results_widget)
51
52list_results_display_widget = CustomWidgetFactory(
53    MultiListDisplayWidget, subwidget=results_display_widget)
54
55class ApplicationsPage(WAeUPPage):
56    grok.context(IApplicantContainer)
57    grok.name('index')
58    title = 'Applications'
59    pnav = 1
60   
61    def getApplications(self):
62        """Get a list of all stored applications.
63        """
64        for key, val in self.context.items():
65            url = self.url(val)
66            yield(dict(url=url, name=key))
67
68class AddApplicant(WAeUPAddFormPage):
69    grok.context(IApplicantContainer)
70    grok.name('add')
71    form_fields = grok.AutoFields(IApplicant)
72    form_fields['fst_sit_results'].custom_widget = list_results_widget
73    label = 'Add Applicant'
74    title = 'Add Applicant'
75    pnav = 1
76
77    @grok.action('Add applicant')
78    def addApplicant(self, **data):
79        from waeup.sirp.jambtables.applicants import Applicant
80        applicant = Applicant()
81        self.applyData(applicant, **data)
82        self.context[applicant.reg_no] = applicant
83        self.redirect(self.url(self.context))
84
85class DisplayApplicant(WAeUPDisplayFormPage):
86    grok.context(IApplicant)
87    grok.name('index')
88    form_fields = grok.AutoFields(IApplicant)
89    form_fields['fst_sit_results'].custom_widget = list_results_display_widget
90    label = 'Applicant'
91    title = 'Applicant'
92    pnav = 1
93
94class EditApplicant(WAeUPEditFormPage):
95    grok.context(IApplicant)
96    grok.name('edit')
97    form_fields = grok.AutoFields(IApplicant)
98    form_fields['fst_sit_results'].custom_widget = list_results_widget
99    label = 'Edit Application'
100    title = 'Edit Application'
101    pnav = 1
102
103    @grok.action('Save')
104    def save(self, **data):
105        print "DATA: ", data
106        self.applyData(self.context, **data)
107        print "ENTRY: ", self.context.fst_sit_results
108        self.context._p_changed = True
109        return
110
111    @grok.action('Save and return')
112    def saveAndReturn(self, **data):
113        self.applyData(self.context, **data)
114        self.redirect(self.url(self.context))
115        return
116
117    @grok.action('Cancel', validator=NullValidator)
118    def cancel(self, **data):
119        self.redirect(self.url(self.context))
120        return
Note: See TracBrowser for help on using the repository browser.