diff --git a/README.md b/README.md index b195545..6f1f3dc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Simple terms and condition notify app ## Install ```shell -$ pip install -e git+https://github.com/rouxcode/django-tac@0.1.0#egg=django-tac +$ pip install -e git+https://github.com/rouxcode/django-tac@0.1.1#egg=django-tac ``` ## Usage @@ -20,6 +20,8 @@ INSTALLED_APPS = ( ``` add the middleware: + +django >= 1.10: ```python MIDDLEWARE = [ '...', @@ -28,6 +30,15 @@ MIDDLEWARE = [ '...' ] ```` +django <= 1.9.x +```python +MIDDLEWARE_CLASSES = [ + '...', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'tac.middleware.TACMiddlewareLegacy', + '...' +] +```` if desired load initial data ```shell diff --git a/tac/__init__.py b/tac/__init__.py index b37ef52..7226693 100644 --- a/tac/__init__.py +++ b/tac/__init__.py @@ -1,5 +1,5 @@ from __future__ import unicode_literals -__version__ = '0.1.0' +__version__ = '0.1.1' default_app_config = 'tac.apps.TACConfig' diff --git a/tac/middleware.py b/tac/middleware.py index d4a63b3..ee345d2 100644 --- a/tac/middleware.py +++ b/tac/middleware.py @@ -13,6 +13,7 @@ class TACAcceptedForm(forms.Form): ) +# django >= 1.10 class TACMiddleware(object): def __init__(self, get_response): @@ -32,3 +33,12 @@ def process_request(self, request): def process_response(self, request): response = self.get_response(request) return response + + +# django <= 1.9.x +class TACMiddlewareLegacy(object): + + def process_request(self, request): + form = TACAcceptedForm(request.GET) + if form.is_valid(): + request.session[conf.TAC_ACCEPTED_SESSION_KEY] = True diff --git a/testproject/settings.py b/testproject/settings.py index 07899b0..c571e57 100644 --- a/testproject/settings.py +++ b/testproject/settings.py @@ -63,6 +63,23 @@ 'djangocms_admin_style', ] +MIDDLEWARE_CLASSES = [ + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'django.contrib.redirects.middleware.RedirectFallbackMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django.contrib.sites.middleware.CurrentSiteMiddleware', + 'tac.middleware.TACMiddlewareLegacy', + 'cms.middleware.page.CurrentPageMiddleware', + 'cms.middleware.user.CurrentUserMiddleware', + 'cms.middleware.toolbar.ToolbarMiddleware', + 'cms.middleware.utils.ApphookReloadMiddleware', + 'cms.middleware.language.LanguageCookieMiddleware', +] MIDDLEWARE = [ 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',