aboutsummaryrefslogtreecommitdiffstats
path: root/flywheel
diff options
context:
space:
mode:
authorTom Christie2011-01-28 17:42:57 +0000
committerTom Christie2011-01-28 17:42:57 +0000
commit40f47a9fb31aebd965dce03ae57c036d5360d124 (patch)
tree9e95ee3e500b5c2d8eb4e1adecefaf1d2de47b8a /flywheel
parent2e9fd9c6b93a77dcf5caa42a4d71b9da2021693f (diff)
downloaddjango-rest-framework-40f47a9fb31aebd965dce03ae57c036d5360d124.tar.bz2
Minor bit of tidy up (all the stuff I noticed when demoing to francis)
Diffstat (limited to 'flywheel')
-rw-r--r--flywheel/emitters.py7
-rw-r--r--flywheel/resource.py13
-rw-r--r--flywheel/templates/emitter.html8
3 files changed, 19 insertions, 9 deletions
diff --git a/flywheel/emitters.py b/flywheel/emitters.py
index d052d965..57e95ec2 100644
--- a/flywheel/emitters.py
+++ b/flywheel/emitters.py
@@ -32,6 +32,8 @@ class BaseEmitter(object):
self.resource = resource
def emit(self, output=NoContent, verbose=False):
+ """By default emit simply returns the ouput as-is.
+ Override this method to provide for other behaviour."""
if output is NoContent:
return ''
@@ -81,7 +83,8 @@ class DocumentingTemplateEmitter(BaseEmitter):
provide a form that can be used to submit arbitrary content."""
# Get the form instance if we have one bound to the input
form_instance = resource.form_instance
-
+ print form_instance
+
# Otherwise if this isn't an error response
# then attempt to get a form bound to the response object
if not form_instance and resource.response.has_content_body:
@@ -89,6 +92,8 @@ class DocumentingTemplateEmitter(BaseEmitter):
form_instance = resource.get_form(resource.response.raw_content)
except:
pass
+ if form_instance and not form_instance.is_valid():
+ form_instance = None
# If we still don't have a form instance then try to get an unbound form
if not form_instance:
diff --git a/flywheel/resource.py b/flywheel/resource.py
index 677bdfce..2a8554f3 100644
--- a/flywheel/resource.py
+++ b/flywheel/resource.py
@@ -58,14 +58,19 @@ class Resource(object):
CSRF_PARAM = 'csrfmiddlewaretoken' # Django's CSRF token used in form params
- def __new__(cls, request, *args, **kwargs):
+ def __new__(cls, *args, **kwargs):
"""Make the class callable so it can be used as a Django view."""
self = object.__new__(cls)
- self.__init__(request)
- return self._handle_request(request, *args, **kwargs)
+ if args:
+ request = args[0]
+ self.__init__(request)
+ return self._handle_request(request, *args[1:], **kwargs)
+ else:
+ self.__init__()
+ return self
- def __init__(self, request):
+ def __init__(self, request=None):
""""""
# Setup the resource context
self.request = request
diff --git a/flywheel/templates/emitter.html b/flywheel/templates/emitter.html
index 7959af17..4b0a7ce9 100644
--- a/flywheel/templates/emitter.html
+++ b/flywheel/templates/emitter.html
@@ -30,9 +30,9 @@
<h1>{{ resource.name }}</h1>
<p>{{ resource.description|linebreaksbr }}</p>
<pre><b>{{ response.status }} {{ response.status_text }}</b>{% autoescape off %}
- {% for key, val in response.headers.items %}<b>{{ key }}:</b> {{ val|urlize_quoted_links }}
- {% endfor %}
- {{ content|urlize_quoted_links }}</pre>{% endautoescape %}
+{% for key, val in response.headers.items %}<b>{{ key }}:</b> {{ val|urlize_quoted_links }}
+{% endfor %}
+{{ content|urlize_quoted_links }}</pre>{% endautoescape %}
{% if 'GET' in resource.allowed_methods %}
<div class='action'>
@@ -40,7 +40,7 @@
<ul class="accepttypes">
{% for media_type in resource.emitted_media_types %}
{% with resource.ACCEPT_QUERY_PARAM|add:"="|add:media_type as param %}
- <li>[<a href='{{ request.path|add_query_param:param }} rel="nofollow"'>{{ media_type }}</a>]</li>
+ <li>[<a href='{{ request.path|add_query_param:param }}' rel="nofollow">{{ media_type }}</a>]</li>
{% endwith %}
{% endfor %}
</ul>