aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/urlpatterns.py
diff options
context:
space:
mode:
authorTom Christie2012-09-07 09:36:52 +0100
committerTom Christie2012-09-07 09:36:52 +0100
commit01d6a0899e4435417f774196b08e0613bd0a51f7 (patch)
tree118d29048d2df9100928830c6c65d45e590f0c6e /djangorestframework/urlpatterns.py
parentc648f2786f37ffe0b64ed2d85de2b7b491ee341b (diff)
downloaddjango-rest-framework-01d6a0899e4435417f774196b08e0613bd0a51f7.tar.bz2
Bits of cleanup
Diffstat (limited to 'djangorestframework/urlpatterns.py')
-rw-r--r--djangorestframework/urlpatterns.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/djangorestframework/urlpatterns.py b/djangorestframework/urlpatterns.py
index d34acf9b..6cef721e 100644
--- a/djangorestframework/urlpatterns.py
+++ b/djangorestframework/urlpatterns.py
@@ -1,15 +1,19 @@
from django.conf.urls.defaults import url
+from djangorestframework.settings import api_settings
-def format_suffix_patterns(urlpatterns, suffix_required=False):
+def format_suffix_patterns(urlpatterns, suffix_required=False, suffix_kwarg=None):
"""
Supplement existing urlpatterns with corrosponding patterns that also
include a '.format' suffix. Retains urlpattern ordering.
"""
+ suffix_kwarg = suffix_kwarg or api_settings.FORMAT_SUFFIX_KWARG
+ suffix_pattern = '.(?P<%s>[a-z]+)$' % suffix_kwarg
+
ret = []
for urlpattern in urlpatterns:
# Form our complementing '.format' urlpattern
- regex = urlpattern.regex.pattern.rstrip('$') + '.(?P<format>[a-z]+)$'
+ regex = urlpattern.regex.pattern.rstrip('$') + suffix_pattern
view = urlpattern._callback or urlpattern._callback_str
kwargs = urlpattern.default_args
name = urlpattern.name