[Grok-dev] template association redux: module-level directives and inheritance

Jan-Wijbrand Kolman janwijbrand at gmail.com
Fri Sep 26 05:53:03 EDT 2008


>> However now for the real problem: for grok.templatedir() there is no
>> class-level equivalent. And it does not really make sense either. 
> 
> There being no class-level equivalent makes no sense? Or do you mean 
> that having one on a per-class level makes no sense? I can see 
> grok.templatedir() doing something on a per-class level as well as a 
> per-module level.

I meant that I do not really see a reason for grok.templatedir() to be
definable on a class-level, even though technically it would be
certainly be very easy to implement.

>> * We take over, in modified form, Lennart Regebro's suggestion to
>> actually use a path-like syntax for grok.template(). We can then get rid
>> of the grok.templatedir() directive alltogether. Without much thinking,
>> I could imagine something like:
>>
>>   grok.template('mytemplates/foo')
>>
>> and we can probably think of all kinds of sensible defaults for
>> different kinds of path-like values.
> 
> How would the absence of grok.template() interact with inheritance?

If there a grok.template() set somewhere in the inheritance tree, there
would not be a problem: when the directive is executed, we know what the
path of the module is and thus we can compute a path to the template.

Or do you mean something else?

>> * We think of a fundamental solution for "inheriting" directive
>> information for subclasses of components that a defined in another
>> module than the baseclass.
> 
> Perhaps another fall-back level:
> 
> 1) look for the directive on the class
> 
> 2) look for the directive on the module
> 
> 3) look for the directive on the module of the base class.
> 
> Whether 2) should come first or 3) can be debated. For backwards 
> compatibility's sake 2) should at least come first.

When doing 2) before 3) there would actually be a problem in thie
following situation:

module foo.py:

  import grok
  grok.templatedir('somewhere')

  class Content(grok.Model):
    pass

  class ContentView(grok.View):
    grok.template('tmlp1')

module bar.py:

  import grok
  import foo

  grok.templatedir('somewhereelse')

  class AnotherContentView(grok.View):
    grok.template('tmpl2')

  class SubclassOfContentView(foo.ContentView):
    pass

You would expect to find the 'tmpl1' associated with
SubclassOfContentView in the template directory set by the
grok.templatedir() directive in foo.py, not bar.py.

I'm not sure yet to what extent 3) before 2) would hurt backwards
imcompatibility, I need to think about that a bit more.

I'm also inclinded to think a bit more about the
grok.template('mytemplates/foo') spelling.


regards,
jw




More information about the Grok-dev mailing list