diff options
| author | tom christie tom@tomchristie.com | 2011-04-02 16:32:37 +0100 |
|---|---|---|
| committer | tom christie tom@tomchristie.com | 2011-04-02 16:32:37 +0100 |
| commit | 4687db680cda52e9836743940e4cf7279b307294 (patch) | |
| tree | 23b9b22eee3c08f6de09295b3c6630f5fb0730fa /djangorestframework/validators.py | |
| parent | 8845b281fe9aafbc9f9b2a283fafbde9787f4734 (diff) | |
| download | django-rest-framework-4687db680cda52e9836743940e4cf7279b307294.tar.bz2 | |
Refactor to use self.CONTENT to access request body. Get file upload working
Diffstat (limited to 'djangorestframework/validators.py')
| -rw-r--r-- | djangorestframework/validators.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/djangorestframework/validators.py b/djangorestframework/validators.py index 3d0a7794..d96e8d9e 100644 --- a/djangorestframework/validators.py +++ b/djangorestframework/validators.py @@ -58,6 +58,8 @@ class FormValidatorMixin(ValidatorMixin): # Validation succeeded... cleaned_data = bound_form.cleaned_data + cleaned_data.update(bound_form.files) + # Add in any extra fields to the cleaned content... for key in (allowed_extra_fields_set & seen_fields_set) - set(cleaned_data.keys()): cleaned_data[key] = content[key] @@ -95,7 +97,9 @@ class FormValidatorMixin(ValidatorMixin): if not self.form: return None - if content: + if not content is None: + if hasattr(content, 'FILES'): + return self.form(content, content.FILES) return self.form(content) return self.form() @@ -157,8 +161,11 @@ class ModelFormValidatorMixin(FormValidatorMixin): # Instantiate the ModelForm as appropriate if content and isinstance(content, models.Model): + # Bound to an existing model instance return OnTheFlyModelForm(instance=content) - elif content: + elif not content is None: + if hasattr(content, 'FILES'): + return OnTheFlyModelForm(content, content.FILES) return OnTheFlyModelForm(content) return OnTheFlyModelForm() @@ -189,4 +196,4 @@ class ModelFormValidatorMixin(FormValidatorMixin): return property_fields - set(as_tuple(self.exclude_fields)) -
\ No newline at end of file + |
