strange path limitation for templatedir directive

Bug #562262 reported by Wichert Akkerman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
grok
Status tracked in 1.3
1.3
In Progress
Undecided
Unassigned

Bug Description

I want to organize my templates by type, but all in a single templates subdirectory. That means the paths to the templates relative to the python source look like templates/category/template.pt. Unfortunately the grok.templatedir directive does not allow this: it prevents any occurrence of os.path.sep in the pathname.

I can not think of a good reason for that restriction. It does not help with security since the person writing that directive can already write python code to do anything. Can that test be removed?

Revision history for this message
Wichert Akkerman (wichert) wrote :

I am not sure if this is related or warrants a separate bug: the grok.template directive does allow a path separator in its parameter, but the result is a somewhat nasty error on zope startup:

  File "/Users/wichert/Library/eggs/zope.configuration-3.6.0-py2.6.egg/zope/configuration/xmlconfig.py", line 649, in file
    context.execute_actions()
  File "/Users/wichert/Library/eggs/zope.configuration-3.6.0-py2.6.egg/zope/configuration/config.py", line 605, in execute_actions
    callable(*args, **kw)
  File "/Users/wichert/Library/eggs/grokcore.view-1.12.2-py2.6.egg/grokcore/view/meta/views.py", line 90, in checkTemplates
    has_render, has_no_render)
  File "/Users/wichert/Library/eggs/grokcore.view-1.12.2-py2.6.egg/grokcore/view/templatereg.py", line 135, in checkTemplates
    (component_name.title(), factory), factory)
ConfigurationExecutionError: <class 'martian.error.GrokError'>: View <class 'plonetheme.nuplone.skin.error.Error'> has no associated template or 'render' method.
  in:
  File "/Users/wichert/Work/syslab/euphorie/buildout/trunk/src/NuPlone/plonetheme/nuplone/configure.zcml", line 22.2-22.27
    <grok:grok package="." />

> /Users/wichert/Library/eggs/grokcore.view-1.12.2-py2.6.egg/grokcore/view/templatereg.py(135)checkTemplates()
-> (component_name.title(), factory), factory)

the relevant source is correct:

log=logging.getLogger(__name__)

grok.templatedir("templates")

class Error(grok.View):
    grok.context(Exception)
    grok.layer(NuPloneSkin)
    grok.name("index.html")
    grok.template("errors/generic")

    def update(self):
        self.exception=aq_inner(self.context)
        self.context=aq_parent(self)
        log.exception("Error at %r", self.context)

Revision history for this message
Vincent Fretin (vincent-fretin) wrote :

This restriction was not introduced for security reason, but to simplify the implementation of the new pending shared template registry which fix the UserWarning of unassociated templates.

I don't remember precisely why we did that, and maybe it is now unnecessary for the latest implementation of the shared template registry that lives in a branch. I can't tell.

In the meantime, instead of grok.template on the view, you can use:
template = grok.PageTemplateFile("templates/errors/generic.pt")

Revision history for this message
Wichert Akkerman (wichert) wrote :

grok.PageTemplateFile is not supported by five.pt (which had a very hard time to support grok views at all), so I can't use that.

Revision history for this message
Vincent Fretin (vincent-fretin) wrote :

Why it is not supported by five.pt?
five.grok.PageTemplateFile is actually five.grok.components.ZopeTwoPageTemplateFile
and
five.grok.PageTemplate is actually five.grok.components.ZopeTwoPageTemplate
so you should be able to use it.

Revision history for this message
Christian Klinger (cklinger) wrote :

Wichert ist this still a problem? We are working on merging the shared template branch in grokcore.view.

Revision history for this message
Wichert Akkerman (wichert) wrote :

Is there a grokcore.view release that is compatible with Plone 4 I can use to test this?

Revision history for this message
Jan-Jaap Driessen (janjaapdriessen) wrote :

We hope to have a release this week (nov 2010).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.