diff options
| author | Tom Christie | 2013-12-13 16:32:34 +0000 | 
|---|---|---|
| committer | Tom Christie | 2013-12-13 16:32:34 +0000 | 
| commit | 9c41c007afc71c899306bcb02e40bdfc36b09146 (patch) | |
| tree | ca0da04aed0c1b96ddf14a801dc54b5a72a72461 /rest_framework/mixins.py | |
| parent | ed931b90ae9e72f963673e6e188b1802a5a65360 (diff) | |
| parent | ca244ad614e2f6fb4fef1dc9987be996d2624303 (diff) | |
| download | django-rest-framework-9c41c007afc71c899306bcb02e40bdfc36b09146.tar.bz2 | |
Merge branch 'master' into 2.4.0
Conflicts:
	.travis.yml
	docs/api-guide/routers.md
	docs/topics/release-notes.md
	rest_framework/compat.py
Diffstat (limited to 'rest_framework/mixins.py')
| -rw-r--r-- | rest_framework/mixins.py | 13 | 
1 files changed, 11 insertions, 2 deletions
| diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py index 2c85d157..b62a4cc1 100644 --- a/rest_framework/mixins.py +++ b/rest_framework/mixins.py @@ -6,6 +6,7 @@ which allows mixin classes to be composed in interesting ways.  """  from __future__ import unicode_literals +from django.core.exceptions import ValidationError  from django.http import Http404  from rest_framework import status  from rest_framework.response import Response @@ -127,7 +128,12 @@ class UpdateModelMixin(object):                                           files=request.FILES, partial=partial)          if serializer.is_valid(): -            self.pre_save(serializer.object) +            try: +                self.pre_save(serializer.object) +            except ValidationError as err: +                # full_clean on model instance may be called in pre_save, so we +                # have to handle eventual errors. +                return Response(err.message_dict, status=status.HTTP_400_BAD_REQUEST)              self.object = serializer.save(**save_kwargs)              self.post_save(self.object, created=created)              return Response(serializer.data, status=success_status_code) @@ -158,7 +164,8 @@ class UpdateModelMixin(object):          Set any attributes on the object that are implicit in the request.          """          # pk and/or slug attributes are implicit in the URL. -        lookup = self.kwargs.get(self.lookup_field, None) +        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field +        lookup = self.kwargs.get(lookup_url_kwarg, None)          pk = self.kwargs.get(self.pk_url_kwarg, None)          slug = self.kwargs.get(self.slug_url_kwarg, None)          slug_field = slug and self.slug_field or None @@ -185,5 +192,7 @@ class DestroyModelMixin(object):      """      def destroy(self, request, *args, **kwargs):          obj = self.get_object() +        self.pre_delete(obj)          obj.delete() +        self.post_delete(obj)          return Response(status=status.HTTP_204_NO_CONTENT) | 
