[TurboGears] #2457: [PATCH] Make override_template work for all content types

5 views
Skip to first unread message

TurboGears

unread,
Feb 3, 2010, 4:16:41 AM2/3/10
to turbogear...@googlegroups.com
#2457: [PATCH] Make override_template work for all content types
-------------------------+--------------------------------------------------
Reporter: lento | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: __unclassified__
Component: TurboGears | Version: trunk
Severity: normal | Keywords: override_template, content_type
-------------------------+--------------------------------------------------
At the moment override_template only works for the "text/html" engine,
this small patch allows it to work for other content types.

As an example I use override_template to have a single controller serving
javascripts generated at runtime from templates and return the result with
a content_type of "text/javascript".

{{{
@expose(content_type='text/javascript')
def parsedjs(self, script):
"""
Render the required javascript from a template of the same name
(but
with a .mak extension) as found in spam/templates/parsedjs/

This is needed for javascripts that use config variables from spam
or
other variable data.
"""
scriptname = os.path.splitext(script)[0]
templatename = 'spam.templates.parsedjs.%s' % scriptname

if config.get('use_dotted_templatenames', False):
template = G.dotted_filename_finder.get_dotted_filename(
templatename,
template_extension='.mak')
if not os.path.exists(template):
raise HTTPNotFound

override_template(self.parsedjs, 'mako:%s' % templatename)

return dict()
}}}

--
Ticket URL: <http://trac.turbogears.org/ticket/2457>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development

TurboGears

unread,
Feb 23, 2010, 10:18:46 AM2/23/10
to turbogear...@googlegroups.com
#2457: [PATCH] Make override_template work for all content types
---------------------------------------------+------------------------------

Reporter: lento | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 2.1b2
Component: TurboGears | Version: 2.1
Severity: normal | Resolution:
Keywords: override_template, content_type |
---------------------------------------------+------------------------------
Changes (by jorge.vargas):

* version: trunk => 2.1
* milestone: __unclassified__ => 2.1b2

Comment:

Use case looks weird but the patch is ok.

--
Ticket URL: <http://trac.turbogears.org/ticket/2457#comment:1>

TurboGears

unread,
Feb 23, 2010, 5:45:49 PM2/23/10
to turbogear...@googlegroups.com
#2457: [PATCH] Make override_template work for all content types
---------------------------------------------+------------------------------
Reporter: lento | Owner:
Type: enhancement | Status: closed

Priority: normal | Milestone: 2.1b2
Component: TurboGears | Version: 2.1
Severity: normal | Resolution: fixed
Keywords: override_template, content_type |
---------------------------------------------+------------------------------
Changes (by percious):

* status: new => closed
* resolution: => fixed

--
Ticket URL: <http://trac.turbogears.org/ticket/2457#comment:2>

Reply all
Reply to author
Forward
0 new messages