Viewlets template inheritance broken if in another package?

View: New views
3 Messages — Rating Filter:   Alert me  

Viewlets template inheritance broken if in another package?

by Mikko Ohtamaa_ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am using five.grok to cook up some viewlets.

I'd like to make viewlets reusable, so that other *packages* should subclass them.

foo.package1
foo.package1/templates/head.pt

class HeadViewlet(grok.Viewlet):

   grok.template("head")

bar.package2
(no templates)

from foo.package1 import HeadViewlet

class HeadViewlet2(HeadViewlet):
    pass

However, looks like Grok doesn't liket the idea.

- Grok assumes templates are under "templates" which in my case happens to be Python package of the parent class. Grok does not look templates from there, but assumes bar.package2/templates which does not exist.

- I cannot specify absolute templatedir (only relative paths allowed) with grok.templatedir() to force to use parent class template path

Is there any other solution than just copying the same template around to every package?

Re: Viewlets template inheritance broken if in another package?

by Souheil CHELFOUH :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

yes, in your base form, you can add a :

template = grok.PageTemplate(...)

that's the quick and dirty solution.
It's now officially unofficially supported :)


2009/10/18 Mikko Ohtamaa_ <mikko+fckingnabbleloginisbroken@...>:

>
> Hi,
>
> I am using five.grok to cook up some viewlets.
>
> I'd like to make viewlets reusable, so that other *packages* should subclass
> them.
>
> foo.package1
> foo.package1/templates/head.pt
>
> class HeadViewlet(grok.Viewlet):
>
>   grok.template("head")
>
> bar.package2
> (no templates)
>
> from foo.package1 import HeadViewlet
>
> class HeadViewlet2(HeadViewlet):
>    pass
>
> However, looks like Grok doesn't liket the idea.
>
> - Grok assumes templates are under "templates" which in my case happens to
> be Python package of the parent class. Grok does not look templates from
> there, but assumes bar.package2/templates which does not exist.
>
> - I cannot specify absolute templatedir (only relative paths allowed) with
> grok.templatedir() to force to use parent class template path
>
> Is there any other solution than just copying the same template around to
> every package?
> --
> View this message in context: http://www.nabble.com/Viewlets-template-inheritance-broken-if-in-another-package--tp25944725p25944725.html
> Sent from the Grok mailing list archive at Nabble.com.
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev@...
> https://mail.zope.org/mailman/listinfo/grok-dev
>
_______________________________________________
Grok-dev mailing list
Grok-dev@...
https://mail.zope.org/mailman/listinfo/grok-dev

Re: Viewlets template inheritance broken if in another package?

by Jan-Wijbrand Kolman-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mikko Ohtamaa_ wrote:

> Hi,
>
> I am using five.grok to cook up some viewlets.
>
> I'd like to make viewlets reusable, so that other *packages* should subclass
> them.
>
> foo.package1
> foo.package1/templates/head.pt
>
> class HeadViewlet(grok.Viewlet):
>
>    grok.template("head")
>
> bar.package2
> (no templates)
>
> from foo.package1 import HeadViewlet
>
> class HeadViewlet2(HeadViewlet):
>     pass
>
> However, looks like Grok doesn't liket the idea.
>
> - Grok assumes templates are under "templates" which in my case happens to
> be Python package of the parent class. Grok does not look templates from
> there, but assumes bar.package2/templates which does not exist.
>
> - I cannot specify absolute templatedir (only relative paths allowed) with
> grok.templatedir() to force to use parent class template path
>
> Is there any other solution than just copying the same template around to
> every package?

This template inheritance issue is in the process of being fixed in
martian, grokcore.component and grokcore.view.

It is a nasty problem and indeed until it is fixed we need to copy
template files around. Souheil's solution kind of works arround it.

sorry for the inconvenience
regards,
jw

_______________________________________________
Grok-dev mailing list
Grok-dev@...
https://mail.zope.org/mailman/listinfo/grok-dev