Skip to content

Commit

Permalink
add django 1.8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
wullerot committed May 25, 2018
1 parent 3d5b8d8 commit 02d6916
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Simple terms and condition notify app

## Install
```shell
$ pip install -e git+https://github.com/rouxcode/[email protected].0#egg=django-tac
$ pip install -e git+https://github.com/rouxcode/[email protected].1#egg=django-tac
```

## Usage
Expand All @@ -20,6 +20,8 @@ INSTALLED_APPS = (
```

add the middleware:

django >= 1.10:
```python
MIDDLEWARE = [
'...',
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tac/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import unicode_literals


__version__ = '0.1.0'
__version__ = '0.1.1'
default_app_config = 'tac.apps.TACConfig'
10 changes: 10 additions & 0 deletions tac/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TACAcceptedForm(forms.Form):
)


# django >= 1.10
class TACMiddleware(object):

def __init__(self, get_response):
Expand All @@ -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
17 changes: 17 additions & 0 deletions testproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 02d6916

Please sign in to comment.