Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #56 from aericson/django-18
Browse files Browse the repository at this point in the history
Compatibility with Django 1.8
  • Loading branch information
antonagestam committed Apr 22, 2015
2 parents ef42a8f + 3b7db94 commit 8921f21
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ python:
- "3.2"
- "3.3"
env:
- DJANGO_VERSION=1.4.10
- DJANGO_VERSION=1.5.5
- DJANGO_VERSION=1.6.2
- DJANGO_VERSION=1.4.20
- DJANGO_VERSION=1.5.12
- DJANGO_VERSION=1.6.11
- DJANGO_VERSION=1.7.7
- DJANGO_VERSION=1.8
install:
- pip install -r test-requirements.txt
- pip install -q Django==$DJANGO_VERSION
Expand All @@ -16,6 +18,6 @@ after_success:
matrix:
exclude:
- python: "3.2"
env: DJANGO_VERSION=1.4.10
env: DJANGO_VERSION=1.4.20
- python: "3.3"
env: DJANGO_VERSION=1.4.10
env: DJANGO_VERSION=1.4.20
30 changes: 23 additions & 7 deletions collectfast/management/commands/collectstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import hashlib
import datetime

from django import VERSION
from django.conf import settings
from django.contrib.staticfiles.management.commands import collectstatic
from django.core.cache import get_cache
from django.core.files.storage import FileSystemStorage
from django.core.management.base import CommandError
from django.utils.encoding import smart_str
Expand All @@ -17,19 +17,27 @@
except ImportError:
_input = raw_input

cache = get_cache(getattr(settings, "COLLECTFAST_CACHE", "default"))

collectfast_cache = getattr(settings, "COLLECTFAST_CACHE", "default")
if VERSION >= (1, 7):
from django.core.cache import caches
cache = caches[collectfast_cache]
else:
from django.core.cache import get_cache
cache = get_cache(collectfast_cache)


class Command(collectstatic.Command):
option_list = collectstatic.Command.option_list + (
make_option(
'--ignore-etag', action="store_true", dest="ignore_etag",
default=False, help="Disable Collectfast."),
)

lookups = None
cache_key_prefix = 'collectfast_asset_'

def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument('--ignore-etag',
action='store_true', dest='ignore_etag', default=False,
help="Disable Collectfast.")

def __init__(self, *args, **kwargs):
super(Command, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -200,3 +208,11 @@ def handle_noargs(self, **options):
'collect_time': self.collect_time,
}
self.stdout.write(smart_str(summary))


if VERSION < (1, 8):
Command.option_list = collectstatic.Command.option_list + (
make_option(
'--ignore-etag', action="store_true", dest="ignore_etag",
default=False, help="Disable Collectfast."),
)
10 changes: 10 additions & 0 deletions collectfast/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from mock import patch
from os.path import join

from django import VERSION
from django.core.files.storage import Storage, FileSystemStorage
from django.core.files.base import ContentFile
from django.conf import settings
Expand Down Expand Up @@ -97,6 +98,14 @@ def test_destroy_lookup(self, mocked_lookup):
self.assertEqual(cache.get(cache_key, 'empty'), 'empty')
self.assertNotIn(path, c.lookups)

def test_make_sure_it_has_ignore_etag(self):
command = self.get_command()
parser = command.create_parser('', '')
if VERSION >= (1, 8):
self.assertIn('ignore_etag', parser.parse_args())
else:
self.assertTrue(parser.has_option('--ignore-etag'))


class TestGetFileHash(CollectfastTestCase):
def test_get_file_hash(self):
Expand All @@ -122,6 +131,7 @@ class TestCopyFile(CollectfastTestCase):
def call_copy_file(self, mocked_lookup, mocked_copy_file_super, **kwargs):
options = {
"interactive": False,
"verbosity": 1,
"post_process": False,
"dry_run": False,
"clear": False,
Expand Down
4 changes: 4 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from optparse import OptionParser

import django
from django.conf import settings
from django.core.management import call_command

Expand Down Expand Up @@ -58,12 +59,15 @@ def main():
"STATIC_ROOT": "./",

"AWS_PRELOAD_METADATA": True,
"MIDDLEWARE_CLASSES": [],
})

if options.TEST_SUITE is not None:
test_arg = "%s.%s" % (app_name, options.TEST_SUITE)
else:
test_arg = app_name
if django.VERSION >= (1, 7):
django.setup()

call_command("test", test_arg)

Expand Down

0 comments on commit 8921f21

Please sign in to comment.