Skip to content

Commit

Permalink
Refactoring templatetags
Browse files Browse the repository at this point in the history
  • Loading branch information
silentsokolov committed Jan 30, 2019
1 parent d83274f commit af1a205
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion rangefilter/templates/rangefilter/date_filter.html
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
19 changes: 19 additions & 0 deletions rangefilter/templatetags/rangefilter_compat.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 0 additions & 14 deletions rangefilter/templatetags/static_or_admin_static.py

This file was deleted.

14 changes: 5 additions & 9 deletions rangefilter/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import datetime

from django.contrib.staticfiles.storage import staticfiles_storage

try:
import pytz
except ImportError:
Expand All @@ -21,9 +19,10 @@
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):
Expand Down Expand Up @@ -280,11 +279,9 @@ def test_datefilter_filtered_with_one_params(self):


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={
Expand All @@ -293,7 +290,6 @@ def test_returns_static_path_to_asset_when_staticfiles_app_is_installed(self):
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

0 comments on commit af1a205

Please sign in to comment.