Changeset 8215 for django/branches/gis/django/core/urlresolvers.py
- Timestamp:
- 08/05/08 12:15:33 (5 months ago)
- Files:
-
- django/branches/gis (modified) (1 prop)
- django/branches/gis/django/core/urlresolvers.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis
- Property svnmerge-integrated changed from /django/trunk:1-7978 to /django/trunk:1-8214
django/branches/gis/django/core/urlresolvers.py
r7836 r8215 7 7 (view_function, function_args, function_kwargs) 8 8 """ 9 10 import re 9 11 10 12 from django.http import Http404 … … 12 14 from django.utils.encoding import iri_to_uri, force_unicode, smart_str 13 15 from django.utils.functional import memoize 14 import re 16 from django.utils.thread_support import currentThread 15 17 16 18 try: … … 21 23 _resolver_cache = {} # Maps urlconf modules to RegexURLResolver instances. 22 24 _callable_cache = {} # Maps view and url pattern names to their view functions. 25 26 # SCRIPT_NAME prefixes for each thread are stored here. If there's no entry for 27 # the current thread (which is the only one we ever access), it is assumed to 28 # be empty. 29 _prefixes = {} 23 30 24 31 class Resolver404(Http404): … … 292 299 return get_resolver(urlconf).resolve(path) 293 300 294 def reverse(viewname, urlconf=None, args=None, kwargs=None ):301 def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None): 295 302 args = args or [] 296 303 kwargs = kwargs or {} 297 return iri_to_uri(u'/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs)) 304 if prefix is None: 305 prefix = get_script_prefix() 306 return iri_to_uri(u'%s%s' % (prefix, get_resolver(urlconf).reverse(viewname, 307 *args, **kwargs))) 298 308 299 309 def clear_url_caches(): … … 302 312 _resolver_cache.clear() 303 313 _callable_cache.clear() 314 315 def set_script_prefix(prefix): 316 """ 317 Sets the script prefix for the current thread. 318 """ 319 if not prefix.endswith('/'): 320 prefix += '/' 321 _prefixes[currentThread()] = prefix 322 323 def get_script_prefix(): 324 """ 325 Returns the currently active script prefix. Useful for client code that 326 wishes to construct their own URLs manually (although accessing the request 327 instance is normally going to be a lot cleaner). 328 """ 329 return _prefixes.get(currentThread(), u'/') 330
