Skip to content

Commit

Permalink
Refactor Template.render()
Browse files Browse the repository at this point in the history
- Template now subclasses Jinja2.Template, like it should have all along
- We now fire off template rendered signals.
- This now works in Django Debug Toolbar (thanks for the pointers @robhudson)
  • Loading branch information
davedash committed Oct 26, 2011
1 parent 5d73f69 commit f1b0367
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions jingo/__init__.py
Expand Up @@ -2,6 +2,7 @@
import functools import functools
import imp import imp
import logging import logging
import warnings


from django import http from django import http
from django.conf import settings from django.conf import settings
Expand Down Expand Up @@ -69,8 +70,8 @@ def render(request, template, context=None, **kwargs):
.. deprecated:: 0.4 .. deprecated:: 0.4
use ``django.shortcuts.render()`` use ``django.shortcuts.render()``
""" """
log.warning('jingo.render() has been deprecated. ' warnings.warn('jingo.render() has been deprecated. Use '
'Use django.shortcuts.render().') 'django.shortcuts.render().', DeprecationWarning)
rendered = render_to_string(request, template, context) rendered = render_to_string(request, template, context)
return http.HttpResponse(rendered, **kwargs) return http.HttpResponse(rendered, **kwargs)


Expand Down Expand Up @@ -172,10 +173,13 @@ def render(self, context={}):
else: else:
context_dict = context context_dict = context


# Django Debug Toolbar needs a RequestContext-like object in order
# to inspect context.
class FakeRequestContext: class FakeRequestContext:
dicts = [context] dicts = [context]
context = FakeRequestContext() context = FakeRequestContext()


# Used by debug_toolbar.
if settings.TEMPLATE_DEBUG: if settings.TEMPLATE_DEBUG:
from django.test import signals from django.test import signals
self.origin = Origin(self.filename) self.origin = Origin(self.filename)
Expand Down

0 comments on commit f1b0367

Please sign in to comment.