[Grok-dev] Problem with grok.AddForm, grok.Adapter and widgets

Hannes hannes.flocke at gmx.li
Fri Jan 29 15:01:13 EST 2010


Hi Martijn,

thanks for the fast reply!


--------------- Here's the version module ----------------------

import grok
from interfaces import IVersion

class Version(grok.Model):
""" Persistent Version """
grok.implements(IVersion)

def __init__(self, major, minor, v1, v2, v3):
super(Version, self).__init__()
self.major = major
self.minor = minor
self.v1 = v1
self.v2 = v2
self.v3 = v3


class Index(grok.DisplayForm):
""" Knows how to display a version """


-------------------------------------------------------------------------------------

> Hannes wrote:I've some problem with a schema.Object field when I wanna use grok.AddForm.
>
> Seems like I've to write an Adapter class...?, but unfortunately I don't 
> know how.... :-(
>
>   
>
> Hm, it works for edit forms, right? I guess the tricky bit is that you 
> need objects of the right type to be constructed with an add form. With 
> an edit form you don't care, you just need to edit the object according 
> to its schema, whatever object it may be.
>
> I think I've made it work in the past when I *don't* provide a custom 
> object to create, i.e. I have no Version or Product, but just rely on 
> the default ObjectWidget to create a default one for me.
>
> Could you show your Version or Product implementation? It looks to me 
> like these expect multiple arguments to create them. If you changed them 
> to take no arguments (or created factory functions to do that), 
> ObjectWidget should be able to create them (call self.factory()). 
> Looking at the ObjectWidget implementation it should then set the 
> attributes from your schema directly.
>
> Regards,
>
> Martijn
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/grok-dev/attachments/20100129/22fc9e58/attachment.html 


More information about the Grok-dev mailing list