Skip to content

Commit

Permalink
Merge pull request #594 from malefice/master
Browse files Browse the repository at this point in the history
Start Django 1.10 compatibility
  • Loading branch information
cyberdelia committed Oct 20, 2016
2 parents b0f83b9 + baf1e6a commit 837f02c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ env:
- TOXENV=pypy-django19
- TOXENV=py34-django19
- TOXENV=py35-django19
- TOXENV=py27-django110
- TOXENV=pypy-django110
- TOXENV=py34-django110
- TOXENV=py35-django110
docsinstall: pip install -q tox
before_install:
- nvm install node
Expand Down
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ or just made Pipeline more awesome.
* Andy Kish <agkish@gmail.com>
* Ara Anjargolian <ara818@gmail.com>
* Arnar Yngvason <arnar@hvitahusid.is>
* Austin Pua <pua.austin.anderson@gmail.com>
* Axel Haustant <noirbizarre@gmail.com>
* Balazs Kossovics <balazs.kossovics@e-loue.com>
* Ben Vinegar <ben@benv.ca>
Expand Down
10 changes: 8 additions & 2 deletions pipeline/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from collections import OrderedDict

import django
from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage
from django.utils import six
Expand All @@ -19,6 +20,11 @@ def __init__(self, storage=None):
storage = staticfiles_storage
self.storage = storage

def _get_modified_time(self, storage, prefixed_path):
if django.VERSION[:2] >= (1, 10):
return storage.get_modified_time(prefixed_path)
return storage.modified_time(prefixed_path)

def clear(self, path=""):
dirs, files = self.storage.listdir(path)
for f in files:
Expand Down Expand Up @@ -65,14 +71,14 @@ def delete_file(self, path, prefixed_path, source_storage):
if self.storage.exists(prefixed_path):
try:
# When was the target file modified last time?
target_last_modified = self.storage.modified_time(prefixed_path)
target_last_modified = self._get_modified_time(self.storage, prefixed_path)
except (OSError, NotImplementedError, AttributeError):
# The storage doesn't support ``modified_time`` or failed
pass
else:
try:
# When was the source file modified last time?
source_last_modified = source_storage.modified_time(path)
source_last_modified = self._get_modified_time(source_storage, prefixed_path)
except (OSError, NotImplementedError, AttributeError):
pass
else:
Expand Down
8 changes: 7 additions & 1 deletion pipeline/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

from pipeline.conf import settings

try:
# Support for Django 1.10 new MIDDLEWARE setting
from django.utils.deprecation import MiddlewareMixin
except ImportError: # Django < 1.10
MiddlewareMixin = object

class MinifyHTMLMiddleware(object):

class MinifyHTMLMiddleware(MiddlewareMixin):
def __init__(self):
if not settings.PIPELINE_ENABLED:
raise MiddlewareNotUsed
Expand Down
6 changes: 6 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

import django
from django.conf import settings
from django.utils import six

Expand All @@ -17,6 +18,11 @@ def _(path):

class pipeline_settings(override_settings):
def __init__(self, **kwargs):
if django.VERSION[:2] >= (1, 10):
# Django 1.10's override_settings inherits from TestContextDecorator
# and its __init__ method calls its superclass' __init__ method too,
# so we must do the same.
super(pipeline_settings, self).__init__()
self.options = {'PIPELINE': kwargs}


Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
{py27,pypy,py34}-django{16,17,18,19},py35-django19,docs
{py27,pypy,py34}-django{16,17,18,19,110},py35-django{19,110},docs

[testenv]
basepython =
Expand All @@ -15,6 +15,7 @@ deps =
django17: Django>=1.7,<1.8
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11
jinja2
jsmin==2.2.0
ply==3.4
Expand Down

0 comments on commit 837f02c

Please sign in to comment.