[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/form/browser/metaconfigure.py Added conditional use of class interfaces to configure widget attributes ('widget' directive). In some cases, a widget class can be a function (used in double-dispatch patterns, e.g. vocab widgets).

Garrett Smith garrett at mojave-corp.com
Thu Aug 5 19:47:56 EDT 2004


Log message for revision 26932:
  Added conditional use of class interfaces to configure widget attributes ('widget' directive). In some cases, a widget class can be a function (used in double-dispatch patterns, e.g. vocab widgets).
  
  In cases where a function is specified as the 'class' attribute, additional widget paramters (e.g. width, height, etc.) are silently ignored.


Changed:
  U   Zope3/trunk/src/zope/app/form/browser/metaconfigure.py


-=-
Modified: Zope3/trunk/src/zope/app/form/browser/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/metaconfigure.py	2004-08-05 23:43:16 UTC (rev 26931)
+++ Zope3/trunk/src/zope/app/form/browser/metaconfigure.py	2004-08-05 23:47:56 UTC (rev 26932)
@@ -64,16 +64,16 @@
 
     def widget(self, _context, field, class_, **kw):
         attrs = kw
-        ifaces = implementedBy(class_)
         # Try to do better than accepting the string value by looking through
         # the interfaces and trying to find the field, so that we can use
         # 'fromUnicode()' 
-        for name, value in kw.items():
-            for iface in ifaces:
-                if name in iface:
-                    attrs[name] = iface[name].fromUnicode(value)
-                    break
-
+        if isinstance(class_, type):
+            ifaces = implementedBy(class_)
+            for name, value in kw.items():
+                for iface in ifaces:
+                    if name in iface:
+                        attrs[name] = iface[name].fromUnicode(value)
+                        break
         self._widgets[field+'_widget'] = CustomWidgetFactory(class_, **attrs) 
 
     def _processWidgets(self):



More information about the Zope3-Checkins mailing list