Re: [Zope3-Users] "has a" relationships
hi there Alright... I'm working on implementing IPerson in the class Person and I'm not sure exactly what has to happen. I kinda have two ideas but I suspect I need to some how combine them but I don't know how to do that. A big part of the problem is that I do not know what zope.schema.fieldproperty.FieldProperty does. The only reason I'm working it in, is because it appears to be necessary to get this whole thing to work: http://svn.zope.org/Zope3/trunk/src/zope/app/form/browser/ objectwidget.txt Here are my ideas: -- from persistent import Persistent from zope.interface import implements from abook.interfaces import IPerson class Person(Persistent): implements(IPerson) firstName = u"" lastName = u"" phoneNumbers = persistent.dict.PersistentDict() emails = persistent.dict.PersistentDict() addresses = persistent.dict.PersistentDict() -- from persistent import Persistent from zope.interface import implements from zope.schema.fieldproperty import FieldProperty from abook.interfaces import IStreetAddress from abook.interfaces import IPerson class Person(Persistent): implements(IPerson) phoneNumbers = FieldProperty(IPerson['phoneNumbers']) emails = FieldProperty(IPerson['emails']) addresses = FieldProperty(IPerson['addresses']) def __init__(self, firstName = u"", lastName = u"", phoneNumbers = None, emails = None, addresses = None): self.firstName = firstName self.lastName = lastName self.phoneNumbers = phoneNumbers self.emails = emails self.addresses = addresses -- I guess my question is, how should I be implementing Person? Is one of those right or are they both wrong? thanks -jachin #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
Re: [Zope3-Users] "has a" relationships
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: ((0x16e5430>, URL=http://localhost:8080/something/@@contents.html>), , 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=IStr
Re: [Zope3-Users] "has a" relationships
On May 4, 2006, at 5: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. Depends on the relationship. 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. This should work, and it seems like the right way to model this particular kind of relationship. If you were to want to reuse address objects for multiple people then you might need some different choices (of which there are many approaches and implementations). Gary ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] "has a" relationships
On Fri, 2006-05-05 at 08:49 +0100, Cliff Ford wrote: > An alternative to including addresses in the ICompany/IPerson schemas > would be to use Annotations. And you might also consider using a > relational database. For me, the "add an Address Object" notion does not > make much sense - either the address fields are part of the IPerson and > ICompany schemas or they are not. > To me it doesn't feel right to store Address details in annotations as company/person address is part of the actual data model and should be included in the schema. I would probably have something like addresses Dict attribute as part of the ICompany and IPerson schema. The dictionary would have address type ('personal', 'work', 'home' etc.) as the key, and values of the dictionary being IAddress type objects. Alen ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] "has a" relationships
An alternative to including addresses in the ICompany/IPerson schemas would be to use Annotations. And you might also consider using a relational database. For me, the "add an Address Object" notion does not make much sense - either the address fields are part of the IPerson and ICompany schemas or they are not. Cliff 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@zope.org http://mail.zope.org/mailman/listinfo/zope3-users ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users