Django

Code

Show
Ignore:
Timestamp:
08/05/08 12:15:33 (5 months ago)
Author:
jbronn
Message:

gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.

Files:

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  
    77    (view_function, function_args, function_kwargs) 
    88""" 
     9 
     10import re 
    911 
    1012from django.http import Http404 
     
    1214from django.utils.encoding import iri_to_uri, force_unicode, smart_str 
    1315from django.utils.functional import memoize 
    14 import re 
     16from django.utils.thread_support import currentThread 
    1517 
    1618try: 
     
    2123_resolver_cache = {} # Maps urlconf modules to RegexURLResolver instances. 
    2224_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 = {} 
    2330 
    2431class Resolver404(Http404): 
     
    292299    return get_resolver(urlconf).resolve(path) 
    293300 
    294 def reverse(viewname, urlconf=None, args=None, kwargs=None): 
     301def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None): 
    295302    args = args or [] 
    296303    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))) 
    298308 
    299309def clear_url_caches(): 
     
    302312    _resolver_cache.clear() 
    303313    _callable_cache.clear() 
     314 
     315def 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 
     323def 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