grok doesn't like explicit grok.template() if it matches implicitly found template

Reported by Ivo van der Wijk on 2008-06-24
2
Affects Status Importance Assigned to Milestone
grok
Medium
Jan Wijbrand Kolman
1.0
Medium
Jan Wijbrand Kolman
1.1
Medium
Martijn Faassen

Bug Description

Consider

class AppCSS(grok.Viewlet):
    grok.template("appcss.pt")
    grok.viewletmanager(Head)
    grok.context(ISomeTheme)

grok will complain with the error:

  File "/Users/ivo/.buildout/eggs/tmpaT3RbW/grok-0.12.1-py2.4.egg/grok/templatereg.py", line 101, in checkTemplates
zope.configuration.config.ConfigurationExecutionError: martian.error.GrokError: Multiple possible templates for viewlet <class 'microbio2.viewlets.AppCSS'>. It uses grok.template('appcss.pt'), but there is also a template called 'appcss'.

Essentially, grok complains because I'm too explicit: grok.template("appcss.pt") results in the same template that grok finds implicitly. In my opinion, this might cause a warning but it should not be considered an error. Also, there is no template called 'appcss', it's still appcss.pt

removing the grok.template line makes the error disappear.

grok.template expects a template name without extension, I think. What
happens if you use 'appcss' without the '.pt'?

Ivo van der Wijk (ivo-m3r) wrote :

that fixes it :)

But then shouldn't grok complain it can't find appcss.pt?

On Tue, Jun 24, 2008 at 6:05 PM, Ivo van der Wijk <email address hidden> wrote:
> But then shouldn't grok complain it can't find appcss.pt?

In this case that would indeed look nicer. Patches with tests are
welcome, I'm not sure how hard it would be to make it behave more
nicely. We could also decide to detect the use of an extension in
grok.template and fail if that happens.

Reed O'Brien (reedobrien) wrote :

On Jun 24, 2008, at 1:30 PM, Martijn Faassen wrote:

> On Tue, Jun 24, 2008 at 6:05 PM, Ivo van der Wijk <email address hidden> wrote:
>> But then shouldn't grok complain it can't find appcss.pt?
>
> In this case that would indeed look nicer. Patches with tests are
> welcome, I'm not sure how hard it would be to make it behave more
> nicely. We could also decide to detect the use of an extension in
> grok.template and fail if that happens.
>
> --
> grok doesn't like explicit grok.template() if it matches implicitly
> found template
> https://bugs.launchpad.net/bugs/242698
> You received this bug notification because you are subscribed to grok.

I assume you mean explicitly detect a '.pt' extension and not '.html'
'.xml' et al.

What about snipping off the .pt and using the rest as the name.

At first I didn't like the name without the extension, but then I
changed my mind.

I would specifically be thinking I want this to go to 'foo.html'. In
which case I don't think of the '.pt' bit when I am typing.

Martijn Faassen (faassen) wrote :

I think what we could perhaps do is explicitly detect the presence of
an extension at all in grok.template, and complain if so. It's of
course *possible* there's something lying around called foo.pt.pt, but
I think we shouldn't worry too much about supporting that case.

todd (todd-infrae) on 2008-12-10
Changed in grok:
assignee: nobody → brandon-rhodes
milestone: none → 1.0
Changed in grok:
assignee: brandon-rhodes → janwijbrand
importance: Undecided → Medium
status: New → Confirmed
Reinout van Rees (reinout) wrote :

See https://bugs.launchpad.net/grok/1.0/+bug/225855 : "grok.template doesn't complain if the given template does not exist". With the render() method gone from regular View classes, we can be more explicit about missing templates.

the referenced issue 225855 has been fixed and fixes most of the problems in this issue, except for the file extension part that will be ignored in the issue.

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

Other bug subscribers