aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework
diff options
context:
space:
mode:
authorTom Christie2012-10-09 12:01:17 +0100
committerTom Christie2012-10-09 12:01:17 +0100
commit115e61be0900b3d5dd93ff84f20629311aceff9f (patch)
treef8a521e65ee4a3671acd3c512cddc1f613c97d82 /rest_framework
parentdc52ceaaa273f3d3b5248c2ebf655a747fa516db (diff)
downloaddjango-rest-framework-115e61be0900b3d5dd93ff84f20629311aceff9f.tar.bz2
Added quickstart guide
Diffstat (limited to 'rest_framework')
-rw-r--r--rest_framework/decorators.py3
-rw-r--r--rest_framework/templates/rest_framework/base.html2
-rw-r--r--rest_framework/urlpatterns.py25
3 files changed, 26 insertions, 4 deletions
diff --git a/rest_framework/decorators.py b/rest_framework/decorators.py
index 2adbff24..948973ae 100644
--- a/rest_framework/decorators.py
+++ b/rest_framework/decorators.py
@@ -13,7 +13,8 @@ def api_view(http_method_names):
class WrappedAPIView(APIView):
pass
- WrappedAPIView.http_method_names = [method.lower() for method in http_method_names]
+ allowed_methods = set(http_method_names) | set(('options',))
+ WrappedAPIView.http_method_names = [method.lower() for method in allowed_methods]
def handler(self, *args, **kwargs):
return func(*args, **kwargs)
diff --git a/rest_framework/templates/rest_framework/base.html b/rest_framework/templates/rest_framework/base.html
index f213554b..abf3672f 100644
--- a/rest_framework/templates/rest_framework/base.html
+++ b/rest_framework/templates/rest_framework/base.html
@@ -39,7 +39,7 @@
{% if user.is_authenticated %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
- Welcome, {{ user }}
+ Logged in as {{ user }}
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
diff --git a/rest_framework/urlpatterns.py b/rest_framework/urlpatterns.py
index a040b621..386c78a2 100644
--- a/rest_framework/urlpatterns.py
+++ b/rest_framework/urlpatterns.py
@@ -2,13 +2,34 @@ from django.conf.urls.defaults import url
from rest_framework.settings import api_settings
-def format_suffix_patterns(urlpatterns, suffix_required=False, suffix_kwarg=None):
+def format_suffix_patterns(urlpatterns, suffix_required=False,
+ suffix_kwarg=None, allowed=None):
"""
Supplement existing urlpatterns with corrosponding patterns that also
include a '.format' suffix. Retains urlpattern ordering.
+
+ suffix_required:
+ If `True`, only suffixed URLs will be generated, and non-suffixed
+ URLs will not be used. Defaults to `False`.
+
+ suffix_kwarg:
+ The name of the kwarg that will be passed to the view.
+ Defaults to 'format'.
+
+ allowed:
+ An optional tuple/list of allowed suffixes. eg ['json', 'api']
+ Defaults to `None`, which allows any suffix.
+
"""
suffix_kwarg = suffix_kwarg or api_settings.FORMAT_SUFFIX_KWARG
- suffix_pattern = r'\.(?P<%s>[a-z]+)$' % suffix_kwarg
+ if allowed:
+ if len(allowed) == 1:
+ allowed_pattern = allowed[0]
+ else:
+ allowed_pattern = '(%s)' % '|'.join(allowed)
+ suffix_pattern = r'\.(?P<%s>%s)$' % (suffix_kwarg, allowed_pattern)
+ else:
+ suffix_pattern = r'\.(?P<%s>[a-z]+)$' % suffix_kwarg
ret = []
for urlpattern in urlpatterns: