Permalink
Browse files

fixes #1678

  • Loading branch information...
digi604 committed Jun 14, 2013
1 parent cd2fa36 commit ed21c1b2438bab94e1803e6e4f173eb0c2013bb3
View
@@ -93,7 +93,7 @@ def resolve_page_id(self, path):
raise Resolver404, {'tried': tried, 'path': new_path}
-def recurse_patterns(path, pattern_list, page_id):
+def recurse_patterns(path, pattern_list, page_id, default_args=None):
"""
Recurse over a list of to-be-hooked patterns for a given path prefix
"""
@@ -109,12 +109,19 @@ def recurse_patterns(path, pattern_list, page_id):
resolver = RegexURLResolver(regex, 'cms_appresolver',
pattern.default_kwargs, pattern.app_name, pattern.namespace)
resolver.page_id = page_id
+ # include default_args
+ args = pattern.default_kwargs
+ if default_args:
+ args.update(default_args)
# see lines 243 and 236 of urlresolvers.py to understand the next line
- resolver._urlconf_module = recurse_patterns(regex, pattern.url_patterns, page_id)
+ resolver._urlconf_module = recurse_patterns(regex, pattern.url_patterns, page_id, args)
else:
# Re-do the RegexURLPattern with the new regular expression
+ args = pattern.default_args
+ if default_args:
+ args.update(default_args)
resolver = RegexURLPattern(regex, pattern.callback,
- pattern.default_args, pattern.name)
+ args, pattern.name)
resolver.page_id = page_id
newpatterns.append(resolver)
return newpatterns
@@ -5,5 +5,5 @@
"""
urlpatterns = patterns('cms.test_utils.project.sampleapp.views',
- url(r'^current-app/$', 'current_app', name='current-app'),
+ url(r'^current-app/$', 'current_app', name='current-app' ),
)
@@ -3,9 +3,10 @@
{% load cms_tags %}
{% block content %}
- <h2>Sample application page - on page {% page_attribute page_title %}</h2>
- <h3>{{ message }}</h3>
- {{ block.super }}
- {% url 'extra_first' %}
- {% url 'extra_second' %}
+<h2>Sample application page - on page {% page_attribute page_title %}</h2>
+<h3>{{ message }}</h3>
+<h4>{{ opts }}</h4>
+{{ block.super }}
+{% if app %}{% url 'namespaced_app_ns:extra_first' %}{% else %}{% url 'extra_first' %}{% endif %}
+{% if app %}{% url 'namespaced_app_ns:extra_second' %}{% else %}{% url 'extra_second' %}{% endif %}
{% endblock content %}
@@ -14,5 +14,5 @@
url(r'^category/(?P<id>[0-9]+)/$', 'category_view', name='category_view'),
url(r'^notfound/$', 'notfound', name='notfound'),
url(r'^extra_1/$', 'extra_view', {'message': 'test urlconf'}, name='extra_first'),
- url(r'^', include('cms.test_utils.project.sampleapp.urls_extra')),
+ url(r'^', include('cms.test_utils.project.sampleapp.urls_extra'), {'opts': 'someopts'}),
)
@@ -1,4 +1,4 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import *
"""
Also used in cms.tests.ApphooksTestCase
@@ -26,7 +26,10 @@ def category_view(request, id):
def extra_view(request, **kw):
- context = RequestContext(request, kw)
+ app = resolve(request.path).namespace
+ kw['app'] = app
+ response_kwargs = {'current_app': app, 'dict_': kw}
+ context = RequestContext(request, **response_kwargs)
return render_to_response("sampleapp/extra.html", context)
View
@@ -297,6 +297,18 @@ def test_get_i18n_apphook_with_explicit_current_app(self):
path = reverse('namespaced_app_ns:current-app', current_app="instance_2")
path = reverse('namespaced_app_ns:current-app')
+ def test_apphook_include_extra_parameters(self):
+ with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.second_urls_for_apphook_tests'):
+ titles = self.create_base_structure(NS_APP_NAME, ['en', 'de'], 'instance_1')
+ with force_language("en"):
+ path = reverse('namespaced_app_ns:extra_second')
+ request = self.get_request(path)
+ request.LANGUAGE_CODE = 'en'
+ response = self.client.get(path)
+ self.assertEquals(response.status_code, 200)
+ self.assertTemplateUsed(response, 'sampleapp/extra.html')
+ self.assertContains(response, 'someopts')
+
def test_get_sub_page_for_apphook_with_explicit_current_app(self):
with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.second_urls_for_apphook_tests'):
en_title = self.create_base_structure(NS_APP_NAME, 'en', 'instance_ns')

0 comments on commit ed21c1b

Please sign in to comment.