[Zope3-Users] zope.schema.Object and custom widgets in formlib
Jachin Rupe
jachin at voltzsoftware.com
Mon May 22 10:59:09 EDT 2006
On May 22, 2006, at 2:19 AM, Frank Burkhardt wrote:
[snip]
>
> Yes, I'm using Zope-SVN but the ObjectWidget-Code was written for
> ZopeX3.
> I can't see the Dispatcher-Widget. Are you sure, you implemented
> and registered it
> as described in Part "Vorarbeit(Preparation)" of the Howto?
Ah... I was thinking that part was some sort of generic example.
Alright, I added that code and now my component
"ComponentLookupError" cleared up. However I'm now having another
problem. When I add a new
I am getting a "ForbiddenAttribute" error. I can run the addform
with out any errors but if I editform the "street" field is blank
(even though I added some text to it when I added it). Then if I
makes some changes to the fields and try to save my changes I get one
of these:
ForbiddenAttribute: ('street', <simple_abook.entry.ABookEntry object
at 0x405d3b0>)
Anytime I've seen this in the past it means there's a permission
problem. So I played with the security setting in configure.zcml
some but I could not find anything that helped.
Judging from the error message it looks like it's trying to look up
the security settings for "street" in entry.ABookEntry. Which would
kinda makes sense, and then it should be looking instead in
entry.StreetAddress, but I don't know how to make it do that. I'll
include my code again too.
thanks
-jachin
<!-- -===configure.zcml===- -->
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<content class=".entry.ABookEntry">
<factory
id = "entry.ABookEntry"
title = "An address book entry"
/>
<require
permission="zope.View"
interface=".interfaces.IABookEntry"
/>
<require
permission="zope.ManageContent"
set_schema=".interfaces.IABookEntry"
/>
</content>
<content class=".entry.StreetAddress">
<allow interface=".interfaces.IABookEntry" />
</content>
<view type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IObject"
provides="zope.app.form.interfaces.IInputWidget"
factory=".objectwidgetdispatcher.ObjectInputWidget"
permission="zope.Public"
/>
<view
type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IObject .interfaces.IStreetAddress"
provides="zope.app.form.interfaces.IInputWidget"
factory=".widgets.ABookEntryWidget"
permission="zope.Public"
/>
<browser:addform
label = "New address book entry"
name = "add_address_book_entry.html"
schema = ".interfaces.IABookEntry"
content_factory = ".entry.ABookEntry"
permission = "zope.ManageContent"
/>
<browser:editform
label = "Change address book entry"
name = "edit.html"
schema = ".interfaces.IABookEntry"
permission = "zope.ManageContent"
menu="zmi_views"
title="Edit"
/>
<browser:addMenuItem
title="ABook Entry"
class=".entry.ABookEntry"
permission="zope.ManageContent"
view = "add_address_book_entry.html"
/>
</configure>
# -===interfaces.py===-
from zope.interface import Interface
from zope.schema import TextLine, Object
class IStreetAddress(Interface):
"""A street address"""
street = TextLine(
title=u"street",
description=u"",
required=False)
class IABookEntry(Interface):
"""An address book entry"""
streetAddress = Object(
schema=IStreetAddress,
title=u"Street Address",
description=u"",
required=False)
firstName = TextLine(
title=u"First Name",
description=u"",
required=False)
# -===entry.py===-
from zope.interface import implements
from persistent import Persistent
from interfaces import IStreetAddress
from interfaces import IABookEntry
class StreetAddress(Persistent):
"""The Street Address object."""
implements(IStreetAddress)
class ABookEntry(Persistent):
"""The Address Book Entry object."""
implements(IABookEntry)
# -===widgets.py===-
from zope.app.form.browser import ObjectWidget
from entry import ABookEntry
def ABookEntryWidget(context,obj,request):
return ObjectWidget(context, request, ABookEntry)
# -===objectwidgetdispatcher.py===-
from zope.app import zapi
from zope.interface import implements
from zope.app.form.interfaces import IInputWidget
def ObjectInputWidget(context, request):
"""Dispatch widget for Object schema field to a widget that is
registered for (IObject, schema, IBrowserRequest) where schema
is the schema of the object."""
class Obj(object):
implements(context.schema)
widget=zapi.getMultiAdapter((context, Obj(), request), IInputWidget)
return widget
More information about the Zope3-users
mailing list