Skip to content

Commit

Permalink
redirect old slug
Browse files Browse the repository at this point in the history
  • Loading branch information
remik committed Jan 8, 2014
1 parent 338d87f commit 1304b72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions basic_cms/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,10 @@ def _get_context_page(path):
self.assertEqual(_get_context_page('/').status_code, 200)
self.assertEqual(_get_context_page('/page1/').status_code, 200)
self.assertEqual(_get_context_page('/page1/').status_code, 200)
self.assertEqual(_get_context_page('/page1/page2').status_code, 200)
self.assertEqual(_get_context_page('/page1/page2/').status_code, 200)
self.assertEqual(_get_context_page('/page1/page2').status_code, 301)
self.assertEqual(_get_context_page('/page1/page2/').status_code, 301)
self.assertEqual(_get_context_page('/page1/page2/doc-%d' % doc.id
).status_code, 200)
).status_code, 301)
self.assertRaises(Http404, _get_context_page,
'/page1/page-wrong/doc-%d' % doc.id)

Expand Down
18 changes: 10 additions & 8 deletions basic_cms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class Details(object):
All is rendered with the current page's template.
"""

def __call__(self, request, path=None, lang=None, delegation=True,
**kwargs):
def __call__(self, request, path=None, lang=None, delegation=True, **kwargs):

current_page = False

Expand Down Expand Up @@ -53,6 +52,12 @@ def __call__(self, request, path=None, lang=None, delegation=True,
is_staff = self.is_user_staff(request)

current_page = self.resolve_page(request, context, is_staff)
if current_page and not current_page.is_first_root():
url = current_page.get_absolute_url(language=lang)
slug = current_page.get_complete_slug(language=lang)
current_url = request.get_full_path()
if url != path and url + '/' != current_url and slug != path:
return HttpResponsePermanentRedirect(url)

# if no pages has been found, we will try to find it via an Alias
if not current_page:
Expand Down Expand Up @@ -83,8 +88,7 @@ def __call__(self, request, path=None, lang=None, delegation=True,
if kwargs.get('only_context', False):
return context
template_name = kwargs.get('template_name', template_name)
response = render_to_response(template_name,
RequestContext(request, context))
response = render_to_response(template_name, RequestContext(request, context))
current_page = context['current_page']
# populate_xheaders(request, response, Page, current_page.id)
return response
Expand All @@ -93,8 +97,7 @@ def resolve_page(self, request, context, is_staff):
"""Return the appropriate page according to the path."""
path = context['path']
lang = context['lang']
page = Page.objects.from_path(path, lang,
exclude_drafts=(not is_staff))
page = Page.objects.from_path(path, lang, exclude_drafts=(not is_staff))
if page:
return page
# if the complete path didn't worked out properly
Expand All @@ -105,8 +108,7 @@ def resolve_page(self, request, context, is_staff):
if not settings.PAGE_USE_STRICT_URL:
path = remove_slug(path)
while path is not None:
page = Page.objects.from_path(path, lang,
exclude_drafts=(not is_staff))
page = Page.objects.from_path(path, lang, exclude_drafts=(not is_staff))
# find a match. Is the page delegating?
if page:
if page.delegate_to:
Expand Down

0 comments on commit 1304b72

Please sign in to comment.