[Checkins] SVN: z3c.form/trunk/ Fix an ugly bug with buttons and the button manager.

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Jul 6 23:57:23 EDT 2007


Log message for revision 77552:
  Fix an ugly bug with buttons and the button manager.
  

Changed:
  U   z3c.form/trunk/CHANGES.txt
  U   z3c.form/trunk/src/z3c/form/button.py
  U   z3c.form/trunk/src/z3c/form/button.txt

-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt	2007-07-07 03:18:52 UTC (rev 77551)
+++ z3c.form/trunk/CHANGES.txt	2007-07-07 03:57:20 UTC (rev 77552)
@@ -36,6 +36,10 @@
 
 - Bug/Feature: Correctly create labels for radio button choices.
 
+- Bug: Buttons did not honor the name given by the schema, if created within
+  one, because we were too anxious to give buttons a name. Now name assignment
+  is delayed until the button is added to the button manager.
+
 - Bug: Button actions were never updated in the actions manager.
 
 - Bug: Added tests for textarea widget.

Modified: z3c.form/trunk/src/z3c/form/button.py
===================================================================
--- z3c.form/trunk/src/z3c/form/button.py	2007-07-07 03:18:52 UTC (rev 77551)
+++ z3c.form/trunk/src/z3c/form/button.py	2007-07-07 03:57:20 UTC (rev 77552)
@@ -55,9 +55,6 @@
         self.condition = kwargs.pop('condition', None)
         # Initialize the button
         super(Button, self).__init__(*args, **kwargs)
-        # Make sure the button has a name by the time it is initialized.
-        if self.__name__ is '':
-            self.__name__ = util.createId(self.title)
 
     def __repr__(self):
         return '<%s %r %r>' %(
@@ -80,6 +77,8 @@
             elif self.managerInterface.providedBy(arg):
                 buttons += arg.items()
             elif interfaces.IButton.providedBy(arg):
+                if not arg.__name__:
+                    arg.__name__ = util.createId(arg.title)
                 buttons.append((arg.__name__, arg))
             else:
                 raise TypeError("Unrecognized argument type", arg)

Modified: z3c.form/trunk/src/z3c/form/button.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/button.txt	2007-07-07 03:18:52 UTC (rev 77551)
+++ z3c.form/trunk/src/z3c/form/button.txt	2007-07-07 03:57:20 UTC (rev 77552)
@@ -215,15 +215,31 @@
   >>> button.Button(__name__='apply').__name__
   'apply'
 
-If no name is specified, the name will be assigned to the button. When it can
-it uses the title, otherwise a hexadecimal string is created:
+If no name is specified, the button will not have a name immediately, ...
 
   >>> button.Button(title=u'Apply').__name__
+  ''
+
+because if the button is created within an interface, the name is assigned
+later:
+
+  >>> class IActions(zope.interface.Interface):
+  ...    apply = button.Button(title=u'Apply')
+
+  >>> IActions['apply'].__name__
   'apply'
-  >>> button.Button(title=u'Apply and more').__name__
+
+However, once the button is added to a button manager, a name will be
+assigned:
+
+  >>> btns = button.Buttons(button.Button(title=u'Apply'))
+  >>> btns['apply'].__name__
+  'apply'
+
+  >>> btns = button.Buttons(button.Button(title=u'Apply and more'))
+  >>> btns['4170706c7920616e64206d6f7265'].__name__
   '4170706c7920616e64206d6f7265'
 
-
 This declaration behaves identical to the one before:
 
   >>> form = Form()
@@ -474,8 +490,8 @@
 
 Now all special buttons should use that handler:
 
-  >>> button1 = SpecialButton(title=u'Button 1')
-  >>> button2 = SpecialButton(title=u'Button 2')
+  >>> button1 = SpecialButton(name='button1', title=u'Button 1')
+  >>> button2 = SpecialButton(name='button2', title=u'Button 2')
 
   >>> form.handlers.getHandler(button1)(form, None)
   'Special button action'
@@ -500,7 +516,7 @@
 
   >>> handlers2 = button.Handlers()
 
-  >>> button3 = SpecialButton(title=u'Button 3')
+  >>> button3 = SpecialButton(name='button3', title=u'Button 3')
   >>> handlers2.addHandler(
   ...     button3, button.Handler(button3, None))
 
@@ -508,8 +524,8 @@
   <Handlers
       [<Handler for <Button 'apply' u'Apply'>>,
        <Handler for <class 'SpecialButton'>>,
-       <Handler for <SpecialButton '427574746f6e2031' u'Button 1'>>,
-       <Handler for <SpecialButton '427574746f6e2033' u'Button 3'>>]>
+       <Handler for <SpecialButton 'button1' u'Button 1'>>,
+       <Handler for <SpecialButton 'button3' u'Button 3'>>]>
 
 However, adding other components is not supported:
 



More information about the Checkins mailing list