[Zope3-Users] Re: browser:page and zope.formlib to replace browser:addform?

baiju m baiju.m.mail at gmail.com
Sun Dec 18 08:10:52 EST 2005


[Reply to my own mail]

>    Could anyone show a sample code to replace browser:addform
> with browser:page and zope.formlib?

I think I got the answer, please let me know if there is a better way to do it.

> Can I use zope.formlib.form.AddForm for this (its not documented)?
>

I created one view like this::

  from zope.formlib import form

  from websquare.interfaces import ICompany
  from websquare.square.company import Company

  class CompaniesView(form.AddForm):

      form_fields = form.Fields(ICompany)

      def create(self, data):
          company = Company()
          company.name = data['name']
          company.description = data['description']
          return company

Then registered like this::

  <page
      class=".companies.CompaniesView"
      name="AddCompany.html"
      permission="zope.ManageContent"
      for="zope.app.container.interfaces.IAdding"
      />

  <addMenuItem
      factory="websquare.square.company.Company"
      title="Company"
      description="Company"
      permission="zope.ManageContent"
      view="AddCompany.html"
      />


And this was my interface::

  class ICompany(IContainer):

      name = TextLine(
          title=_(u"Company Name"),
          description=_(u"Company Name"),
          default=u"",
          required=True)

      description = Text(
          title=_(u"Description"),
          description=_(u"A detailed description."),
          default=u"",
          required=False)

      def __setitem__(name, obj):
          pass

      __setitem__.precondition = ItemTypePrecondition(IAccount)


> Also how to use templates along with zope.formlib forms?

Hmm.. any help pointer?

Thanks,
Baiju M


More information about the Zope3-users mailing list