summaryrefslogtreecommitdiff
path: root/django/core/urlresolvers.py
diff options
context:
space:
mode:
authorChristopher Long <indirecthit@gmail.com>2007-06-17 22:18:54 +0000
committerChristopher Long <indirecthit@gmail.com>2007-06-17 22:18:54 +0000
commitae22b6d403dcf25098c77f0dfcf59ae58b186461 (patch)
treec37fc631e99a7e4d909d6b6d236f495003731ea7 /django/core/urlresolvers.py
parent0cf7bc439129c66df8d64601e885f83b256b4f25 (diff)
per-object-permissions: Merged to trunk [5486] NOTE: Not fully tested, will be working on this over the next few weeks.
git-svn-id: http://code.djangoproject.com/svn/django/branches/per-object-permissions@5488 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/urlresolvers.py')
-rw-r--r--django/core/urlresolvers.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index 93c9c30cca..38b3263da1 100644
--- a/django/core/urlresolvers.py
+++ b/django/core/urlresolvers.py
@@ -16,7 +16,7 @@ class Resolver404(Http404):
class NoReverseMatch(Exception):
# Don't make this raise an error when used in a template.
- silent_variable_failure = True
+ silent_variable_failure = True
def get_mod_func(callback):
# Converts 'django.views.news.stories.story_detail' to
@@ -88,7 +88,7 @@ class MatchChecker(object):
return str(value) # TODO: Unicode?
class RegexURLPattern(object):
- def __init__(self, regex, callback, default_args=None):
+ def __init__(self, regex, callback, default_args=None, name=None):
# regex is a string representing a regular expression.
# callback is either a string like 'foo.views.news.stories.story_detail'
# which represents the path to a module and a view function name, or a
@@ -100,6 +100,15 @@ class RegexURLPattern(object):
self._callback = None
self._callback_str = callback
self.default_args = default_args or {}
+ self.name = name
+
+ def add_prefix(self, prefix):
+ """
+ Adds the prefix string to a string-based callback.
+ """
+ if not prefix or not hasattr(self, '_callback_str'):
+ return
+ self._callback_str = prefix + '.' + self._callback_str
def resolve(self, path):
match = self.regex.search(path)
@@ -110,7 +119,7 @@ class RegexURLPattern(object):
kwargs = match.groupdict()
if kwargs:
args = ()
- if not kwargs:
+ else:
args = match.groups()
# In both cases, pass any extra_kwargs as **kwargs.
kwargs.update(self.default_args)
@@ -205,14 +214,15 @@ class RegexURLResolver(object):
try:
lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name)
except (ImportError, AttributeError):
- raise NoReverseMatch
+ if func_name != '':
+ raise NoReverseMatch
for pattern in self.urlconf_module.urlpatterns:
if isinstance(pattern, RegexURLResolver):
try:
return pattern.reverse_helper(lookup_view, *args, **kwargs)
except NoReverseMatch:
continue
- elif pattern.callback == lookup_view:
+ elif pattern.callback == lookup_view or pattern.name == lookup_view:
try:
return pattern.reverse_helper(*args, **kwargs)
except NoReverseMatch: