mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #18254 -- Added ability to the static template tags to store the result in a contextt variable. Many thanks to Andrei Antoukh for the initial patch.
This commit is contained in:
@@ -87,14 +87,16 @@ class BaseStaticFilesTestCase(object):
|
||||
template = loader.get_template_from_string(template)
|
||||
return template.render(Context(kwargs)).strip()
|
||||
|
||||
def static_template_snippet(self, path):
|
||||
def static_template_snippet(self, path, asvar=False):
|
||||
if asvar:
|
||||
return "{%% load static from staticfiles %%}{%% static '%s' as var %%}{{ var }}" % path
|
||||
return "{%% load static from staticfiles %%}{%% static '%s' %%}" % path
|
||||
|
||||
def assertStaticRenders(self, path, result, **kwargs):
|
||||
template = self.static_template_snippet(path)
|
||||
def assertStaticRenders(self, path, result, asvar=False, **kwargs):
|
||||
template = self.static_template_snippet(path, asvar)
|
||||
self.assertEqual(self.render_template(template, **kwargs), result)
|
||||
|
||||
def assertStaticRaises(self, exc, path, result, **kwargs):
|
||||
def assertStaticRaises(self, exc, path, result, asvar=False, **kwargs):
|
||||
self.assertRaises(exc, self.assertStaticRenders, path, result, **kwargs)
|
||||
|
||||
|
||||
@@ -368,6 +370,8 @@ class TestCollectionCachedStorage(BaseCollectionTestCase,
|
||||
"/static/does/not/exist.png")
|
||||
self.assertStaticRenders("test/file.txt",
|
||||
"/static/test/file.dad0999e4f8f.txt")
|
||||
self.assertStaticRenders("test/file.txt",
|
||||
"/static/test/file.dad0999e4f8f.txt", asvar=True)
|
||||
self.assertStaticRenders("cached/styles.css",
|
||||
"/static/cached/styles.93b1147e8552.css")
|
||||
self.assertStaticRenders("path/",
|
||||
|
||||
@@ -1616,6 +1616,8 @@ class Templates(unittest.TestCase):
|
||||
'static-prefixtag04': ('{% load static %}{% get_media_prefix as media_prefix %}{{ media_prefix }}', {}, settings.MEDIA_URL),
|
||||
'static-statictag01': ('{% load static %}{% static "admin/base.css" %}', {}, urljoin(settings.STATIC_URL, 'admin/base.css')),
|
||||
'static-statictag02': ('{% load static %}{% static base_css %}', {'base_css': 'admin/base.css'}, urljoin(settings.STATIC_URL, 'admin/base.css')),
|
||||
'static-statictag03': ('{% load static %}{% static "admin/base.css" as foo %}{{ foo }}', {}, urljoin(settings.STATIC_URL, 'admin/base.css')),
|
||||
'static-statictag04': ('{% load static %}{% static base_css as foo %}{{ foo }}', {'base_css': 'admin/base.css'}, urljoin(settings.STATIC_URL, 'admin/base.css')),
|
||||
|
||||
# Verbatim template tag outputs contents without rendering.
|
||||
'verbatim-tag01': ('{% verbatim %}{{bare }}{% endverbatim %}', {}, '{{bare }}'),
|
||||
|
||||
Reference in New Issue
Block a user