Menu

#82 Multiple override_template usage issue (mixed decorated and classic call)

2.1.2
closed
nobody
core
defect
normal
core
2.1.0
2015-02-06
2011-03-29
No

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.

Discussion