diff options
| author | tom christie tom@tomchristie.com | 2011-02-07 08:23:54 +0000 |
|---|---|---|
| committer | tom christie tom@tomchristie.com | 2011-02-07 08:23:54 +0000 |
| commit | 027ffed21064b1ec304a1ea559104382313d76f4 (patch) | |
| tree | 8621c8741d76cc672da207cf314574a4fbd828d1 /djangorestframework/emitters.py | |
| parent | a8bcb2edc63564522b89b9950ea0882d6b25f24a (diff) | |
| download | django-rest-framework-027ffed21064b1ec304a1ea559104382313d76f4.tar.bz2 | |
Refactor a bunch of stuff into mixins, more tests
Diffstat (limited to 'djangorestframework/emitters.py')
| -rw-r--r-- | djangorestframework/emitters.py | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/djangorestframework/emitters.py b/djangorestframework/emitters.py index a69407f1..d6bb33c1 100644 --- a/djangorestframework/emitters.py +++ b/djangorestframework/emitters.py @@ -8,6 +8,7 @@ from django.template import RequestContext, loader from django import forms from djangorestframework.response import NoContent +from djangorestframework.validators import FormValidatorMixin from djangorestframework.utils import dict2xml, url_resolves from urllib import quote_plus @@ -82,24 +83,28 @@ class DocumentingTemplateEmitter(BaseEmitter): In the absence on of the Resource having an associated form then 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 - - # 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: - try: - form_instance = resource.get_form(resource.response.raw_content) - if form_instance: - form_instance.is_valid() - except: - form_instance = None - - # If we still don't have a form instance then try to get an unbound form - if not form_instance: - try: - form_instance = self.resource.get_form() - except: - pass + #form_instance = resource.form_instance + # TODO! Reinstate this + + form_instance = None + + if isinstance(self, FormValidatorMixin): + # 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: + try: + form_instance = resource.get_bound_form(resource.response.raw_content) + if form_instance: + form_instance.is_valid() + except: + form_instance = None + + # If we still don't have a form instance then try to get an unbound form + if not form_instance: + try: + form_instance = self.resource.get_bound_form() + except: + pass # If we still don't have a form instance then try to get an unbound form which can tunnel arbitrary content types if not form_instance: |
