[Checkins] SVN: grok/trunk/src/grok/ test that nested attribute 'fields' only does something if it is an old-style class

Wolfgang Schnerring wosc at wosc.de
Thu Oct 19 08:27:13 EDT 2006


Log message for revision 70808:
  test that nested attribute 'fields' only does something if it is an old-style class

Changed:
  U   grok/trunk/src/grok/components.py
  U   grok/trunk/src/grok/tests/form/form.py

-=-
Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py	2006-10-19 12:15:41 UTC (rev 70807)
+++ grok/trunk/src/grok/components.py	2006-10-19 12:27:12 UTC (rev 70808)
@@ -15,6 +15,8 @@
 """
 
 import persistent
+import types
+
 from zope import component
 from zope import interface
 from zope import schema
@@ -204,10 +206,11 @@
     fields = []
     fields_class = getattr(obj, 'fields', None)
     if fields_class is not None:
-        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)
+        if type(fields_class) == types.ClassType:
+            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)
     return fields

Modified: grok/trunk/src/grok/tests/form/form.py
===================================================================
--- grok/trunk/src/grok/tests/form/form.py	2006-10-19 12:15:41 UTC (rev 70807)
+++ grok/trunk/src/grok/tests/form/form.py	2006-10-19 12:27:12 UTC (rev 70808)
@@ -14,6 +14,16 @@
     ...
   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.
 
 We need to set up the default formlib template first, because even though we
@@ -41,5 +51,10 @@
         size = schema.TextLine(title=u"Size", default=u"Quite normal")
         somethingelse = None
 
+grok.context(Mammoth)
+
 class Edit(grok.EditForm):
     pass
+
+class Cave(grok.Model):
+    fields = ['ignored']



More information about the Checkins mailing list