[Grok-dev] overridding default form templates
Joshua Immanuel
josh at hipro.co.in
Tue Sep 11 13:20:31 UTC 2012
Hello,
I was trying to override the default form template for grok.AddForm
using grok.PageTemplateFile
class AddUser(grok.AddForm):
grok.context(UserFolder)
grok.name('add_user')
form_fields = grok.AutoFields(User)
label = "Add new user"
template = grok.PageTemplateFile(
os.path.join('form_templates','dash_form.pt'))
@grok.action('Add user')
def add(self, **data):
...
return self.redirect(self.url(self.context))
In the overridden template file I was using a macro to fill a slot with
form contents.
<div xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro=
"path:context/@@dashboard/template/macros/dashboard_layout">
<tal:block metal:fill-slot="dashboard_content">
<form action="." tal:attributes="action request/URL"
method="post" class="edit-form"
enctype="multipart/form-data">
...
</tal:block>
</div>
But, while rendering this page I get the following traceback
> File "/opt/buildout/eggs/zope.publisher-3.12.6-py2.7.egg/zope/publisher/publish.py", line 132, in publish
> result = publication.callObject(request, obj)
> File "/opt/buildout/eggs/grokcore.view-2.7-py2.7.egg/grokcore/view/publication.py", line 56, in callObject
> return super(ZopePublicationSansProxy, self).callObject(request, ob)
> File "/opt/buildout/eggs/zope.app.publication-3.13.1-py2.7.egg/zope/app/publication/zopepublication.py", line 207, in callObject
> return mapply(ob, request.getPositionalArguments(), request)
> File "/opt/buildout/eggs/zope.publisher-3.12.6-py2.7.egg/zope/publisher/publish.py", line 107, in mapply
> return debug_call(obj, args)
> File "/opt/buildout/eggs/zope.publisher-3.12.6-py2.7.egg/zope/publisher/publish.py", line 113, in debug_call
> return obj(*args)
> File "/opt/buildout/eggs/grokcore.formlib-1.9-py2.7.egg/grokcore/formlib/components.py", line 91, in __call__
> return self.render()
> File "/opt/buildout/eggs/grokcore.formlib-1.9-py2.7.egg/grokcore/formlib/components.py", line 74, in render
> self.form_result = self._render_template()
> File "/opt/buildout/eggs/grokcore.view-2.7-py2.7.egg/grokcore/view/components.py", line 144, in _render_template
> return self.template.render(self)
> File "/opt/buildout/eggs/grokcore.view-2.7-py2.7.egg/grokcore/view/components.py", line 363, in render
> return template.pt_render(namespace)
> File "/opt/buildout/eggs/zope.pagetemplate-3.5.2-py2.7.egg/zope/pagetemplate/pagetemplate.py", line 113, in pt_render
> strictinsert=0, sourceAnnotations=sourceAnnotations)()
> File "/opt/buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 271, in __call__
> self.interpret(self.program)
> File "/opt/buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 343, in interpret
> handlers[opcode](self, args)
> File "/opt/buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/talinterpreter.py", line 871, in do_useMacro
> if not isCurrentVersion(macro):
> File "/opt/buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/taldefs.py", line 151, in isCurrentVersion
> version = getProgramVersion(program)
> File "/opt/buildout/eggs/zope.tal-3.5.2-py2.7.egg/zope/tal/taldefs.py", line 172, in getProgramVersion
> if (len(program) >= 2 and
> TypeError: object of type 'Macro' has no len()
Am I missing something? Please guide me.
Regards
--
Joshua Immanuel
HiPro IT Solutions Private Limited
http://hipro.co.in
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://mail.zope.org/pipermail/grok-dev/attachments/20120911/3c6c58b0/attachment.sig>
More information about the Grok-dev
mailing list