Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support Django 1.10 #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions django_mobile/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from django_mobile import flavour_storage
from django_mobile import set_flavour, _init_flavour
from django_mobile.conf import settings
from django.utils.deprecation import MiddlewareMixin


class SetFlavourMiddleware(object):
class SetFlavourMiddleware(MiddlewareMixin):
def process_request(self, request):
_init_flavour(request)

Expand All @@ -18,7 +19,7 @@ def process_response(self, request, response):
return response


class MobileDetectionMiddleware(object):
class MobileDetectionMiddleware(MiddlewareMixin):
user_agents_test_match = (
"w3c ", "acs-", "alav", "alca", "amoi", "audi",
"avan", "benq", "bird", "blac", "blaz", "brew",
Expand All @@ -44,7 +45,8 @@ class MobileDetectionMiddleware(object):
))
http_accept_regex = re.compile("application/vnd\.wap\.xhtml\+xml", re.IGNORECASE)

def __init__(self):
def __init__(self, get_response=None, *args, **kwargs):
self.get_response = get_response
user_agents_test_match = r'^(?:%s)' % '|'.join(self.user_agents_test_match)
self.user_agents_test_match_regex = re.compile(user_agents_test_match, re.IGNORECASE)
self.user_agents_test_search_regex = re.compile(self.user_agents_test_search, re.IGNORECASE)
Expand Down
48 changes: 28 additions & 20 deletions django_mobile_tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,42 @@
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',
)),
)

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django_mobile.middleware.MobileDetectionMiddleware',
'django_mobile.middleware.SetFlavourMiddleware',
)

TEMPLATE_DIRS = (
os.path.join(PROJECT_ROOT, 'templates'),
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(PROJECT_ROOT, 'templates'),
],
'OPTIONS': {
'context_processors': [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django_mobile.context_processors.flavour",
"django_mobile.context_processors.is_mobile",
],
'loaders': [
('django_mobile.loader.CachedLoader', (
'django_mobile.loader.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)),
]
},
},
]

TEMPLATE_LOADERS = TEMPLATES[0]['OPTIONS']['loaders']

INSTALLED_APPS = (
'django.contrib.auth',
Expand All @@ -74,15 +91,6 @@
'django_mobile_tests',
)

TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django_mobile.context_processors.flavour",
"django_mobile.context_processors.is_mobile",
)


import django
if django.VERSION < (1, 6):
Expand Down
2 changes: 1 addition & 1 deletion django_mobile_tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', request=RequestContext(Mock()))
result = result.strip()
self.assertEqual(result, 'Hello full.')
set_flavour('mobile')
Expand Down
10 changes: 4 additions & 6 deletions django_mobile_tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
from django.conf.urls.defaults import *
except ImportError:
from django.conf.urls import *
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import render
from django_mobile.cache import cache_page


def index(request):
return render_to_response('index.html', {
}, context_instance=RequestContext(request))
return render(request, 'index.html', {})


urlpatterns = patterns('',
urlpatterns = [
url(r'^$', index),
url(r'^cached/$', cache_page(60*10)(index)),
)
]
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ deps =
17: Django >= 1.7, < 1.8
18: Django >= 1.8, < 1.9
19: Django >= 1.9, < 1.10
20: Django >= 1.10
master: https://github.com/django/django/tarball/master#egg=Django
-r{toxinidir}/requirements/tests.txt