Jump to >

djblets.urls.resolvers

class DynamicURLResolver(regex=u'', app_name=None, namespace=None)[source]

Bases: django.core.urlresolvers.RegexURLResolver

A URL resolver that allows for dynamically altering URL patterns.

A standard RegexURLResolver expects that a list of URL patterns will be set once and never again change. In most applications, this is a good assumption. However, some that are more specialized may need to be able to swap in URL patterns dynamically. For example, those that can plug in third-party extensions.

DynamicURLResolver makes it easy to add and remove URL patterns. Any time the list of URL patterns changes, they’ll be immediately available for all URL resolution and reversing.

The usage is very simple:

dynamic_patterns = DynamicURLResolver()
urlpatterns = [dynamic_patterns]

dynamic_patterns.add_patterns([
    url(...),
    url(...),
])

DynamicURLResolver will handle managing all the lookup caches to ensure that there won’t be any stale entries affecting any dynamic URL patterns.

__init__(regex=u'', app_name=None, namespace=None)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

url_patterns[source]

Returns the current list of URL patterns.

This is a simplified version of RegexURLResolver.url_patterns that simply returns the preset list of patterns. Unlike the original function, we don’t care if the list is empty.

add_patterns(patterns)[source]

Adds a list of URL patterns.

The patterns will be made immediately available for use for any lookups or reversing.

remove_patterns(patterns)[source]

Removes a list of URL patterns.

These patterns will no longer be able to be looked up or reversed.

resolver_chain[source]

Returns every RegexURLResolver between here and the root.

The list of resolvers is cached in order to prevent having to locate the resolvers more than once.