From ba3c7ab460e26e8544ce61d35a8663ad80cc1d3d Mon Sep 17 00:00:00 2001 From: romain Date: Wed, 31 Aug 2016 15:43:01 +0200 Subject: [PATCH 1/3] tackle Issue #72 (Django 1.10 Compatibility) --- .gitignore | 2 ++ django_mobile/__init__.py | 1 + django_mobile/conf.py | 7 ++++++- django_mobile_tests/settings.py | 21 ++++++++++++++------- django_mobile_tests/test_base.py | 2 +- django_mobile_tests/urls.py | 9 ++++----- tox.ini | 8 +++++--- 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 33defe4..d6fcc47 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .tox/ +*.pyc +*.egg-info/ \ No newline at end of file diff --git a/django_mobile/__init__.py b/django_mobile/__init__.py index 99d0dcd..a61d22f 100644 --- a/django_mobile/__init__.py +++ b/django_mobile/__init__.py @@ -76,6 +76,7 @@ def save(self, *args, **kwargs): def get_flavour(request=None, default=None): + import pdb; pdb.set_trace() flavour = None request = request or getattr(_local, 'request', None) # get flavour from storage if enabled diff --git a/django_mobile/conf.py b/django_mobile/conf.py index 3ffc804..f872b68 100644 --- a/django_mobile/conf.py +++ b/django_mobile/conf.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from django.conf import settings as django_settings +import django CACHE_LOADER_NAME = 'django_mobile.loader.CachedLoader' DJANGO_MOBILE_LOADER = 'django_mobile.loader.Loader' @@ -30,7 +31,11 @@ class defaults(object): FLAVOURS_COOKIE_HTTPONLY = False FLAVOURS_SESSION_KEY = u'flavour' FLAVOURS_TEMPLATE_LOADERS = [] - for loader in django_settings.TEMPLATE_LOADERS: + if django.VERSION[0] < 2 and django.VERSION[1] < 8 : + TEMPLATES = django_settings.TEMPLATE_LOADERS + else: + TEMPLATES = django_settings.TEMPLATES[0]['OPTIONS']['loaders'] + for loader in TEMPLATES: if isinstance(loader, (tuple, list)) and loader[0] == CACHE_LOADER_NAME: for cached_loader in loader[1]: if cached_loader != DJANGO_MOBILE_LOADER: diff --git a/django_mobile_tests/settings.py b/django_mobile_tests/settings.py index 53c8c54..94cd57b 100644 --- a/django_mobile_tests/settings.py +++ b/django_mobile_tests/settings.py @@ -43,13 +43,20 @@ ROOT_URLCONF = 'django_mobile_tests.urls' # List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - ('django_mobile.loader.CachedLoader', ( - 'django_mobile.loader.Loader', - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', - )), -) +TEMPLATES= [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'OPTIONS':{ + 'loaders':( + ('django_mobile.loader.CachedLoader', ( + 'django_mobile.loader.Loader', + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + )), + ) + } + } +] MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', diff --git a/django_mobile_tests/test_base.py b/django_mobile_tests/test_base.py index a952d62..b93c1a0 100644 --- a/django_mobile_tests/test_base.py +++ b/django_mobile_tests/test_base.py @@ -158,7 +158,7 @@ def test_functional(self): result = result.strip() self.assertEqual(result, 'Hello .') # simulate RequestContext - result = render_to_string('index.html', context_instance=RequestContext(Mock())) + result = render_to_string('index.html', context = RequestContext(Mock()).flatten()) result = result.strip() self.assertEqual(result, 'Hello full.') set_flavour('mobile') diff --git a/django_mobile_tests/urls.py b/django_mobile_tests/urls.py index 9e5f5a9..ad9ca0f 100644 --- a/django_mobile_tests/urls.py +++ b/django_mobile_tests/urls.py @@ -8,11 +8,10 @@ def index(request): - return render_to_response('index.html', { - }, context_instance=RequestContext(request)) + return render_to_response('index.html', + context=RequestContext(request).flatten()) - -urlpatterns = patterns('', +urlpatterns = [ url(r'^$', index), url(r'^cached/$', cache_page(60*10)(index)), -) +] diff --git a/tox.ini b/tox.ini index 2767fb0..593f656 100644 --- a/tox.ini +++ b/tox.ini @@ -2,18 +2,20 @@ minversion = 1.8 envlist = py26-{15,16}, - py27-{15,16,17,18,19,master}, + py27-{15,16,17,18,19,110,master}, py33-{17,18,master}, - py34-{17,18,19,master}, - pypy-{15,16,17,18,19,master} + py34-{17,18,19,110,master}, + pypy-{15,16,17,18,19,110,master} [testenv] commands = python runtests.py deps = + pdbpp 15: Django >= 1.5, < 1.6 16: Django >= 1.6, < 1.7 17: Django >= 1.7, < 1.8 18: Django >= 1.8, < 1.9 19: Django >= 1.9, < 1.10 + 110: Django >= 1.10, <1.11 master: https://github.com/django/django/tarball/master#egg=Django -r{toxinidir}/requirements/tests.txt From f9b88050d77277ae79f81ba8615c653edad2f9f4 Mon Sep 17 00:00:00 2001 From: romain Date: Wed, 31 Aug 2016 15:49:02 +0200 Subject: [PATCH 2/3] Forgot to remove pdb --- django_mobile/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/django_mobile/__init__.py b/django_mobile/__init__.py index a61d22f..99d0dcd 100644 --- a/django_mobile/__init__.py +++ b/django_mobile/__init__.py @@ -76,7 +76,6 @@ def save(self, *args, **kwargs): def get_flavour(request=None, default=None): - import pdb; pdb.set_trace() flavour = None request = request or getattr(_local, 'request', None) # get flavour from storage if enabled From a405543aaba2b8ee48ca91f3b8a900553dfa9e8a Mon Sep 17 00:00:00 2001 From: romain Date: Wed, 31 Aug 2016 15:51:54 +0200 Subject: [PATCH 3/3] put back TEMPLATE_LOADERS for compatibility with older version --- django_mobile_tests/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/django_mobile_tests/settings.py b/django_mobile_tests/settings.py index 94cd57b..9900f45 100644 --- a/django_mobile_tests/settings.py +++ b/django_mobile_tests/settings.py @@ -58,6 +58,8 @@ } ] +TEMPLATE_LOADERS = TEMPLATES[0]['OPTIONS']['loaders'] + MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',