[Grok-dev] Re: A plan for removing the fields inner class support
Luciano Ramalho
luciano at ramalho.org
Wed Sep 12 22:18:27 EDT 2007
OK, things are not going to be as simple as I described...
The ModelGrok.grok method can't be simply removed, even though the
only thing it does is what we don't want it do do anymore.
class ModelGrokker(martian.ClassGrokker):
component_class = grok.Model
def grok(self, name, factory, context, module_info, templates):
for field in formlib.get_context_schema_fields(factory):
setattr(factory, field.__name__, field.default)
return True
The reason is that martian.ComponentGrokkerBase.grok raises
NotImplementedError, and ModelGrokker is the first
ComponentGrokkerBase subclass that actually does implement the grok
method.
Then I started reading some of the tests which use the fields inner
class, and realized we may want the ModelGrokker to do something for
us after all.
What if the ModelGrokker created attributes in our model class from
the attributes declared in an interface which our model promises to
implement?
So, for instance, this test from tests/form/form.py would pass:
######################
>>> grok.grok(__name__)
>>> manfred = Mammoth()
>>> print manfred.name
None
>>> print manfred.size
Quite normal
######################
Provided that Mammoth was written like this:
######################
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)
######################
What do you think?
Regards,
Luciano
More information about the Grok-dev
mailing list