[Zope3-Users] zope.schema.Object and custom widgets in formlib

Jachin Rupe jachin at voltzsoftware.com
Fri May 19 15:21:23 EDT 2006


>
> [snip]
>
>> I still haven't gotten it working yet though.  I'm going to keep  
>> trying to figure out what
>> the problem is, I think I see what your basic strategy is.
>>
>> However there are a few error I found in your example you may be  
>> interested in fixing:
>>
>> in your interfaces.py file you probably want the IPhoneBookEntry  
>> interface to look like
>> this:
>
> [...]
>
> Sorry for the Typo - corrected it. But the whole concept works for  
> me - I'm
> using schema.Object, too.
>
> Maybe I can help - what's the problem?


I'm still getting a "ComponentLookupError".  I'll just include the  
example I'm trying to make work at the bottom, it's pretty short.   
I'm beginning to think there may be something in your explication  
that I need to understand.

Also, from looking at your example I'm guessing your using the SVN  
version of zope3, is that true and do you happen to know if that  
would make a difference?  I'm currently using Zope-3.2.1.

thanks

-jachin

# -=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)

from zope.app.form.browser import ObjectWidget
from entry import ABookEntry

def ABookEntryWidget(context,obj,request):
	# We create an objectwidget which is aware of the correct object
	# factory (here:PhoneNumber)
	return ObjectWidget(context, request, ABookEntry)



# -=widgets.py=-

from zope.app.form.browser import ObjectWidget
from entry import ABookEntry

def ABookEntryWidget(context,obj,request):
	return ObjectWidget(context, request, ABookEntry)



<!-- -=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 .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>


More information about the Zope3-users mailing list