newforms-admin has a special-cased URL dispatcher in site.py. (see
#6470)
Various REST-ish frameworks have a '.*' url mapping and a similar
hacky dispatcher.
Django has a nice URL dispatcher in core/urlresolvers.py, which could
drop in and replace those ad-hoc dispatchers. Only it takes the name
of a module where you'll find urlpatterns, instead of urlpatterns
itself. Removing that one assumption to a subclass makes
RegexURLResolver immediately more useful.
I've pulled the common functionality into a BaseRegexURLResolver,
which takes (regex, url_patterns, default_kwargs) in __init__. If
url_patterns is callable, it calls it before first use and takes the
result.
RegexURLResolver then inherits from BaseRegexURLResolver, but
overrides url_patterns to lazily import the module.
I've tried using the newly factored base class in my version of a
RESTful Resource class, and so far I like the results. The naming of a
few things could use some more thought, though. A tangible upshot is
that nested resources become much easier to configure; some recent
email on this list discussed that.
Patch? I got a little carried away improving the documentation and
trying to fix #4824, so the diff looks much scarier than the change.
The result lives temporarily at
http://code.google.com/p/django-webapp/source/browse/trunk/dwa/urlresolvers.py.
I haven't run the test suite on it, but I've tried two of my apps on
it and they work. (The attempt at fixing #4824 actually caught a minor
bug in my app code...)
I wanted to get any feedback on this change before submitting a
ticket, but if people think it's a good idea, I can clean up the patch
and make a ticket.
-Ken