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)) if page: return page # if the complete path didn't worked out properly # and if didn't used PAGE_USE_STRICT_URL setting we gonna # try to see if it might be a delegation page. # To do that we remove the right part of the url and try again # to find a page that match 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)) # find a match. Is the page delegating? if page: if page.delegate_to: return page path = remove_slug(path) return None
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)) if page: return page # if the complete path didn't worked out properly # and if didn't used PAGE_USE_STRICT_URL setting we gonna # try to see if it might be a delegation page. # To do that we remove the right part of the url and try again # to find a page that match 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)) # find a match. Is the page delegating? if page: if page.delegate_to: return page path = remove_slug(path) return None
def test_remove_slug(self): """Test the remove slug function.""" self.assertEqual(remove_slug('hello/world/toto'), 'hello/world') self.assertEqual(remove_slug('hello/world'), 'hello') self.assertEqual(remove_slug('/hello/world/'), 'hello') self.assertEqual(remove_slug('hello'), None)
def test_remove_slug(self): """Test the remove slug function.""" self.assertEqual(remove_slug('hello/world/toto'), 'hello/world') self.assertEqual(remove_slug('hello/world'), 'hello') self.assertEqual(remove_slug('/hello/world/'), 'hello') self.assertEqual(remove_slug('hello'), None)