Ticket #682: fully-decoupled-urlconfs-v2.diff
File fully-decoupled-urlconfs-v2.diff, 1.2 KB (added by , 19 years ago) |
---|
-
django/conf/urls/defaults.py
1 import sys 1 2 from django.core.urlresolvers import RegexURLPattern, RegexURLResolver 2 3 3 __all__ = ['handler404', 'handler500', 'include', 'patterns' ]4 __all__ = ['handler404', 'handler500', 'include', 'patterns', 'prefix'] 4 5 5 6 handler404 = 'django.views.defaults.page_not_found' 6 7 handler500 = 'django.views.defaults.server_error' 7 8 8 9 include = lambda urlconf_module: [urlconf_module] 9 10 11 def prefix(postfix): 12 """ 13 Figures out and adds a prefix to the given postfix by 14 examining the module name of the calling URLconf. 15 16 if the given postfix is: 17 'views.polls.vote' 18 and this function is called from: 19 'myproject.apps.polls.urls' 20 the return value will be: 21 'myproject.apps.polls.views.polls.vote' 22 """ 23 f = sys._getframe(1) 24 module = f.f_globals["__name__"] 25 segs = module.split(".") 26 segs = segs[:3] 27 segs.append(postfix) 28 return ".".join(segs) 29 10 30 def patterns(prefix, *tuples): 11 31 pattern_list = [] 12 32 for t in tuples: