[Grok-dev] Re: Fields inner class support removed in branch

Jan-Wijbrand Kolman janwijbrand at gmail.com
Thu Sep 13 13:44:48 EDT 2007


Luciano Ramalho wrote:
> ################################
> class IMammoth(Interface):
>     name = schema.TextLine(title=u"Name")
>     size = schema.TextLine(title=u"Size", default=u"Quite normal")
> 
> class Mammoth(grok.Model):
>     implements(IMammoth)
> 
>     name = None
>     size = None
> ################################
> 
> The test fails if the size attribute is not defined in the Mammoth
> class, and to define it we must set an initial value, of course. But
> IMammoth already declares an initial value.
> 
> This is an example of the DRY violation I mentioned before. It's not a
> big deal, but it's a wart, IMHO.
> 
> I agree that my initial proposal of making ModelGrokker set the fields
> declared in the interface was too magic, but I'd like to hear comments
> on the alternative proposal of having a grok.implements declaration to
> do that.

Zope already has a way of doing this:

   from zope.interface import Interface, implements
   from zope import schema
   from zope.schema.fieldproperty import FieldProperty

   class IMammoth(Interface):
     name = schema.TextLine(title=u"Name")
     size = schema.TextLine(title=u"Size", default=u"Quite normal")

   class Mammoth(grok.Model):
       implements(IMammoth)
       name = FieldProperty(IMammoth['name'])
       size = FieldProperty(IMammoth['size'])

kind regards,
jw



More information about the Grok-dev mailing list