[Grok-dev] How do I use schema.Object?

Sylvain Viollon sylvain at infrae.com
Wed Mar 11 06:09:03 EDT 2009


Le Tue, 10 Mar 2009 15:00:02 +0100,
Sebastian Ware <sebastian at urbantalk.se> a écrit :

  Hello,

> I am having difficulties understanding how to render forms using  
> schema.Object. I have looked at various Zope 3 samples, but I am  
> failing to translate it to Grok. The doctests I have found aren't  
> helping me either.
> 
> Does anybody have some code that would successfully render and
> update an object field?
> 
> class IEvent(Interface):
>      show_in_calendar = schema.Bool(title=u"Show in calendar")
>      event_date = schema.Date(title=u'Date', required = False)
> 
> class INews(IStory):
>      event = schema.Object(title=u"Event", schema = IEvent)
> 
> 


  In non-Grok I do the following, but I think this should work with
  Grok as well:

   class Event(persistent.Persistent):

       def __init__(self, show_in_calendar, event_date):
           self.show_in_calendar = show_in_calendar
           self.event_date = event_date


   from zope.app.form import CustomWidgetFactory
   from zope.app.form.browser import ObjectWidget

   class NewsForm(grok.Form):

       form_fields = grok.Fields(INews)
       form_fields['event'].custom_widget = \
          CustomWidgetFactory(ObjectWidget, Event)


   Best regards,

   Sylvain

-- 
Sylvain Viollon -- Infrae
t +31 10 243 7051 -- http://infrae.com
Hoevestraat 10 3033GC Rotterdam -- The Netherlands
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20090311/e8451754/attachment.bin 


More information about the Grok-dev mailing list