Re: [Zope3-Users] sequence of custom widgets
Frank Burkhardt wrote: some months ago, Phillip von Weitershausen wrote such a widget for me. I'm not using it anymore and I don't know, if it's still working. But maybe it will help: Thank you (and Phil), having a template surely come handy, but I have another problem. Even with the default sequence widget, the form appears to work. At the moment I press Add, however, the following is raised: Traceback (innermost last): Module zope.publisher.publish, line 138, in publish result = publication.callObject(request, object) Module zope.app.publication.zopepublication, line 161, in callObject return mapply(ob, request.getPositionalArguments(), request) Module zope.publisher.publish, line 113, in mapply return debug_call(object, args) - __traceback_info__: security proxied zope.app.publisher.browser.viewmeta.FamilyAdd instance at 0xb57c854c [...] Module zope.tal.talinterpreter, line 839, in do_loop_tal iterator = self.engine.setRepeat(name, expr) Module zope.tales.tales, line 685, in setRepeat it = self._engine.iteratorFactory(name, expr, self) Module zope.tales.tales, line 110, in __init__ self._next = i.next() Module zope.formlib.form, line 749, in error_views zope.app.form.browser.interfaces.IWidgetInputErrorView) Module zope.component, line 157, in getMultiAdapter raise ComponentLookupError(objects, interface, name) ComponentLookupError: ((() type 'list', zope.publisher.browser.BrowserRequest instance URL=http://laptop:8080/++skin++Debug/afaf/+/AddFamily.html%3D), InterfaceClass zope.app.form.browser.interfaces.IWidgetInputErrorView, u'') where the list is the list of children I've tried to create: ComponentLookupError: (((person.Person object at 0xb578ea6c,) type 'list', zope.publisher.browser.BrowserRequest instance URL=http://laptop:8080/++skin++Debug/afaf/+/AddFamily.html%3D), InterfaceClass zope.app.form.browser.interfaces.IWidgetInputErrorView, u'') I reckon it's trying to display the error, but.. which one? Do I need to add another view along the lines of this one? !-- Views for Widget Errors -- view type=zope.publisher.interfaces.browser.IBrowserRequest for=zope.app.form.interfaces.IWidgetInputError provides=zope.app.form.browser.interfaces.IWidgetInputErrorView factory=zope.app.form.browser.exception.WidgetInputErrorView permission=zope.Public / I'll try to follow it with the debugger. - person/configure.zcml - configure xmlns=http://namespaces.zope.org/zope; interface interface=.IPerson type=zope.app.content.interfaces.IContentType / content class=.Person factory id=person.Person description=Person / require permission=zope.View interface=.IPerson / require permission=zope.ManageContent set_schema=.IPerson / /content interface interface=.IFamily type=zope.app.content.interfaces.IContentType / content class=.Family factory id=person.Family description=Family / require permission=zope.View interface=.IFamily / require permission=zope.ManageContent set_schema=.IFamily / /content include package=.browser / /configure -- person/__init__.py -- from zope.interface import Interface, implements from zope.schema import TextLine, Object, List, Choice, Field from persistent import Persistent class IPerson(Interface): name = TextLine(title=u'Name', description=u'The first name') class Person(Persistent): implements(IPerson) name = '' class IFamily(Interface): The familiy interface. mother = Object(title=u'Mother', required=False, schema=IPerson) father = Object(title=u'Father', required=False, schema=IPerson) children = List(title=u'Children', required=False, value_type=Object( title=u'Child', schema=IPerson) ) class Family(Persistent): The familiy interface. implements(IFamily) mother = '' father = '' children = [] - person/browser/configure.zcml - configure xmlns:zope=http://namespaces.zope.org/zope; xmlns:browser=http://namespaces.zope.org/browser; !-- PERSON -- browser:page class=.forms.PersonAdd name=AddPerson.html permission=zope.ManageContent for=zope.app.container.interfaces.IAdding / browser:addMenuItem factory=person.Person title=Person description=New Person
Re: [Zope3-Users] sequence of custom widgets
On Mon, May 15, 2006 at 10:43:56PM +0200, Marco Mariani wrote: form_fields['children'].custom_widget = CustomWidgetFactory(SequenceWidget, CustomWidgetFactory(ObjectWidget, Person)) Found it. Passing ListSequenceWidget works well :-) Still curious about the error view, though. ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] sequence of custom widgets
Hi, On Fri, May 12, 2006 at 10:48:52AM +0200, Marco Mariani wrote: I've got a form which contains an object widget given by CustomWidgetFactory(ObjectWidget, MyClass) Now, how can I render a Sequence widget to store a list of MyClass instances? some months ago, Phillip von Weitershausen wrote such a widget for me. I'm not using it anymore and I don't know, if it's still working. But maybe it will help: configure.zcml !-- A widget for rendering objects that are usually used in lists of records structures. -- zope:view type=zope.publisher.interfaces.browser.IBrowserRequest for=zope.schema.interfaces.IObject provides=zope.app.form.interfaces.IInputWidget factory=.widgets.ObjectInputWidget permission=zope.Public / !-- A template based widget for rendering edit forms out of sequences (eg. Lists) that are a bit more user friendly than the defaults. -- zope:view type=zope.publisher.interfaces.browser.IBrowserRequest for=zope.schema.interfaces.IList zope.schema.interfaces.IObject provides=zope.app.form.interfaces.IInputWidget factory=.widgets.TemplateSequenceWidget permission=zope.Public / /configure.zcml widgets.py from zope.app.form.browser import ObjectWidget, ListSequenceWidget from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile from zope.interface import implements from zope.app import zapi from zope.app.form.browser.objectwidget import ObjectWidgetView from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile from zope.app.form.browser.widget import BrowserWidget from zope.app.form.interfaces import IDisplayWidget, IInputWidget from zope.app.form import InputWidget from zope.app.form.interfaces import WidgetInputError, MissingInputError from zope.schema.interfaces import ValidationError, InvalidValue from zope.app.i18n import MessageFactory _=MessageFactory('mpgsite') from zope.i18n import translate from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from zope.app.form.browser.textwidgets import TextWidget from zope.app.form.browser.widget import renderElement def ObjectInputWidget(context, request): Dispatch widget for Object schema field to widget that is registered for (Object, schema) where schema is the schema of the object. class Obj(object): implements(context.schema) return zapi.getMultiAdapter((context, Obj(), request), IInputWidget) class TemplateObjectWidget(ObjectWidget): A Widget that uses a page template def __init__(self, context, request, factory, template_, **kw): super(TemplateObjectWidget, self).__init__(context, request, factory, **kw) class TemplateObjectWidgetView(ObjectWidgetView): template = ViewPageTemplateFile(template_) self.view = TemplateObjectWidgetView(self, request) class TemplateSequenceWidget(ListSequenceWidget): def __init__(self, context, field, request, template_='sequencewidget.pt', subwidget=None): super(TemplateSequenceWidget, self).__init__( context, field, request, subwidget) class TemplateObjectWidgetView(ObjectWidgetView): template = ViewPageTemplateFile(template_) self.view = TemplateObjectWidgetView(self, request) def __call__(self): return self.view() /widgets.py sequencewidget.pt div tal:define=sequence context/_getRenderedValue; num_items python:len(sequence); min_length context/context/min_length; max_length context/context/max_length i18n:domain=mpgsite tal:attributes=class context/classes div class=itemstable div class=items div tal:repeat=i python:range(num_items) tal:block define=value python:sequence[i]; widget python:context._getWidget(i); nixpython:widget.setRenderedValue(value) input class=editcheck type=checkbox tal:attributes=name string:${context/name}.remove_${i} / tal:widget replace=structure widget / /tal:block /div /div /div input type=submit value=Remove selected items tal:condition=python:sequence and num_items min_length tal:attributes=name string:${context/name}.remove i18n:domain=zope i18n:attributes=value remove-selected-items/ input type=submit value=Add item tal:attributes=name string:${context/name}.add tal:condition=python:max_length is None or num_items max_length i18n:attributes=value i18n:domain=zope/ input type=hidden