Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ by :mod:`feincms.module.page`.
random gunk after a valid page URL. The standard behavior is to raise a 404
if extra path elements aren't handled by a content type's ``process()`` method.

``FEINCMS_ALLOW_EXTRA_PATH_PREFIX``: Defaults to ``()``. Define a tuple of
strings to allow predetermined url prefixes to be ignored. The standard behavior
is to raise a 404 if extra path elements aren't handled by a content type's
``process()`` method.

``FEINCMS_TRANSLATION_POLICY``: Defaults to ``STANDARD``. How to switch
languages.

Expand Down
3 changes: 2 additions & 1 deletion feincms/content/application/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import

from collections import OrderedDict
from email.utils import parsedate
from functools import partial, wraps
from time import mktime
Expand Down Expand Up @@ -171,7 +172,7 @@ class ApplicationContent(models.Model):
# MyBlogApp for blog <slug>")
parameters = JSONField(null=True, editable=False)

ALL_APPS_CONFIG = {}
ALL_APPS_CONFIG = OrderedDict()

class Meta:
abstract = True
Expand Down
10 changes: 10 additions & 0 deletions feincms/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
'FEINCMS_ALLOW_EXTRA_PATH',
False)

# ------------------------------------------------------------------------
#: Allow random prefixes to be ignored when using
#: `Page.best_match_for_path()` and the `add_page_if_missing` context
#: processor.
#: Defaults to an empty tuple.
FEINCMS_ALLOW_EXTRA_PATH_PREFIX = getattr(
settings,
'FEINCMS_ALLOW_EXTRA_PATH_PREFIX',
())

# ------------------------------------------------------------------------
#: How to switch languages.
#: * ``'STANDARD'``: The page a user navigates to sets the site's language
Expand Down
4 changes: 4 additions & 0 deletions feincms/module/page/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def best_match_for_path(self, path, raise404=False):

paths = ['/']
path = path.strip('/')

for prefix in settings.FEINCMS_ALLOW_EXTRA_PATH_PREFIX:
if path.startswith('%s/' % prefix):
path = path[len(prefix)+1:]

if path:
tokens = path.split('/')
Expand Down
21 changes: 21 additions & 0 deletions tests/testapp/tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,9 @@ def test_19_page_manager(self):
Page.objects.best_match_for_path(
page.get_absolute_url() + 'something/hello/'))

# test `FEINCMS_ALLOW_EXTRA_PATH`
old = feincms_settings.FEINCMS_ALLOW_EXTRA_PATH
old_path = request.path
request.path += 'hello/'

feincms_settings.FEINCMS_ALLOW_EXTRA_PATH = False
Expand All @@ -1075,6 +1077,25 @@ def test_19_page_manager(self):
page, Page.objects.for_request(request, best_match=True))

feincms_settings.FEINCMS_ALLOW_EXTRA_PATH = old
request.path = old_path

# test FEINCMS_ALLOW_EXTRA_PATH_PREFIX
old = feincms_settings.FEINCMS_ALLOW_EXTRA_PATH_PREFIX
old_path = request.path
request.path = 'prefix' + request.path

feincms_settings.FEINCMS_ALLOW_EXTRA_PATH = ()
self.assertRaises(
Page.DoesNotExist,
lambda: Page.objects.best_match_for_path(request.path))

feincms_settings.FEINCMS_ALLOW_EXTRA_PATH_PREFIX = ('prefix',)
self.assertIsInstance(
Page.objects.best_match_for_path(request.path),
Page)

feincms_settings.FEINCMS_ALLOW_EXTRA_PATH_PREFIX = old
request.path = old_path

page_id = id(request._feincms_page)
p = Page.objects.for_request(request)
Expand Down