Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ Define the prefix in your django settings:
::
JS_REVERSE_SCRIPT_PREFIX = '/myprefix/'

By default collectstatic_js_reverse writes its output (reverse.js) to your project's STATIC_ROOT.
You can change the output path:

::

JS_REVERSE_OUTPUT_PATH = 'some_path'


License
-------
Expand Down
1 change: 1 addition & 0 deletions django_js_reverse/js_reverse_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
JS_EXCLUDE_NAMESPACES = []
JS_SCRIPT_PREFIX = None
JS_GLOBAL_OBJECT_NAME = 'this'
JS_OUTPUT_PATH = None
14 changes: 11 additions & 3 deletions django_js_reverse/management/commands/collectstatic_js_reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@
from django.core.management.base import BaseCommand

from django_js_reverse.core import generate_js
from django_js_reverse.js_reverse_settings import JS_OUTPUT_PATH


class Command(BaseCommand):
help = 'Creates a static urls-js file for django-js-reverse'

def handle(self, *args, **options):
def get_location(self):
output_path = getattr(settings, 'JS_REVERSE_OUTPUT_PATH', JS_OUTPUT_PATH)
if output_path:
return output_path

if not hasattr(settings, 'STATIC_ROOT') or not settings.STATIC_ROOT:
raise ImproperlyConfigured('The collectstatic_js_reverse command needs settings.STATIC_ROOT to be set.')
raise ImproperlyConfigured('The collectstatic_js_reverse command needs settings.JS_OUTPUT_PATH or settings.STATIC_ROOT to be set.')

location = os.path.join(settings.STATIC_ROOT, 'django_js_reverse', 'js')
return os.path.join(settings.STATIC_ROOT, 'django_js_reverse', 'js')

def handle(self, *args, **options):
location = self.get_location()
file = 'reverse.js'
fs = FileSystemStorage(location=location)
if fs.exists(file):
Expand Down
2 changes: 1 addition & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
)
ALLOWED_HOSTS = ['testserver']
MIDDLEWARE_CLASSES = ()
STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'tmp')
STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'tmp', 'static_root')
Empty file removed tests/tmp/DONOTDELETE
Empty file.
2 changes: 2 additions & 0 deletions tests/tmp/some_path/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions tests/tmp/static_root/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
25 changes: 25 additions & 0 deletions tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,31 @@ def test_reverse_js_file_save(self):
with self.assertRaises(ImproperlyConfigured):
call_command('collectstatic_js_reverse')

def test_reverse_js_file_save_with_output_path_option(self):
js_output_path = os.path.join(os.path.dirname(__file__), 'tmp', 'some_path')
with override_settings(JS_REVERSE_OUTPUT_PATH=js_output_path):
call_command('collectstatic_js_reverse')

f = open(os.path.join(js_output_path, 'reverse.js'))
content1 = f.read()
if hasattr(content1, 'decode'):
content1 = content1.decode()

r2 = self.client.get('/jsreverse/')
content2 = r2.content
if hasattr(content2, 'decode'):
content2 = content2.decode()

self.assertEqual(len(content1), len(content2), 'Static file don\'t match http response content_1')
self.assertEqual(content1, content2, 'Static file don\'t match http response content_2')

# should not raise ImproperlyConfigured exception if STATIC_ROOT is not set
with override_settings(STATIC_ROOT=None):
try:
call_command('collectstatic_js_reverse')
except ImproperlyConfigured:
self.fail('should not raise ImproperlyConfigured exception if STATIC_ROOT is not set and JS_REVERSE_OUTPUT_PATH is set')

def test_script_prefix(self):
script_prefix = '/test/foo/bar/'
with override_settings(JS_REVERSE_SCRIPT_PREFIX=script_prefix):
Expand Down
25 changes: 0 additions & 25 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
envlist =
py26-django16, py26-django15,
py27-django18, py27-django17, py27-django16, py27-django15,
py32-django18, py32-django17, py32-django16, py32-django15,
py33-django18, py33-django17, py33-django16, py33-django15,
py34-django18, py34-django17, py34-django16, py34-django15,
;pypy25-django18, pypy25-django17, pypy25-django16, pypy25-django15,
Expand Down Expand Up @@ -51,30 +50,6 @@ deps =
Django>=1.5,<1.6
{[testenv]deps}

[testenv:py32-django18]
basepython = python3.2
deps =
Django>=1.8,<1.9
{[testenv]deps}

[testenv:py32-django17]
basepython = python3.2
deps =
Django>=1.7,<1.8
{[testenv]deps}

[testenv:py32-django16]
basepython = python3.2
deps =
Django>=1.6,<1.7
{[testenv]deps}

[testenv:py32-django15]
basepython = python3.2
deps =
Django>=1.5,<1.6
{[testenv]deps}

[testenv:py33-django18]
basepython = python3.3
deps =
Expand Down