Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'middleware-path' of https://github.com/mrj0/django-cms-…

…redirects into mrj0-middleware-path
  • Loading branch information...
commit ddaba9e141d252b9f1a0671f153f4277ed1cd878 2 parents 8c802b6 + 973b472
@andrewschoen andrewschoen authored
Showing with 19 additions and 19 deletions.
  1. +19 −19 cms_redirects/middleware.py
View
38 cms_redirects/middleware.py
@@ -6,28 +6,28 @@ class RedirectFallbackMiddleware(object):
def process_exception(self, request, exception):
if isinstance(exception, http.Http404):
path = request.get_full_path()
- try:
- r = CMSRedirect.objects.get(site__id__exact=settings.SITE_ID, old_path=path)
- except CMSRedirect.DoesNotExist:
- r = None
- if r is None and settings.APPEND_SLASH:
- # Try removing the trailing slash.
try:
- r = CMSRedirect.objects.get(site__id__exact=settings.SITE_ID,
- old_path=path[:path.rfind('/')]+path[path.rfind('/')+1:])
+ r = CMSRedirect.objects.get(site__id__exact=settings.SITE_ID, old_path=path)
except CMSRedirect.DoesNotExist:
- pass
- if r is not None:
- if r.page:
+ r = None
+ if r is None and settings.APPEND_SLASH:
+ # Try removing the trailing slash.
+ try:
+ r = CMSRedirect.objects.get(site__id__exact=settings.SITE_ID,
+ old_path=path[:path.rfind('/')]+path[path.rfind('/')+1:])
+ except CMSRedirect.DoesNotExist:
+ pass
+ if r is not None:
+ if r.page:
+ if r.response_code == '302':
+ return http.HttpResponseRedirect(r.page.get_absolute_url())
+ else:
+ return http.HttpResponsePermanentRedirect(r.page.get_absolute_url())
+ if r.new_path == '':
+ return http.HttpResponseGone()
if r.response_code == '302':
- return http.HttpResponseRedirect(r.page.get_absolute_url())
+ return http.HttpResponseRedirect(r.new_path)
else:
- return http.HttpResponsePermanentRedirect(r.page.get_absolute_url())
- if r.new_path == '':
- return http.HttpResponseGone()
- if r.response_code == '302':
- return http.HttpResponseRedirect(r.new_path)
- else:
- return http.HttpResponsePermanentRedirect(r.new_path)
+ return http.HttpResponsePermanentRedirect(r.new_path)
Please sign in to comment.
Something went wrong with that request. Please try again.