Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2457 (closed enhancement: migrated)

Opened 9 years ago

Last modified 8 years ago

[PATCH] Make override_template work for all content types

Reported by: lento Owned by:
Priority: normal Milestone: 2.1.1
Component: TurboGears Version: 2.1
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".

    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()


generalize_override_template.patch Download (1002 bytes) - added by lento 9 years ago.
fixed_override_template.patch Download (1.2 KB) - added by chrisz 9 years ago.
Proposed fix of already checked in patch

Change History

Changed 9 years ago by lento

comment:1 Changed 9 years ago by jorge.vargas

  • Version changed from trunk to 2.1
  • Milestone changed from __unclassified__ to 2.1b2

Use case looks weird but the patch is ok.

comment:2 Changed 9 years ago by percious

  • Status changed from new to closed
  • Resolution set to fixed

comment:3 Changed 9 years ago by chrisz

  • Status changed from closed to reopened
  • Resolution fixed deleted
  • Milestone changed from 2.1b2 to __unclassified__

The checked in patch is flawed (see also  here): First and worst, template is changed during the loop. Second, the override_mapping should not be set in every round of the loop. See attached proposed fix.

The other big flaw that I have not fixed is that there is no unit test or integration test for this function.

Changed 9 years ago by chrisz

Proposed fix of already checked in patch

comment:4 Changed 9 years ago by chrisz

  • Milestone changed from __unclassified__ to 2.1.1

comment:5 Changed 8 years ago by pedersen

  • Status changed from reopened to closed
  • Resolution set to migrated
Note: See TracTickets for help on using tickets.