diff options
| author | Tom Christie | 2012-09-03 16:06:17 +0100 |
|---|---|---|
| committer | Tom Christie | 2012-09-03 16:06:17 +0100 |
| commit | 93189ec27d53d3216d452abdc2711e973a888d0c (patch) | |
| tree | 4f21c9f2e9817fb2177d81b229fb03083e39de02 /djangorestframework/urlpatterns.py | |
| parent | 149b00a070fcbfd44feee5b37096081e18356f93 (diff) | |
| download | django-rest-framework-93189ec27d53d3216d452abdc2711e973a888d0c.tar.bz2 | |
Added format_suffix_patterns, and fix up settings
Diffstat (limited to 'djangorestframework/urlpatterns.py')
| -rw-r--r-- | djangorestframework/urlpatterns.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/djangorestframework/urlpatterns.py b/djangorestframework/urlpatterns.py new file mode 100644 index 00000000..d34acf9b --- /dev/null +++ b/djangorestframework/urlpatterns.py @@ -0,0 +1,20 @@ +from django.conf.urls.defaults import url + + +def format_suffix_patterns(urlpatterns, suffix_required=False): + """ + Supplement existing urlpatterns with corrosponding patterns that also + include a '.format' suffix. Retains urlpattern ordering. + """ + ret = [] + for urlpattern in urlpatterns: + # Form our complementing '.format' urlpattern + regex = urlpattern.regex.pattern.rstrip('$') + '.(?P<format>[a-z]+)$' + view = urlpattern._callback or urlpattern._callback_str + kwargs = urlpattern.default_args + name = urlpattern.name + # Add in both the existing and the new urlpattern + if not suffix_required: + ret.append(urlpattern) + ret.append(url(regex, view, kwargs, name)) + return ret |
