From b8559c619288be71d1f0709d3c4e622580da7e2d Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 7 Sep 2012 10:41:16 +0100 Subject: [PATCH] Fixing up browseable API for rest framework 2 --- djangorestframework/renderers.py | 2 + .../templates/djangorestframework/api.txt | 2 +- .../templates/djangorestframework/base.html | 82 ++++++++++--------- 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/djangorestframework/renderers.py b/djangorestframework/renderers.py index 6a280de76..4f8225b12 100644 --- a/djangorestframework/renderers.py +++ b/djangorestframework/renderers.py @@ -10,6 +10,7 @@ from django.template import RequestContext, loader from django.utils import simplejson as json from djangorestframework.compat import yaml +from djangorestframework.settings import api_settings from djangorestframework.utils import dict2xml from djangorestframework.utils import encoders from djangorestframework.utils.breadcrumbs import get_breadcrumbs @@ -344,6 +345,7 @@ class DocumentingTemplateRenderer(BaseRenderer): 'post_form': post_form_instance, 'FORMAT_PARAM': self._FORMAT_QUERY_PARAM, 'METHOD_PARAM': getattr(self.view, '_METHOD_PARAM', None), + 'api_settings': api_settings }) ret = template.render(context) diff --git a/djangorestframework/templates/djangorestframework/api.txt b/djangorestframework/templates/djangorestframework/api.txt index b584952cb..b2f071d64 100644 --- a/djangorestframework/templates/djangorestframework/api.txt +++ b/djangorestframework/templates/djangorestframework/api.txt @@ -2,7 +2,7 @@ {{ description }} -HTTP/1.0 {{ response.status }} {{ response.status_text }} +HTTP {{ response.status }} {{ response.status_text }} {% for key, val in response.headers.items %}{{ key }}: {{ val }} {% endfor %} {{ content }}{% endautoescape %} diff --git a/djangorestframework/templates/djangorestframework/base.html b/djangorestframework/templates/djangorestframework/base.html index 7a3e71eb7..d33c53930 100644 --- a/djangorestframework/templates/djangorestframework/base.html +++ b/djangorestframework/templates/djangorestframework/base.html @@ -1,17 +1,17 @@ {% load url from future %} - - {% load urlize_quoted_links %} {% load add_query_param %} {% load optional_login %} {% load static %} + + - - - {% block extrastyle %}{% endblock %} - {% block title %}Django REST framework - {{ name }}{% endblock %} - {% block extrahead %}{% endblock %} + + + {% block extrastyle %}{% endblock %} + {% block title %}Django REST framework - {{ name }}{% endblock %} + {% block extrahead %}{% endblock %} {% block blockbots %}{% endblock %} @@ -37,19 +37,19 @@ + {{ breadcrumb_name }} {% if not forloop.last %}›{% endif %} + {% endfor %} + {% endblock %} + - -
+ +
- {% if 'OPTIONS' in allowed_methods %} + {% if 'OPTIONS' in allowed_methods and api_settings.FORM_METHOD_OVERRIDE %}
- {% csrf_token %} - - + {% csrf_token %} + +
{% endif %} @@ -57,7 +57,7 @@

{{ name }}

{{ description }}

-
{{ response.status_code }} {{ response.status_text }}{% autoescape off %}
+	    
HTTP {{ response.status_code }} {{ response.status_text }}{% autoescape off %}
 {% for key, val in response.items %}{{ key }}: {{ val|urlize_quoted_links }}
 {% endfor %}
 {{ content|urlize_quoted_links }}
{% endautoescape %}
@@ -78,21 +78,24 @@ {% endif %} + {% comment %} + DROP POST/PUT/DELETE until the forms are working with REST framework 2 + {# Only display the POST/PUT/DELETE forms if method tunneling via POST forms is enabled and the user has permissions on this view. #} - {% if METHOD_PARAM and response.status_code != 403 %} + {% if response.status_code != 403 %} {% if 'POST' in allowed_methods %} -
+

POST {{ name }}

- {% csrf_token %} - {{ post_form.non_field_errors }} + {% csrf_token %} + {{ post_form.non_field_errors }} {% for field in post_form %}
- {{ field.label_tag }} - {{ field }} - {{ field.help_text }} - {{ field.errors }} + {{ field.label_tag }} + {{ field }} + {{ field.help_text }} + {{ field.errors }}
{% endfor %}
@@ -102,42 +105,43 @@ {% endif %} - {% if 'PUT' in allowed_methods %} -
+ {% if 'PUT' in allowed_methods and api_settings.FORM_METHOD_OVERRIDE %} +

PUT {{ name }}

- + {% csrf_token %} {{ put_form.non_field_errors }} {% for field in put_form %}
- {{ field.label_tag }} - {{ field }} - {{ field.help_text }} - {{ field.errors }} + {{ field.label_tag }} + {{ field }} + {{ field.help_text }} + {{ field.errors }}
{% endfor %}
- +
{% endif %} - {% if 'DELETE' in allowed_methods %} -
+ {% if 'DELETE' in allowed_methods and api_settings.FORM_METHOD_OVERRIDE %} +

DELETE {{ name }}

{% csrf_token %} - +
- +
{% endif %} {% endif %} + {% endcomment %}