[Zope-dev] plone.z3cform: ExtensibleForm should not change groups class attribute

2009-08-14 Thread Gerhard Weis

Hi,

Sorry if this is the wrong list, but as plone.z3cform is in the 
zope-svn. I thought it may be Ok.


There is a small problem in plone.z3cform. The class 
plone.z3cform.fieldsets.extensible.ExtensibleForm has a class attribute 
groups, which is changed by the provided API methods. I don't think this 
is intentional, becuase it makes it hard to recreate additional 
instances of ExtensibleForm. The current behaviour works for forms which 
use already groups, but for forms, where the EtensibleForm creates new 
groups on the fly, it does not work. The attached patch fixes this. It 
also includes a small addition to the Readme, which failes without the 
patch applied, and runes clean with the patch applied.


cheers,

Gerhard


Index: plone/z3cform/fieldsets/utils.py
===
--- plone/z3cform/fieldsets/utils.py	(revision 102759)
+++ plone/z3cform/fieldsets/utils.py	(working copy)
@@ -22,7 +22,7 @@
 
 if source is None and group:
 source = GroupFactory(group, new_fields)
-form.groups.append(source)
+form.groups += (source, )
 else:
 if index is None or index = len(source.fields):
 source.fields += new_fields
@@ -114,4 +114,4 @@
 return group_factory[0]
 else:
 return None
-return form
\ No newline at end of file
+return form
Index: plone/z3cform/fieldsets/extensible.py
===
--- plone/z3cform/fieldsets/extensible.py	(revision 102759)
+++ plone/z3cform/fieldsets/extensible.py	(working copy)
@@ -51,7 +51,7 @@
 class ExtensibleForm(GroupForm):
 implements(IExtensibleForm)
 
-groups = []
+groups = ()
 default_fieldset_label = _(uDefault)
 
 def update(self):
@@ -61,4 +61,4 @@
 def updateFields(self):
 extenders = getAdapters((self.context, self.request, self), IFormExtender)
 for name, extender in sorted(extenders, key=order_key):
-extender.update()
\ No newline at end of file
+extender.update()
Index: plone/z3cform/fieldsets/README.txt
===
--- plone/z3cform/fieldsets/README.txt	(revision 102759)
+++ plone/z3cform/fieldsets/README.txt	(working copy)
@@ -131,6 +131,13 @@
form.groups # doctest: +ELLIPSIS
   (plone.z3cform.fieldsets.group.Group object at ...,)
 
+Let's recreate the form and see if it still works:
+
+   form = TestForm(context, request)
+   form.update()
+   form.groups # doctest: +ELLIPSIS
+  (plone.z3cform.fieldsets.group.Group object at ...,)
+
 Note that the created group is of a subtype of the standard z3c.form group,
 which has got support for a separate label and description as well as a 
 canonical name.
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] plone.z3cform: ExtensibleForm should not change groups class attribute

2009-08-14 Thread Martin Aspeli
Gerhard Weis wrote:
 Hi,
 
 Sorry if this is the wrong list, but as plone.z3cform is in the 
 zope-svn. I thought it may be Ok.
 
 There is a small problem in plone.z3cform. The class 
 plone.z3cform.fieldsets.extensible.ExtensibleForm has a class attribute 
 groups, which is changed by the provided API methods. I don't think this 
 is intentional, becuase it makes it hard to recreate additional 
 instances of ExtensibleForm. The current behaviour works for forms which 
 use already groups, but for forms, where the EtensibleForm creates new 
 groups on the fly, it does not work. The attached patch fixes this. It 
 also includes a small addition to the Readme, which failes without the 
 patch applied, and runes clean with the patch applied.

Modify the class variable is certainly not intentional. It is supposed 
to copy it to an instance variable.

Martin

-- 
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )