[Checkins] SVN: grok/branches/luciano-fields-class-removal/ removed
support for the fields inner class schema declaration idiom
Luciano Ramalho
luciano at ramalho.org
Thu Sep 13 11:26:01 EDT 2007
Log message for revision 79616:
removed support for the fields inner class schema declaration idiom
formlib.py
- deleted the get_context_schema_fields function
- removed the call to it from the get_auto_fields function
meta.py
- deleted ModelGrokker, ContainerGrokker and LocalUtilityGrokker
tests/form/form.py
- deleted initial tests showing default values
- removed fields inner class from the Mammoth model
- added IMammoth interface to declare the schema for the Mammoth model
tests/form/schemaform.py
- removed tests and sample model showing combination of schemas from
interface and inner class
ftests/form/addform.py
- removed fields inner class from the Mammoth model
- added IMammoth interface to declare the schema for the Mammoth model
ftests/form/actions.py, ftests/form/update.py, ftests/form/form.py
- removed fields inner class from the Mammoth model
- added IMammoth interface to declare the schema for the Mammoth model
- added class attributes to provide initial values to Mammoth instance attrs
ftests/form/editform_applydata_classfields.py
- changed initial explanation about how the schema is defined in the example
- removed fields inner class from the Mammoth model
- added IMammoth interface to declare the schema for the Mammoth model
Changed:
A grok/branches/luciano-fields-class-removal/
U grok/branches/luciano-fields-class-removal/src/grok/formlib.py
U grok/branches/luciano-fields-class-removal/src/grok/ftests/form/actions.py
U grok/branches/luciano-fields-class-removal/src/grok/ftests/form/addform.py
U grok/branches/luciano-fields-class-removal/src/grok/ftests/form/editform_applydata_classfields.py
U grok/branches/luciano-fields-class-removal/src/grok/ftests/form/form.py
U grok/branches/luciano-fields-class-removal/src/grok/ftests/form/update.py
U grok/branches/luciano-fields-class-removal/src/grok/meta.py
U grok/branches/luciano-fields-class-removal/src/grok/tests/form/form.py
U grok/branches/luciano-fields-class-removal/src/grok/tests/form/schemaform.py
-=-
Copied: grok/branches/luciano-fields-class-removal (from rev 79607, grok/trunk)
Modified: grok/branches/luciano-fields-class-removal/src/grok/formlib.py
===================================================================
--- grok/trunk/src/grok/formlib.py 2007-09-12 21:55:28 UTC (rev 79607)
+++ grok/branches/luciano-fields-class-removal/src/grok/formlib.py 2007-09-13 15:26:00 UTC (rev 79616)
@@ -27,27 +27,6 @@
fields.sort(key=lambda field: field.order)
return form.Fields(*(args + tuple(fields)), **kw)
-def get_context_schema_fields(context):
- """Get the schema fields for a context object.
- """
- fields = []
- fields_class = getattr(context, 'fields', None)
- # bail out if there is no fields attribute at all
- if fields_class is None:
- return fields
- # bail out if there's a fields attribute but it isn't an old-style class
- if type(fields_class) != types.ClassType:
- return fields
- # get the fields from the class
- for name in dir(fields_class):
- field = getattr(fields_class, name)
- if IField.providedBy(field):
- if not getattr(field, '__name__', None):
- field.__name__ = name
- fields.append(field)
- fields.sort(key=lambda field: field.order)
- return fields
-
def get_auto_fields(context):
"""Get the form fields for context.
"""
@@ -57,8 +36,7 @@
# if we have a non-interface context,
# we're autogenerating them from any model-specific
# fields along with any schemas defined by the context
- fields = form.Fields(*get_context_schema_fields(context))
- fields += form.Fields(*most_specialized_interfaces(context))
+ fields = form.Fields(*most_specialized_interfaces(context))
# we pull in this field by default, but we don't want it in our form
fields = fields.omit('__name__')
return fields
Modified: grok/branches/luciano-fields-class-removal/src/grok/ftests/form/actions.py
===================================================================
--- grok/trunk/src/grok/ftests/form/actions.py 2007-09-12 21:55:28 UTC (rev 79607)
+++ grok/branches/luciano-fields-class-removal/src/grok/ftests/form/actions.py 2007-09-13 15:26:00 UTC (rev 79616)
@@ -45,11 +45,17 @@
"""
import grok
from zope import schema
+from zope.interface import Interface, implements
+class IMammoth(Interface):
+ name = schema.TextLine(title=u"Name")
+ size = schema.TextLine(title=u"Size", default=u"Quite normal")
+
class Mammoth(grok.Model):
- class fields:
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size")
+ implements(IMammoth)
+
+ name = None
+ size = None
class Edit(grok.EditForm):
@grok.action("Apply")
Modified: grok/branches/luciano-fields-class-removal/src/grok/ftests/form/addform.py
===================================================================
--- grok/trunk/src/grok/ftests/form/addform.py 2007-09-12 21:55:28 UTC (rev 79607)
+++ grok/branches/luciano-fields-class-removal/src/grok/ftests/form/addform.py 2007-09-13 15:26:00 UTC (rev 79616)
@@ -27,14 +27,17 @@
"""
import grok
from zope import schema
+from zope.interface import Interface, implements
class Zoo(grok.Container):
pass
+class IMammoth(Interface):
+ name = schema.TextLine(title=u"Name")
+ size = schema.TextLine(title=u"Size", default=u"Quite normal")
+
class Mammoth(grok.Model):
- class fields:
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size")
+ implements(IMammoth)
def __init__(self, name='', size=''):
self.name = name
Modified: grok/branches/luciano-fields-class-removal/src/grok/ftests/form/editform_applydata_classfields.py
===================================================================
--- grok/trunk/src/grok/ftests/form/editform_applydata_classfields.py 2007-09-12 21:55:28 UTC (rev 79607)
+++ grok/branches/luciano-fields-class-removal/src/grok/ftests/form/editform_applydata_classfields.py 2007-09-13 15:26:00 UTC (rev 79616)
@@ -3,8 +3,9 @@
the object. Update mode means that only those fields are changed on
the object that need to be changed.
-This is essentially the same narrative as 'editform_applydata'. Here
-we test the whole procedure on fields defined on the model class:
+This is essentially the same narrative as 'editform_applydata'. Here we
+test the whole procedure on fields on the interface implemented by the
+model class:
>>> getRootFolder()["manfred"] = mammoth = Mammoth()
>>> mammoth.name = 'Manfred the Mammoth'
@@ -54,13 +55,15 @@
"""
import grok
from zope import schema
+from zope.interface import Interface, implements
+class IMammoth(Interface):
+ name = schema.TextLine(title=u"Name")
+ size = schema.TextLine(title=u"Size", default=u"Quite normal")
class Mammoth(grok.Model):
- class fields:
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size")
-
+ implements(IMammoth)
+
class Edit(grok.EditForm):
pass
Modified: grok/branches/luciano-fields-class-removal/src/grok/ftests/form/form.py
===================================================================
--- grok/trunk/src/grok/ftests/form/form.py 2007-09-12 21:55:28 UTC (rev 79607)
+++ grok/branches/luciano-fields-class-removal/src/grok/ftests/form/form.py 2007-09-13 15:26:00 UTC (rev 79616)
@@ -28,11 +28,17 @@
"""
import grok
from zope import schema
+from zope.interface import Interface, implements
+class IMammoth(Interface):
+ name = schema.TextLine(title=u"Name")
+ size = schema.TextLine(title=u"Size", default=u"Quite normal")
+
class Mammoth(grok.Model):
- class fields:
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size")
+ implements(IMammoth)
+
+ name = None
+ size = None
class Edit(grok.EditForm):
pass
Modified: grok/branches/luciano-fields-class-removal/src/grok/ftests/form/update.py
===================================================================
--- grok/trunk/src/grok/ftests/form/update.py 2007-09-12 21:55:28 UTC (rev 79607)
+++ grok/branches/luciano-fields-class-removal/src/grok/ftests/form/update.py 2007-09-13 15:26:00 UTC (rev 79616)
@@ -45,9 +45,15 @@
import grok
from zope import schema
+from zope.interface import Interface, implements
+
+class IMammoth(Interface):
+ name = schema.TextLine(title=u"Name")
+
class Mammoth(grok.Model):
- class fields:
- name = schema.TextLine(title=u"Name", default=u'Manfred')
+ implements(IMammoth)
+
+ name = u'Manfred'
class Index(grok.View):
Modified: grok/branches/luciano-fields-class-removal/src/grok/meta.py
===================================================================
--- grok/trunk/src/grok/meta.py 2007-09-12 21:55:28 UTC (rev 79607)
+++ grok/branches/luciano-fields-class-removal/src/grok/meta.py 2007-09-13 15:26:00 UTC (rev 79616)
@@ -49,23 +49,6 @@
from grok.util import check_adapts, get_default_permission, make_checker
-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
-
-
-class ContainerGrokker(ModelGrokker):
- component_class = grok.Container
-
-
-class LocalUtilityGrokker(ModelGrokker):
- component_class = grok.LocalUtility
-
-
class AdapterGrokker(martian.ClassGrokker):
component_class = grok.Adapter
Modified: grok/branches/luciano-fields-class-removal/src/grok/tests/form/form.py
===================================================================
--- grok/trunk/src/grok/tests/form/form.py 2007-09-12 21:55:28 UTC (rev 79607)
+++ grok/branches/luciano-fields-class-removal/src/grok/tests/form/form.py 2007-09-13 15:26:00 UTC (rev 79616)
@@ -1,32 +1,10 @@
"""
-A grok.Model may contain a nested class named 'fields'. All attributes of
-'fields' that provide IField will cause attributes of the same name to appear on
-the grok.Model:
-
- >>> grok.grok(__name__)
- >>> manfred = Mammoth()
- >>> print manfred.name
- None
- >>> print manfred.size
- Quite normal
- >>> manfred.somethingelse
- Traceback (most recent call last):
- ...
- AttributeError: 'Mammoth' object has no attribute 'somethingelse'
-
-If the 'fields' attribute is not an old-style class, it will not trigger any
-attribute generation:
-
- >>> cave = Cave()
- >>> cave.ignored
- Traceback (most recent call last):
- ...
- AttributeError: 'Cave' object has no attribute 'ignored'
-
A grok.EditForm is a special grok.View that renders an edit form.
>>> from zope import component
>>> from zope.publisher.browser import TestRequest
+ >>> grok.grok(__name__)
+ >>> manfred = Mammoth()
>>> request = TestRequest()
>>> view = component.getMultiAdapter((manfred, request), name='edit')
>>> len(view.form_fields)
@@ -46,24 +24,26 @@
"""
import grok
from zope import schema
+from zope.interface import Interface, implements
+class IMammoth(Interface):
+ name = schema.TextLine(title=u"Name")
+ size = schema.TextLine(title=u"Size", default=u"Quite normal")
+
class Mammoth(grok.Model):
- class fields:
- name = schema.TextLine(title=u"Name")
- size = schema.TextLine(title=u"Size", default=u"Quite normal")
- somethingelse = None
+ implements(IMammoth)
class Edit(grok.EditForm):
grok.context(Mammoth)
-class Cave(grok.Model):
- fields = ['ignored']
+class IDifferentMammoth(Interface):
+ # mind the different order of fields
+ size = schema.TextLine(title=u"Size", default=u"Quite normal")
+ name = schema.TextLine(title=u"Name")
class DifferentMammoth(grok.Model):
- class fields:
- # mind the different order of fields
- size = schema.TextLine(title=u"Size", default=u"Quite normal")
- name = schema.TextLine(title=u"Name")
+ implements(IDifferentMammoth)
class EditDifferent(grok.EditForm):
grok.context(DifferentMammoth)
+
Modified: grok/branches/luciano-fields-class-removal/src/grok/tests/form/schemaform.py
===================================================================
--- grok/trunk/src/grok/tests/form/schemaform.py 2007-09-12 21:55:28 UTC (rev 79607)
+++ grok/branches/luciano-fields-class-removal/src/grok/tests/form/schemaform.py 2007-09-13 15:26:00 UTC (rev 79616)
@@ -23,15 +23,6 @@
>>> [w.__name__ for w in view.form_fields]
['can_talk', 'name', 'size']
-Schema fields and model level fields are combined:
-
- >>> view = component.getMultiAdapter(
- ... (AnotherMammoth(), request), name='edit3')
- >>> len(view.form_fields)
- 3
- >>> [w.__name__ for w in view.form_fields]
- ['can_talk', 'name', 'size']
-
If the context is an interface instead of a model directly, the fields
will be retrieved from that interface, and that interface only:
@@ -65,13 +56,6 @@
class Edit2(grok.EditForm):
grok.context(Manfred)
-class AnotherMammoth(Mammoth):
- class fields:
- can_talk = schema.Bool(title=u'Can talk', default=False)
-
-class Edit3(grok.EditForm):
- grok.context(AnotherMammoth)
-
class IYetAnotherMammoth(interface.Interface):
alpha = schema.TextLine(title=u'alpha')
beta = schema.TextLine(title=u'beta')
More information about the Checkins
mailing list