Ticket #14365: 14365_r13962.diff
File 14365_r13962.diff, 6.1 KB (added by , 14 years ago) |
---|
-
django/template/__init__.py
diff --git a/django/template/__init__.py b/django/template/__init__.py index c316786..60cbc03 100644
a b from inspect import getargspec 54 54 55 55 from django.conf import settings 56 56 from django.template.context import Context, RequestContext, ContextPopException 57 from django.template.signals import template_rendered 57 58 from django.utils.importlib import import_module 58 59 from django.utils.itercompat import is_iterable 59 60 from django.utils.functional import curry, Promise … … class StringOrigin(Origin): 148 149 return self.source 149 150 150 151 class Template(object): 152 send_rendered_signal = settings.TEMPLATE_DEBUG 153 151 154 def __init__(self, template_string, origin=None, name='<Unknown Template>'): 152 155 try: 153 156 template_string = smart_unicode(template_string) … … class Template(object): 164 167 yield subnode 165 168 166 169 def _render(self, context): 170 if self.send_rendered_signal: 171 template_rendered.send(sender=self, template=self, context=context) 167 172 return self.nodelist.render(context) 168 173 169 174 def render(self, context): -
new file django/template/signals.py
diff --git a/django/template/signals.py b/django/template/signals.py new file mode 100644 index 0000000..a328a77
- + 1 from django.dispatch import Signal 2 3 template_rendered = Signal(providing_args=["template", "context"]) -
django/test/client.py
diff --git a/django/test/client.py b/django/test/client.py index 08e3ff6..3251275 100644
a b from django.core.handlers.wsgi import WSGIRequest 16 16 from django.core.signals import got_request_exception 17 17 from django.http import SimpleCookie, HttpRequest, QueryDict 18 18 from django.template import TemplateDoesNotExist 19 from django.te stimport signals19 from django.template import signals 20 20 from django.utils.functional import curry 21 21 from django.utils.encoding import smart_str 22 22 from django.utils.http import urlencode -
deleted file django/test/signals.py
diff --git a/django/test/signals.py b/django/test/signals.py deleted file mode 100644 index a328a77..0000000
+ - 1 from django.dispatch import Signal2 3 template_rendered = Signal(providing_args=["template", "context"]) -
django/test/utils.py
diff --git a/django/test/utils.py b/django/test/utils.py index 8ecb5a0..7dda41f 100644
a b import os 4 4 from django.conf import settings 5 5 from django.core import mail 6 6 from django.core.mail.backends import locmem 7 from django.test import signals8 7 from django.template import Template 9 8 from django.utils.translation import deactivate 10 9 … … class ContextList(list): 43 42 return False 44 43 return True 45 44 46 def instrumented_test_render(self, context):47 """48 An instrumented Template render method, providing a signal49 that can be intercepted by the test system Client50 """51 signals.template_rendered.send(sender=self, template=self, context=context)52 return self.nodelist.render(context)53 54 45 55 46 def setup_test_environment(): 56 47 """Perform any global pre-test setup. This involves: … … def setup_test_environment(): 59 50 - Set the email backend to the locmem email backend. 60 51 - Setting the active locale to match the LANGUAGE_CODE setting. 61 52 """ 62 Template. original_render = Template._render63 Template. _render = instrumented_test_render53 Template._original_send_rendered_signal = Template.send_rendered_signal 54 Template.send_rendered_signal = True 64 55 65 56 mail.original_SMTPConnection = mail.SMTPConnection 66 57 mail.SMTPConnection = locmem.EmailBackend … … def teardown_test_environment(): 79 70 - Restoring the email sending functions 80 71 81 72 """ 82 Template. _render = Template.original_render83 del Template. original_render73 Template.send_rendered_signal = Template._original_send_rendered_signal 74 del Template._original_send_rendered_signal 84 75 85 76 mail.SMTPConnection = mail.original_SMTPConnection 86 77 del mail.original_SMTPConnection -
tests/regressiontests/templates/tests.py
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index bbbcae3..ff049f1 100644
a b import unittest 16 16 from django import template 17 17 from django.core import urlresolvers 18 18 from django.template import loader 19 from django.template.signals import template_rendered 19 20 from django.template.loaders import app_directories, filesystem, cached 20 21 from django.utils.translation import activate, deactivate, ugettext as _ 21 22 from django.utils.safestring import mark_safe … … class TemplateTagLoading(unittest.TestCase): 1389 1390 settings.INSTALLED_APPS = ('tagsegg',) 1390 1391 t = template.Template(ttext) 1391 1392 1393 1394 class TemplateSignalTests(unittest.TestCase): 1395 def setUp(self): 1396 self._old_send = template.Template.send_rendered_signal 1397 1398 self.received = [] 1399 def _handle_signal(signal, sender, template, context, **kwargs): 1400 self.received.append((template, context)) 1401 template_rendered.connect(_handle_signal, weak=False, dispatch_uid='test-template-rendered') 1402 1403 def tearDown(self): 1404 template_rendered.disconnect(dispatch_uid='test-template-rendered') 1405 1406 template.Template.send_rendered_signal = self._old_send 1407 1408 def test_template_rendered_signal_on(self): 1409 "If Template.send_rendered_signal is True, template-rendering sends a template_rendered signal." 1410 template.Template.send_rendered_signal = True 1411 1412 t = template.Template("{{ stuff }}") 1413 c = template.Context({'stuff': 'something'}) 1414 t.render(c) 1415 1416 self.assertEqual(self.received, [(t, c)]) 1417 1418 def test_template_rendered_signal_off(self): 1419 "If Template.send_rendered_signal is False, template-rendering does not send template_rendered signal." 1420 template.Template.send_rendered_signal = False 1421 1422 t = template.Template("{{ stuff }}") 1423 c = template.Context({'stuff': 'something'}) 1424 t.render(c) 1425 1426 self.assertEqual(self.received, []) 1427 1428 1392 1429 if __name__ == "__main__": 1393 1430 unittest.main()