From 0d213f1439d6c88fb555e21af7a746d4669904f5 Mon Sep 17 00:00:00 2001 From: Craig Blaszczyk Date: Tue, 9 Aug 2011 16:52:19 +0100 Subject: [PATCH] update form to have access to the request object --- djangorestframework/mixins.py | 1 - djangorestframework/resources.py | 23 +++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/djangorestframework/mixins.py b/djangorestframework/mixins.py index f3964ad7f..5be528cb0 100644 --- a/djangorestframework/mixins.py +++ b/djangorestframework/mixins.py @@ -572,7 +572,6 @@ class UpdateModelMixin(object): else: # Otherwise assume the kwargs uniquely identify the model self.model_instance = model.objects.get(**kwargs) - for (key, val) in self.CONTENT.items(): setattr(self.model_instance, key, val) except model.DoesNotExist: diff --git a/djangorestframework/resources.py b/djangorestframework/resources.py index 5dee88356..badec8104 100644 --- a/djangorestframework/resources.py +++ b/djangorestframework/resources.py @@ -212,9 +212,14 @@ class FormResource(Resource): return None if data is not None or files is not None: - return form(data, files) - - return form() + form_ = form(data, files) + else: + form_ = form() + + if hasattr(self.view, 'request'): + form_.request = self.view.request + + return form_ @@ -333,11 +338,17 @@ class ModelResource(FormResource): if data is not None or files is not None: if issubclass(form, forms.ModelForm) and hasattr(self.view, 'model_instance'): # Bound to an existing model instance - return form(data, files, instance=self.view.model_instance) + form_ = form(data, files, instance=self.view.model_instance) else: - return form(data, files) + form_ = form(data, files) - return form() + else: + form_ = form() + + if hasattr(self.view, 'request'): + form_.request = self.view.request + + return form_ def url(self, instance):