On Sat, Jan 10, 2009 at 5:28 AM, Mario Ruggier <[email protected]> wrote:
> you would do something like this:
>
> template = app_globals.evoque_domain.get_template("template_name")
> print template.last_modified
>
> last_modified, for file-based templates, is *file-system-checked* for
> staleness after wait intervals of <auto_reload> number of seconds...
> auto_reload may be set on domain and/or per template collection...
>
> </just-for-fun>
>
> mario ;-)
>
> ps: I would assume in mako it would be pretty much identical
>
In mako you currently have to say something like:
template =
pylons.buffet.engines['mako']['engine'].lookup.get_template(template_file)
last_modified = template.module._modified_time
I've submitted a patch <http://www.makotemplates.org/trac/ticket/97> to be
able to access it through template.last_modified().
Here's what I ended up doing, in case it's of interest:
### in lib/helpers.py:def handle_cache_headers(etag=None, last_modified=None):
if etag:
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.11
response.headers['ETag'] = '"%s"' % etag # note the double-quotes
if last_modified:
response.headers['Last-Modified'] = last_modified
try:
del response.headers['Cache-Control']
del response.headers['Pragma']
except KeyError:
pass
def serialize_date(dt):
# as in http://svn.pythonpaste.org/Paste/WebOb/trunk/webob/__init__.py
# ...
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.11if_none_match_re
= re.compile('(?:W/)?(?:"([^"]*)",?\s*)')def
cacheable_render(template_file, **kw):
template =
buffet.engines['mako']['engine'].lookup.get_template(template_file)
mod_time = template.module._modified_time # timestamp (int)
last_mod = serialize_date(mod_time) # HTTP-date (str)
etag = str(mod_time)
handle_cache_headers(etag=etag, last_modified=last_mod)
if_none_matches =
if_none_match_re.findall(request.environ.get('HTTP_IF_NONE_MATCH',
''))
if (etag in if_none_matches or
last_mod == request.environ.get('HTTP_IF_MODIFIED_SINCE')):
raise HTTPNotModified
return render(template_file, **kw)
### in some controller:
def some_cacheable_page(self):
return cacheable_render('/some_cacheable_page.mako')
(In the course of doing this I also came across a
couple<http://trac.pythonpaste.org/pythonpaste/ticket/331>
bugs <http://pylonshq.com/project/pylonshq/ticket/557>.)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---