mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-21 21:41:55 +00:00
Django 1.10 compatibility for sites/redirects middleware
This commit is contained in:
parent
db54a9f0c4
commit
7a18b538e6
2 changed files with 18 additions and 2 deletions
|
|
@ -1,9 +1,18 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import django
|
||||
|
||||
from wagtail.wagtailcore.models import Site
|
||||
|
||||
|
||||
class SiteMiddleware(object):
|
||||
if django.VERSION >= (1, 10):
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
else:
|
||||
MiddlewareMixin = object
|
||||
|
||||
|
||||
|
||||
class SiteMiddleware(MiddlewareMixin):
|
||||
def process_request(self, request):
|
||||
"""
|
||||
Set request.site to contain the Site object responsible for handling this request,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,18 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import django
|
||||
from django import http
|
||||
from django.utils.six.moves.urllib.parse import urlparse
|
||||
|
||||
from wagtail.wagtailredirects import models
|
||||
|
||||
|
||||
if django.VERSION >= (1, 10):
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
else:
|
||||
MiddlewareMixin = object
|
||||
|
||||
|
||||
def get_redirect(request, path):
|
||||
try:
|
||||
return models.Redirect.get_for_site(request.site).get(old_path=path)
|
||||
|
|
@ -17,7 +24,7 @@ def get_redirect(request, path):
|
|||
|
||||
|
||||
# Originally pinched from: https://github.com/django/django/blob/master/django/contrib/redirects/middleware.py
|
||||
class RedirectMiddleware(object):
|
||||
class RedirectMiddleware(MiddlewareMixin):
|
||||
def process_response(self, request, response):
|
||||
# No need to check for a redirect for non-404 responses.
|
||||
if response.status_code != 404:
|
||||
|
|
|
|||
Loading…
Reference in a new issue