mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Fixed #34692 -- Made autoreloader reset cached template loader for default renderer.
This commit is contained in:
parent
e02fc58889
commit
439242c594
@ -31,12 +31,19 @@ def get_template_directories():
|
||||
|
||||
|
||||
def reset_loaders():
|
||||
from django.forms.renderers import get_default_renderer
|
||||
|
||||
for backend in engines.all():
|
||||
if not isinstance(backend, DjangoTemplates):
|
||||
continue
|
||||
for loader in backend.engine.template_loaders:
|
||||
loader.reset()
|
||||
|
||||
backend = get_default_renderer().engine
|
||||
if isinstance(backend, DjangoTemplates):
|
||||
for loader in backend.engine.template_loaders:
|
||||
loader.reset()
|
||||
|
||||
|
||||
@receiver(autoreload_started, dispatch_uid="template_loaders_watch_changes")
|
||||
def watch_for_template_changes(sender, **kwargs):
|
||||
|
@ -56,6 +56,23 @@ class TemplateReloadTests(SimpleTestCase):
|
||||
self.assertIsNone(autoreload.template_changed(None, Path(__file__)))
|
||||
mock_reset.assert_not_called()
|
||||
|
||||
@mock.patch("django.forms.renderers.get_default_renderer")
|
||||
def test_form_template_reset_template_change(self, mock_renderer):
|
||||
template_path = Path(__file__).parent / "templates" / "index.html"
|
||||
self.assertIs(autoreload.template_changed(None, template_path), True)
|
||||
mock_renderer.assert_called_once()
|
||||
|
||||
@mock.patch("django.template.loaders.cached.Loader.reset")
|
||||
def test_form_template_reset_template_change_reset_call(self, mock_loader_reset):
|
||||
template_path = Path(__file__).parent / "templates" / "index.html"
|
||||
self.assertIs(autoreload.template_changed(None, template_path), True)
|
||||
mock_loader_reset.assert_called_once()
|
||||
|
||||
@mock.patch("django.forms.renderers.get_default_renderer")
|
||||
def test_form_template_reset_non_template_change(self, mock_renderer):
|
||||
self.assertIsNone(autoreload.template_changed(None, Path(__file__)))
|
||||
mock_renderer.assert_not_called()
|
||||
|
||||
def test_watch_for_template_changes(self):
|
||||
mock_reloader = mock.MagicMock()
|
||||
autoreload.watch_for_template_changes(mock_reloader)
|
||||
|
Loading…
Reference in New Issue
Block a user