aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/request.py
diff options
context:
space:
mode:
authorTom Christie2011-04-11 15:03:49 +0100
committerTom Christie2011-04-11 15:03:49 +0100
commita9df917d10e5f84090074e11213eb6d550c174cc (patch)
tree7aa898b643bebf667bf461a18d479acfc7085967 /djangorestframework/request.py
parent136c9b5271fc205abffbbe5422b3c345858a533b (diff)
downloaddjango-rest-framework-a9df917d10e5f84090074e11213eb6d550c174cc.tar.bz2
Lots of validator tests passing after refactor
Diffstat (limited to 'djangorestframework/request.py')
-rw-r--r--djangorestframework/request.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/djangorestframework/request.py b/djangorestframework/request.py
index 7f2cb0bc..33d6bb2f 100644
--- a/djangorestframework/request.py
+++ b/djangorestframework/request.py
@@ -196,6 +196,29 @@ class RequestMixin(object):
return parser.parse(stream)
+
+ def validate(self, content):
+ """
+ Validate, cleanup, and type-ify the request content.
+ """
+ for validator_cls in self.validators:
+ validator = validator_cls(self)
+ content = validator.validate(content)
+ return content
+
+
+ def get_bound_form(self, content=None):
+ """
+ Return a bound form instance for the given content,
+ if there is an appropriate form validator attached to the view.
+ """
+ for validator_cls in self.validators:
+ if hasattr(validator_cls, 'get_bound_form'):
+ validator = validator_cls(self)
+ return validator.get_bound_form(content)
+ return None
+
+
@property
def parsed_media_types(self):
"""Return an list of all the media types that this view can parse."""