Opened 9 years ago

Closed 9 years ago

#24904 closed Bug (fixed)

reverse() doesn't allow for nested current_app namespaces

Reported by: Marten Kenbeek Owned by: Marten Kenbeek
Component: Core (URLs) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

reverse() doesn't split the current_app on : like it does for namespaces in the viewname. It directly compares a single namespace "level" to the full current_app variable. Take the following urlconf:

blog_patterns = [
    url(r'^comments-one/', include('comments.urls', 'comments-one', 'comments')),
    url(r'^comments-two/', include('comments.urls', 'comments-two', 'comments')),
]

urlpatterns = [
    url(r'^blog-one/', include(blog_patterns, 'blog-one', 'blog')),
    url(r'^blog-two/', include(blog_patterns, 'blog-two', 'blog')),
]

To reverse urls for blog-one:comments-one, without hard-coding the instance namespace in viewname, you might assume this would work:

reverse('blog:comments:view_name', current_app='blog-one:comments-one')

However, 'blog-one:comments-one' doesn't compare equal to either 'blog-one' or 'comments-one', so it will use the default namespace for each namespace nesting level instead, and return /blog-two/comments-two/....

This also means that this example in the docs won't work for nested namespaces:

def render_to_response(self, context, **response_kwargs):
    self.request.current_app = self.request.resolver_match.namespace
    return super(DetailView, self).render_to_response(context, **response_kwargs)

Change History (5)

comment:1 by Marten Kenbeek, 9 years ago

Owner: changed from nobody to Marten Kenbeek
Status: newassigned

comment:2 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In f0450c9b:

Fixed #24904 -- Fixed nested namespaces in current_app.

Fixed reverse() to correctly handled nested namespace lookups
in current_app.

Note: See TracTickets for help on using tickets.
Back to Top