[Zope3-Users] "has a" relationships
Jachin Rupe
jachin at voltzsoftware.com
Tue May 9 14:03:27 EDT 2006
hi there
I've spent the last couple of days reading the resonses to this
question and trying to figure things out on my own. I've made some
headway but I'm stuck on trying to get my zope.schema.object field to
show up in my addform and editform:
ComponentLookupError: ((<zope.schema._field.Object object at
0x16e5430>, <zope.publisher.browser.BrowserRequest instance
URL=http://localhost:8080/something/@@contents.html>),
<InterfaceClass zope.app.form.interfaces.IInputWidget>, u'')
127.0.0.1 - - [8/May/2006:18:16:41 -0500] "POST /something/
@@contents.html HTTP/1.1" 500 84 "http://localhost:8080/something/
@@contents.html" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-
US; rv:1.8.0.3) Gecko/20060427 Camino/1.0.1"
Near as I can tell this is exactly the same problem as this one:
http://www.mail-archive.com/zope3-users@zope.org/msg00052.html
However I'm not really understanding the answer:
http://svn.zope.org/Zope3/trunk/src/zope/app/form/browser/
objectwidget.txt
I think this is because my problem is (at least in part) because I'm
missing some ZCML. Since objectwidget.txt is just a bunch of tests
and the connections between ZCML and the python code is still a
little fuzzy in my head I'm struggling to understand what I have to do.
So I have decided to work on a more clear example. I'm thinking that
if I see it through to something like completion it would be a useful
example for others. I haven't seen anything like this in any of the
Zope3 books I have read. Maybe post it on http://zopelabs.com or
something of that nature.
Anyway it's an address book for keeping track of people and business
addresses. What's "cool" about it, is that you will be able to add
more than one phone number, email address or phone number and give
each one a type. So for example an entry for a person could include
email addresses for home, work and school.
I just started it and since I have never gotten anything this
complicated to work yet I thought I would throw up the schema I'm
planning on implementing as well as the implementation of of the
StreetAddress classes and a short unit test I wrote to catch silly
errors.
#------------abook/interfaces.py------------
from zope.interface import Interface
import zope.schema
class IStreetAddress(Interface):
"""A vine street address"""
street = zope.schema.Text (
title=u"Street 1",
description=u"The street address",
required = False
)
city = zope.schema.TextLine (
title=u"City",
description=u"The city.",
required = False
)
state = zope.schema.TextLine (
title=u"State",
description=u"The state.",
required = False
)
zipcode = zope.schema.TextLine (
title=u"Zip Code",
description=u"The zip code",
required = False,
min_length = 5
)
class IABookEntry(Interface):
phoneNumbers = zope.schema.Dict(
title=u"Phone Numbers",
description=u"The phone numbers for this entry",
required=False,
key_type=zope.schema.TextLine (
title=u"Type",
description=u"The type of phone number",
required=True
),
value_type=zope.schema.TextLine (
title=u"Number",
description=u"The phone number.",
required=True
)
)
emails = zope.schema.Dict(
title=u"Email Addresses",
description=u"The email addresses for this entry",
required=False,
key_type=zope.schema.TextLine (
title=u"Type",
description=u"The type of email address",
required=True
),
value_type=zope.schema.TextLine (
title=u"Email Address",
description=u"The email address.",
required=True
)
)
addresses = zope.schema.Dict(
title=u"Addresses",
description=u"Street address",
required=False,
key_type=zope.schema.TextLine(
title=u"Type",
description=u"The type of street address",
required=True
),
value_type=zope.schema.Object (
title=u"Street Address",
description=u"A street address",
required=True,
schema=IStreetAddress
)
)
class IPerson(IABookEntry):
firstName = zope.schema.TextLine (
title=u"First Name",
description=u"The person's first name",
required=False
)
lastName = zope.schema.TextLine (
title=u"Last Name",
description=u"The person's last name",
required=False
)
class IBusiness(IABookEntry):
businessName = zope.schema.TextLine (
title=u"Business Name",
description=u"The business' last name",
required=False
)
#------------abook/streetAddress.py------------
from persistent import Persistent
from zope.interface import implements
from abook.interfaces import IStreetAddress
class StreetAddress(Persistent):
"""This is a class for holding street addresses
Make sure that StreetAddress implements the
correct interface interface:
>>> from zope.interface.verify import verifyClass
>>> verifyClass(IStreetAddress, StreetAddress)
True
Now lets expierment with changing around some of
the attributes:
>>> a = StreetAddress()
>>> a.street
u''
>>> a.street = u"123 Some St."
>>> a.street
u'123 Some St.'
>>> a.city
u''
>>> a.state
u''
>>> a.zipcode
u''
"""
implements(IStreetAddress)
street = u""
city = u""
state = u""
zipcode = u""
#------------abook/tests/test_StreetAddress.py------------
import unittest
from zope.testing.doctestunit import DocTestSuite
def test_suite():
return unittest.TestSuite((
DocTestSuite('abook.streetAddress'),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
If I'm going about this all wrong or doing something silly please let
me know.
In the mean time I'm going to keep working on this. I'll post more
code once I get it written. Once I get to the point where I get that
ComponentLookupError I'm probably going to need some help.
thanks
-jachin
On May 4, 2006, at 4:16 PM, Jachin Rupe wrote:
> hi there
>
> I have another "zope theory" question. I am working on designing a
> application in zope. I've been looking at a lot of examples and I
> am wondering how people are implementing different types of
> relationships between different persistent objects.
>
> For instance I am going to be doing a lot with addresses.
> Naturally it would be nice to have persistent Address class. Then
> I would say that a Person has an Address and a Company has an Address.
>
> My two different ideas are as follows:
>
> 1. Make Person and and Company containers that can each contain an
> Address. I don't really like this idea because it seems like
> container objects are for things like folders. This could be the
> best way though and I'm just not zoppie enough yet.
>
> 2. Add an Object for the Address to the schema for IPerson and
> ICompany (assuming I only need one address) or a List / Dict (if I
> want more than one address for each person or company). I like
> this idea better but I have yet to see any examples where someone
> does that which is making me a little nervous. Among other things
> I'd like to be able to see what happens when "addform"s and
> "editform"s get generated for things like this or at least be
> assured that's the way it is supposed to work.
>
> I just got my very own copies of the "Zope 3 Developers Handbook"
> and "Web Component Development with Zope 3" (I'd suggest these
> books to anyone by the way). I have given each a once over as well
> as looking at lots of shorter tutorials / examples online and have
> not noticed any example projects doing anything like my second idea.
>
> So in your answer please feel free to point out something in either
> of those books (I may have missed) or refer me to some other online
> example where something like this is going on.
>
> thanks
>
> -jachin
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
More information about the Zope3-users
mailing list