From a9df917d10e5f84090074e11213eb6d550c174cc Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 11 Apr 2011 15:03:49 +0100 Subject: Lots of validator tests passing after refactor --- djangorestframework/request.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'djangorestframework/request.py') 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.""" -- cgit v1.2.3