#NEWLINE# def auto_render( func ) : #NEWLINE# #INDENT# 'Decorator that automaticaly call the render_to_response shortcut.\n\n    The view must return a tuple with two items : a template filename and the desired context.\n    HttpResponse object could be also returned. it\'s possible to override the default \n    template filename by calling a decorated view with an "template_name" parameter\n    or to get only the context dictionary via "only_context" parameter.\n\n    >>> from utils.utils import auto_render\n    >>> @auto_render\n    ... def test(request):\n    ...     return \'base.html\', {\'oki\':1}\n    ...\n    >>> from django.http import HttpRequest, HttpResponse\n    >>> response = test(HttpRequest())\n    >>> assert type(response) is HttpResponse\n    >>> response = test(HttpRequest(), only_context=True)\n    >>> assert response[\'oki\'] == 1\n    >>> try:\n    ...     response = test(HttpRequest(), template_name=\'fake_template.html\')\n    ... except Exception, e:\n    ...     e.message\n    \'fake_template.html\'\n    ' #NEWLINE# def _dec( request , * args , **kwargs ) : #NEWLINE# #INDENT# if kwargs . get ( 'only_context' , False ) : #NEWLINE# #INDENT# del kwargs [ 'only_context' ] #NEWLINE# response = func ( request , * args , ** kwargs ) #NEWLINE# if ( isinstance ( response , HttpResponse ) or isinstance ( response , HttpResponseRedirect ) ) : #NEWLINE# #INDENT# raise Except ( 'cannot return context dictionary because a HttpResponseRedirect as been found' ) #NEWLINE# #UNINDENT# ( template_name , context ) = response #NEWLINE# return context #NEWLINE# #UNINDENT# if kwargs . get ( 'template_name' , False ) : #NEWLINE# #INDENT# overriden_template_name = kwargs [ 'template_name' ] #NEWLINE# del kwargs [ 'template_name' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# overriden_template_name = None #NEWLINE# #UNINDENT# response = func ( request , * args , ** kwargs ) #NEWLINE# if ( isinstance ( response , HttpResponse ) or isinstance ( response , HttpResponseRedirect ) ) : #NEWLINE# #INDENT# return response #NEWLINE# #UNINDENT# ( template_name , context ) = response #NEWLINE# if overriden_template_name : #NEWLINE# #INDENT# template_name = overriden_template_name #NEWLINE# #UNINDENT# return render_to_response ( template_name , context , context_instance = RequestContext ( request ) ) #NEWLINE# #UNINDENT# return _dec