[z3-five] Formlib custom template - AttributeError: debug.

Maciej Wisniowski maciej.wisniowski at coig.katowice.pl
Thu Feb 15 23:57:43 CET 2007


Hi

I want to create custom template for Formlib based form.
My code is at the bottom of this post. Zope 2.9.6, Five 1.4.2
In general I tried to define template with:

template = namedtemplate.NamedTemplate('mytemp')
template = ViewPageTemplateFile('mytemp.pt')

In both cases, when I try to visit @@mypage.html I get:

Traceback (innermost last):
  Module ZPublisher.Publish, line 115, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 41, in call_object
  Module zope.formlib.form, line 758, in __call__
  Module zope.formlib.form, line 752, in render
  Module zope.app.pagetemplate.viewpagetemplatefile, line 83, in __call__
  Module zope.app.pagetemplate.viewpagetemplatefile, line 47, in __call__
  Module ZPublisher.HTTPRequest, line 1219, in __getattr__
AttributeError: debug

mytemp.pt is basically a copy of pageform.pt from formlib. Without
custom template assignment everything works.

What is wrong? Code is run at Plone but it's plain five with
formlib here. Possibly lack of acquisition wrapper?


File: browser/views.py:
-----------------------
from zope.app.i18n import ZopeMessageFactory as _
from zope.formlib import form
from Products.Five.formlib import formbase
from Products.myproduct import interfaces
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.formlib import namedtemplate
from zope.formlib import interfaces as form_interfaces

class StartForm(formbase.EditForm):
    form_fields = form.FormFields(interfaces.IInter).select('blablabla')

    template = namedtemplate.NamedTemplate('mytemp')  # option 1
    #template = ViewPageTemplateFile('mytemp.pt')     # option 2

    def __init__(self, *args, **kwargs):
        formbase.EditForm.__init__(self, *args, **kwargs)

mytemp_page_template = namedtemplate.NamedTemplateImplementation(
    ViewPageTemplateFile('mytemp.pt'), form_interfaces.IPageForm)


File: browser/configure.zcml:
----------------------------

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
    xmlns:five="http://namespaces.zope.org/five">

  <adapter factory=".views.mytemp_page_template" name="mytemp" />

  <browser:page
      for="..interfaces.IInter"
      name="mypage.html"
      class=".views.StartForm"
      permission="zope2.View"
      />
</configure>


-- 
Maciej Wisniowski


More information about the z3-five mailing list