Skip to content

Commit 6e940b2

Browse files
committed
Fold ...appcontent_parameters into ...extra_context, remove extra_path attr
1 parent fc1b783 commit 6e940b2

7 files changed

Lines changed: 25 additions & 30 deletions

File tree

docs/releases/1.3.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,14 @@ Changes and highlights
4545
* ``feincms_site`` is not available in the context anymore. It was undocumented,
4646
mostly unused and badly named anyway. If you still need this functionality you
4747
should use ``django.contrib.sites`` directly yourself.
48+
49+
* The ``_feincms_appcontent_parameters`` has been folded into the
50+
``_feincms_extra_context`` attribute on the current request. The
51+
``appcontent_parameters`` template tag is not necessary anymore
52+
(the content of ``_feincms_extra_context`` is guaranteed to be available in
53+
the template context) and has been removed.
54+
55+
* As part of the effort to reduce variables attached to the request object
56+
(acting as a replacement for global variables), ``request.extra_path``
57+
has been removed. The same information can be accessed via
58+
``request._feincms_extra_context['extra_path']``.

feincms/content/application/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def process(self, request):
284284
appcontent_parameters=self.parameters
285285
)
286286
else:
287-
path = re.sub('^' + re.escape(page_url[:-1]), '', request.path)
287+
path = request._feincms_extra_context['extra_path']
288288

289289
# Resolve the module holding the application urls.
290290
urlconf_path = self.app_config.get('urls', self.urlconf_path)
@@ -301,7 +301,7 @@ def process(self, request):
301301
#: Variables from the ApplicationContent parameters are added to request
302302
# so we can expose them to our templates via the appcontent_parameters
303303
# context_processor
304-
request._feincms_appcontent_parameters.update(self.parameters)
304+
request._feincms_extra_context.update(self.parameters)
305305

306306
view_wrapper = self.app_config.get("view_wrapper", None)
307307
if view_wrapper:

feincms/content/comments/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def render(self, **kwargs):
6060
# just the comments for right now, but if we just post to the current path
6161
# and handle it this way .. at least it works for now.
6262

63-
#extra = request._feincms_appcontent_parameters.get('page_extra_path', ())
63+
#extra = request._feincms_extra_context.get('page_extra_path', ())
6464
#if len(extra) > 0 and extra[0] == u"post-comment":
6565

6666
from django.contrib.comments.views.comments import post_comment

feincms/context_processors.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,3 @@ def add_page_if_missing(request):
1414
}
1515
except Page.DoesNotExist:
1616
return {}
17-
18-
19-
def appcontent_parameters(request):
20-
"""Add ApplicationContent parameters from the request
21-
22-
ApplicationContent adds the parameters to the request object before
23-
processing the view so we can expose them to templates here
24-
"""
25-
26-
return getattr(request, '_feincms_appcontent_parameters', {})

feincms/module/page/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ def setup_request(self, request):
418418
"""
419419
request._feincms_page = self
420420
request._feincms_extra_context = {}
421-
request.extra_path = ""
422421

423422
for fn in self.request_processors:
424423
r = fn(self, request)

feincms/module/page/templatetags/feincms_page_tags.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,14 @@ def what(self, page, args):
143143
only_existing = args.get('existing', False)
144144
exclude_current = args.get('excludecurrent', False)
145145

146-
# Preserve the trailing path when switching languages if
147-
# we are inside an ApplicationContent
146+
# Preserve the trailing path when switching languages if extra_path
147+
# exists (this is mostly the case when we are working inside an
148+
# ApplicationContent-managed page subtree)
148149
trailing_path = u''
149150
request = args.get('request', None)
150-
if hasattr(request, '_feincms_appcontent_parameters'):
151-
if request._feincms_appcontent_parameters.get('in_appcontent_subpage'):
152-
trailing_path = request.path[len(page.get_absolute_url()):]
151+
if request:
152+
# Trailing path without first slash
153+
trailing_path = request._feincms_extra_context.get('extra_path', '')[1:]
153154

154155
translations = dict((t.language, t) for t in page.available_translations())
155156
translations[page.language] = page

feincms/views/applicationcontent.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# coding=utf-8
33
# ------------------------------------------------------------------------
44

5+
import re
56
try:
67
from email.utils import parsedate
78
except ImportError: # py 2.4 compat
@@ -16,8 +17,7 @@
1617

1718

1819
def applicationcontent_request_processor(page, request):
19-
if not hasattr(request, '_feincms_appcontent_parameters'):
20-
request._feincms_appcontent_parameters = dict(in_appcontent_subpage=False)
20+
request._feincms_extra_context['in_appcontent_subpage'] = False
2121

2222
if request.path != page.get_absolute_url():
2323
# The best_match logic kicked in. See if we have at least one
@@ -26,22 +26,16 @@ def applicationcontent_request_processor(page, request):
2626
if not settings.FEINCMS_ALLOW_EXTRA_PATH:
2727
raise Http404
2828
else:
29-
request._feincms_appcontent_parameters['in_appcontent_subpage'] = True
29+
request._feincms_extra_context['in_appcontent_subpage'] = True
3030

31-
extra_path = request.path[len(page.get_absolute_url()):]
32-
extra = extra_path.strip('/').split('/')
33-
request._feincms_appcontent_parameters['page_extra_path'] = extra
34-
request.extra_path = extra_path
35-
else:
36-
request.extra_path = ""
31+
request._feincms_extra_context['extra_path'] = re.sub(
32+
'^' + re.escape(page.get_absolute_url()[:-1]), '', request.path)
3733

3834
Page.register_request_processors(applicationcontent_request_processor)
3935

4036

4137
class ApplicationContentHandler(Handler):
4238
def __call__(self, request, path=None):
43-
request._feincms_appcontent_parameters = {}
44-
4539
return self.build_response(request,
4640
Page.objects.best_match_for_path(path or request.path, raise404=True))
4741

0 commit comments

Comments
 (0)