Re: [Zope3-Users] z3c.form - content add and edit forms

2008-07-16 Thread Stephan Richter
On Tuesday 15 July 2008, Martin Aspeli wrote:
> It's very common to have a content type that has both an add- and an
> edit form. If you have custom widget setup code and other logic, you
> often have to replicate this across both forms to make them consistent.

> Is there a standard/recommended z3c.form pattern to reduce duplication
> in this case?

Well, there is no framework way, but you can solve it via inheritance.

class ObjectForm(object):
  fields =...

  def updateWidgets(self):
...

class ObjectAddForm(ObjectForm, form.AddForm):
  pass

class ObjectEditForm(ObjectForm, form.EditForm):
  pass

I could also imagine that you could write a base class AddAndEditForm that has 
a mode with values ADD and EDIT that switches between the variances.

The difference between an add and edit form are only the button and their 
handlers and whether ignoreContext is set to true or false.

Regards,
Stephan
-- 
Stephan Richter
Web Software Design, Development and Training
Google me. "Zope Stephan Richter"
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] z3c.form - content add and edit forms

2008-07-15 Thread Martin Aspeli

Hi,

It's very common to have a content type that has both an add- and an
edit form. If you have custom widget setup code and other logic, you
often have to replicate this across both forms to make them consistent.

Is there a standard/recommended z3c.form pattern to reduce duplication
in this case?

Martin


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

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users