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 #2537 (closed defect: migrated)

Opened 8 years ago

Last modified 8 years ago

Multiple override_template usage issue (mixed decorated and classic call)

Reported by: BeeBob Owned by:
Priority: normal Milestone: __unclassified__
Component: TurboGears Version: 2.1
Severity: normal Keywords: override_template
Cc:

Description

Sample controller that i use to get the issue ;

class SandBoxController(TGController):

    @expose('mako:Browser', content_type='text/html')
    @expose('mako:InPlace', content_type='text/xml')       
    def default(self, **kw):
        """ All in one func for folder browsing """
        # Dummy Datas, provided for example
        MyDatas = [(i,str(i)) for i in range(10)]

        # Request for ajax special statement (for example)
        if kw.has_key('in_place'):  # This case is working
            pylons.response.headers['Content-Type'] = 'text/xml' 
        
        # Special Request - to display file
        if kw.has_key('isFile'):
            # i would like this one with 'text/html' Content-type
            # in this Case, the TG2 override method fails inside decorators.py 
            override_template(self.default, 'mako:Show_File' )
            return dict(Datas = MyData, FileContent = "bla")
        
        # This return is ok for both Content-type
        return dict(Datas = MyDatas)

The issue, in this particular test case, is that the "template" variable is already a list when override_template is called from inside the controller, in fact i get an error ...

Module tg.decorators:344 in override_template

<<      for content_type, content_engine in engines.iteritems():
               template = template.split(':')
               template.extend(content_engine[2:])
               try:
>>  template = template.split(':')
AttributeError: 'list' object has no attribute 'split'

My issue is that template is already a list on this specific case. so, i solve this issue by adding a simple check on it. (patch inside TG2 code)

for content_type, content_engine in engines.iteritems():
    if isinstance(template,str):
        template = template.split(':')
        template.extend(content_engine[2:])

And that works for me now...

Perhaps some of you could test, confirm and do a small patch or give me a 'convenient' way to do this.

Change History

comment:1 Changed 8 years ago by pedersen

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