[Zope3-Users] Combining Views
David Johnson
djohnson at jsatech.com
Wed Mar 22 14:15:53 EST 2006
I have a container and I would like to combine the views of the container
objects. Does anyone have suggestions? This is rather simple and complex
at the same time.
Basically, what I'm trying to do is to display a rather complex form and I
want it to consist of the objects in container.
Imagine buying a car online. Consider the following Zope object layout:
Truck Container:
+ Four Well Drive Options
+ Four Runner Container:
++ Seat Options
++ Stereo Options
++ Color Options
++ Running Board Options
+ Sequoia Container:
++ Seat Options
++ Stereo Options
++ Color Options
+ Tacoma Container:
++ Tow hook Options
++ Stereo Options
++ Color Options
I know only two ways to achieve this objective now, neither which I like.
1. Create a view on the container that calls my showOptions subroutine,
which in turn calls a predefined and specific view class for each content
type. The problem is the large number of conditionals, and its hard to add
more options without modifying each class and hardcoding the content types.
def showOptions(self):
""" Return an HTML string of all of the options and selected
values"""
options = []
for name, child in self.context.items():
if ISeatOptions.providedBy(child):
option = {}
option['title'] = child.name
option['choices'] = SeatOptions(child, self.request,
self.base_url)
options.append(info)
if IColorOptions.providedBy(child):
option = {}
option['title'] = child.name
option['choices'] = ColorOptions(child, self.request,
self.base_url)
options.append(info)
return options
2. Create a subroutine "getForm()" in each content object, and derive all
content objects from "FormOption" to ensure they all have the "getForm()"
function. Then define my showOptions() routine. The problem with this
approach is that it the content object is not actually a typical view, and
so the content object has trouble manipulating sessions and rendering page
templates (because many of the view functions like "self.request, and
self.context", which cause problems with the persistence required for most
content objects).
def getOptions(self):
options = []
for name, child in self.context.items():
if IFormOption.providedBy(child):
option = {}
option['title'] = child.name
option['modifiers'] = child.getForm(self.request)
options.append(info)
return options
--
David Johnson
djohnson at jsatech.com
201 Main Street Suite 1320
Fort Worth, TX 76102
(877) 572-8324 x2200
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope3-users/attachments/20060322/3c73ac80/attachment.htm
More information about the Zope3-users
mailing list