update form to have access to the request object

This commit is contained in:
Craig Blaszczyk 2011-08-09 16:52:19 +01:00
parent 98ec89a575
commit 0d213f1439
2 changed files with 17 additions and 7 deletions

View File

@ -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:

View File

@ -212,9 +212,14 @@ class FormResource(Resource):
return None
if data is not None or files is not None:
return form(data, files)
form_ = form(data, files)
else:
form_ = form()
return 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):