[albatross-users] ctx.locals.__page__ for random pages

Matt Goodall matt at pollenation.net
Mon Aug 18 01:24:20 EST 2003


On Sun, 2003-08-17 at 11:35, Dave Cole wrote:
> > Actually, it would be really nice if run_template() could cope with
> > template file paths relative to the current page path. If the
> > template name starts with a '/' then it's relative to the
> > TemplateLoaderMixin's base_dir, otherwise it's relative to that
> > base_dir plus the os.path.dirname() of the page module.
> > 
> > For a page module '/one/two/three/page.py' that would let you do:
> > 
> >     def page_display(ctx):
> >         ctx.runtemplate('page.html')
> > 
> > rather than
> > 
> >     def page_display(ctx):
> >         ctx.runtemplate('one/two/three/page.html')
> > 
> > I think this would only make sense for random apps though, where the
> > page modules and template files live together.
> 
> It would probably make sense for all types of application.

OK. It would certainly be better if any changes are made to all types of
app but would it be a bit weird for PageObjectMixin applications where
there is no directory structure?

By the way, the reason I said "this would only make sense for random
apps" is because RandomModularXxxApp is the only one of the prepackaged
application types where the page modules and the page templates live
together in a single directory structure.

Perhaps it's best to forget about this idea to avoid the complexity.
It's something that is fairly easily to handle per application (once
__page__ is set for random apps).

> Currently Albatross only really cares about current directory -
> although by passing absolute paths for template and module paths you
> can probably eliminate that as well.
> 
> To do what you are talking about I think Albatross would need to
> develop an internal sense of current page module directory in order to
> resolve relative paths.

Isn't something like template_path + os.path.dirname(__page__) +
template_file sufficient?

> 
> In order to provide what I think you are asking for it is probably
> necessary to introduce one extra path to an Albatross application; the
> application root.  Once you have specified the root you can make the
> page module and template directories relative to that root.  In a
> sense Albatross currently uses the current working directory as an
> implicit application root.
> 
> Then any page or template name beginning with / would be relative to
> the application root and any not beginning with / would be considered
> relative to the directory containing the current page module.
> 
> Not sure how hard this would be...

I'm a bit Random app focussed but it was easy enough there. I wrote a
quick function - run_template_relative(ctx, template) - that used
os.path.dirname(ctx.locals.__page__) to work things out. I don't think I
have the code anymore as I was trying to avoid wandering any further
from your code base but it was fairly straightforward. I couldn't think
of a reason why this couldn't be rolled into the normal run_template()
method.

> > By the way, is it deliberate that the template name cannot start
> > with a '/' at the moment?
> 
> Nope.

OK ;-)


Cheers, Matt

-- 
Matt Goodall, Pollenation Internet Ltd
w: http://www.pollenation.net
e: matt at pollenation.net



More information about the Albatross-users mailing list