2005-08-06 04:50:19 +08:00
|
|
|
from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
|
2007-05-27 19:09:52 +08:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
2005-07-13 09:25:57 +08:00
|
|
|
|
2007-04-01 15:25:20 +08:00
|
|
|
__all__ = ['handler404', 'handler500', 'include', 'patterns', 'url']
|
2005-07-13 09:25:57 +08:00
|
|
|
|
|
|
|
handler404 = 'django.views.defaults.page_not_found'
|
|
|
|
handler500 = 'django.views.defaults.server_error'
|
|
|
|
|
2009-07-17 00:16:13 +08:00
|
|
|
def include(arg, namespace=None, app_name=None):
|
|
|
|
if isinstance(arg, tuple):
|
|
|
|
# callable returning a namespace hint
|
|
|
|
if namespace:
|
|
|
|
raise ImproperlyConfigured('Cannot override the namespace for a dynamic module that provides a namespace')
|
|
|
|
urlconf_module, app_name, namespace = arg
|
|
|
|
else:
|
|
|
|
# No namespace hint - use manually provided namespace
|
|
|
|
urlconf_module = arg
|
|
|
|
return (urlconf_module, app_name, namespace)
|
2005-07-13 09:25:57 +08:00
|
|
|
|
2007-04-01 15:25:20 +08:00
|
|
|
def patterns(prefix, *args):
|
2005-07-13 09:25:57 +08:00
|
|
|
pattern_list = []
|
2007-04-01 15:25:20 +08:00
|
|
|
for t in args:
|
|
|
|
if isinstance(t, (list, tuple)):
|
2007-04-26 19:17:19 +08:00
|
|
|
t = url(prefix=prefix, *t)
|
|
|
|
elif isinstance(t, RegexURLPattern):
|
|
|
|
t.add_prefix(prefix)
|
|
|
|
pattern_list.append(t)
|
2005-07-13 09:25:57 +08:00
|
|
|
return pattern_list
|
2007-04-01 15:25:20 +08:00
|
|
|
|
|
|
|
def url(regex, view, kwargs=None, name=None, prefix=''):
|
2009-07-17 00:16:13 +08:00
|
|
|
if isinstance(view, (list,tuple)):
|
2007-04-01 15:25:20 +08:00
|
|
|
# For include(...) processing.
|
2009-07-17 00:16:13 +08:00
|
|
|
urlconf_module, app_name, namespace = view
|
|
|
|
return RegexURLResolver(regex, urlconf_module, kwargs, app_name=app_name, namespace=namespace)
|
2007-04-01 15:25:20 +08:00
|
|
|
else:
|
2007-05-27 19:09:52 +08:00
|
|
|
if isinstance(view, basestring):
|
|
|
|
if not view:
|
|
|
|
raise ImproperlyConfigured('Empty URL pattern view name not permitted (for pattern %r)' % regex)
|
|
|
|
if prefix:
|
|
|
|
view = prefix + '.' + view
|
2007-04-29 17:41:46 +08:00
|
|
|
return RegexURLPattern(regex, view, kwargs, name)
|
2007-04-01 15:25:20 +08:00
|
|
|
|