[Zope3-Users] list woes

Bernd Dorn zope-mailinglist at mopa.at
Thu Jun 15 03:45:23 EDT 2006


On 13.06.2006, at 00:16, Marco Mariani wrote:

> I'm having this stripped-down use case.
>
>
>
> class IToy(Interface):
>     name = TextLine(title=u"Toy")
>
> class Toy(Persistent):
>     name = FieldProperty(IToy['name'])
>
>
> class IGadget(Interface):
>     name = TextLine(title=u"Gadget")
>
> class Gadget(Persistent):
>     name = FieldProperty(IGadget['name'])
>
>     def __init__(self,toy):
>         super(Person, self).__init__(self)
>         self.name = toy.name
>
>
>
> class IBaby(Interface):
>     name = TextLine(title=u"Name")
>     toys = List(title=u"toys",value_type=Object 
> (schema=IToy,title=u"toy")
>
> class IPerson(Interface):
>     name = TextLine(title=u"Name")
>     gadgets =
> List(title=u"toys",value_type=Object(schema=IGadget,title=u"toy")
>
>
> class Baby(Persistent):
>     name = FieldProperty(IBaby['name'])
>     toys = FieldProperty(IBaby['toys'])
>
> class Person(Persistent):
>     name = FieldProperty(IBaby['name'])
>     gadgets = FieldProperty(IPerson['gadgets'])
>
>     def __init__(self,baby):
>         super(Person, self).__init__(self)
>         self.name = baby.name
>
>
>
> When IBaby is at the end of its workflow, it should be replaced by an
> IPerson.
>
> So I've made a view that creates a new IPerson based on data from the
> old IBaby, and replaces the baby with the person on its container.
>
> class BabyView(BrowserView):
>
>     def growup(self):
>         baby = self.context
>         parentfolder = baby.__parent__
>         id = baby.__name__
>         person = Person(baby)
>         del parentfolder[id]
>         parentfolder[id] = person
>
> self.request.response.redirect(zapi.absoluteURL(person,self.request) 
> +'/@@edit.html')
>
>
> It works, and I see the new object with the name I passed over from  
> IBaby.
>
> The trouble is when I add the following to growup()
>
>         person.gadgets = [ Gadget(toy) for toy in baby.toys ]

you reassign the attribute here, so the list is never persistent

in Person.__init__ do: self.gadgets=PersistentList()

and then in growup:

person.gadgets.extend([ Gadget(toy) for toy in baby.toys ])

Regards, Bernd


>
> This creates the gadgets (one per each toy) but the Gadget.name
> attributes, altough being created, are not persisted.
>
> The @@edit and @@index views show the Gadget.name attributes are
> missing. I did not @@introspect the gadgets because I cannot  
> traverse to
> them.
>
>
> Is this the right place for a PersistentList? Using it in growup() and
> __init__ in place of FieldProperty does not make it work.
>
>
> _______________________________________________
> 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