Refactoring templatetags
This commit is contained in:
parent
d83274f16b
commit
af1a205147
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
|||
.PHONY: test sdist wheel release pre-release clean
|
||||
|
||||
test:
|
||||
python runtests.py
|
||||
python -Wall runtests.py
|
||||
|
||||
sdist:
|
||||
python setup.py sdist
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load i18n static_or_admin_static %}
|
||||
{% load i18n rangefilter_compat %}
|
||||
<h3>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</h3>
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'admin/css/widgets.css' %}">
|
||||
<style>
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import django
|
||||
|
||||
from django.template import Library
|
||||
|
||||
if django.VERSION[:2] >= (1, 10):
|
||||
from django.templatetags.static import static as _static
|
||||
else:
|
||||
from django.contrib.admin.templatetags.admin_static import static as _static
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def static(path):
|
||||
return _static(path)
|
|
@ -1,14 +0,0 @@
|
|||
import django
|
||||
from django.template import Library
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def static(path):
|
||||
if django.VERSION[:2] >= (1, 10):
|
||||
from django.templatetags.static import static as _static
|
||||
else:
|
||||
from django.contrib.admin.templatetags.admin_static import static as _static
|
||||
|
||||
return _static(path)
|
|
@ -4,8 +4,6 @@ from __future__ import unicode_literals
|
|||
|
||||
import datetime
|
||||
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
|
||||
try:
|
||||
import pytz
|
||||
except ImportError:
|
||||
|
@ -21,9 +19,10 @@ from django.contrib.admin import ModelAdmin, site
|
|||
from django.contrib.admin.views.main import ChangeList
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.encoding import force_text
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
|
||||
from .filter import DateRangeFilter, DateTimeRangeFilter
|
||||
from .templatetags import static_or_admin_static
|
||||
from .templatetags.rangefilter_compat import static
|
||||
|
||||
|
||||
class MyModel(models.Model):
|
||||
|
@ -280,11 +279,9 @@ class DateTimeRangeFilterTestCase(TestCase):
|
|||
|
||||
|
||||
class StaticOrAdminStaticTestCase(TestCase):
|
||||
|
||||
@override_settings(STATIC_URL='/my_statics/')
|
||||
@override_settings(STATIC_URL='/test/')
|
||||
def test_returns_static_path_to_asset_when_staticfiles_app_is_not_installed(self):
|
||||
self.assertEqual(static_or_admin_static.static('admin/css/widgets.css'),
|
||||
'/my_statics/admin/css/widgets.css')
|
||||
self.assertEqual(static('path'), '/test/path')
|
||||
|
||||
def test_returns_static_path_to_asset_when_staticfiles_app_is_installed(self):
|
||||
with self.modify_settings(INSTALLED_APPS={
|
||||
|
@ -293,7 +290,6 @@ class StaticOrAdminStaticTestCase(TestCase):
|
|||
old_url = staticfiles_storage.base_url
|
||||
staticfiles_storage.base_url = '/test/'
|
||||
try:
|
||||
self.assertEqual(static_or_admin_static.static('admin/css/widgets.css'),
|
||||
'/test/admin/css/widgets.css')
|
||||
self.assertEqual(static('path'), '/test/path')
|
||||
finally:
|
||||
staticfiles_storage.base_url = old_url
|
||||
|
|
Loading…
Reference in New Issue