[Zope3-Users] z3c.form and subforms in an AddForm?

gnosis mats at ronin-group.org
Fri Jun 15 13:52:24 EDT 2007


I've been trying out the new z3c form package and like what I see.  I am
having problems getting a subform in an AddForm though.  The subform.txt
covers EditForms where you have a context object to work on, in an AddForm
the context is the underlying IContainer.

Here is what I have, using formdemo examples as the basis.  Any help on
getting this to work is greatly appreciated.

IRestaurant with address attribute using schema.Object holding an IAddress.

browser/restaurant.py

class RestaurantAddForm(AddFormLayoutSupport, form.AddForm):
    """Add form"""
    
    template = None
    layout = None
    contentName = None
    label = u'Add Restaurant'
    
    fields = field.Fields(IRestaurant).omit('address')
    
    def update(self):
        self.address = AddressAddForm(self.context.address, self.request) ##
<---- Problem area
        self.address.update()
        super(RestaurantAddForm, self).update()
    
    def create(self, data):
        r = Restaurant()
        r.name = data['name']
        r.description = data['description']
        r.address = data['address']
        return r
    
    def add(self, object):
        self._name = object.name
        self.context[self._name] = object
        return object
    
    def nextURL(self):
        return absoluteURL(self.context[self._name], self.request)


browser/address.py

class AddressAddForm(AddFormLayoutSupport, form.AddForm):
    template = None
    layout = None
    contentName = None
    label = u'Address'
    
    fields = field.Fields(IAddress)
    prefix = u'address'

browser/configure.zcml

  <!-- Restaurant Add Form -->
  <z3c:pagelet
    name="addRestaurant.html"
    for="zope.app.folder.interfaces.IFolder"
    class=".restaurant.RestaurantAddForm"
    layer="metrod.app.layer.IMetroDBrowserLayer"
    permission="zope.Public" />
  
  <z3c:template
    template="restaurant.pt"
    for=".restaurant.RestaurantAddForm"
    layer="metrod.app.layer.IMetroDBrowserLayer" />

   <!-- Address Add Form -->  
  <z3c:pagelet
    name="addAddress.html"
    for="metrod.restaurant.interfaces.IAddress"
    class=".address.AddressAddForm"
    layer="metrod.app.layer.IMetroDBrowserLayer"
    permission="zope.Public" />
    
  <z3c:template
    template="address.pt"
    for=".address.AddressAddForm"
    layer="metrod.app.layer.IMetroDBrowserLayer" />
-- 
View this message in context: http://www.nabble.com/z3c.form-and-subforms-in-an-AddForm--tf3929436.html#a11144644
Sent from the Zope3 - users mailing list archive at Nabble.com.



More information about the Zope3-users mailing list