django-orchestra-test/orchestra/api/actions.py

19 lines
668 B
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from rest_framework import status
from rest_framework.decorators import action
from rest_framework.response import Response
from .serializers import SetPasswordSerializer
class SetPasswordApiMixin(object):
@action(serializer_class=SetPasswordSerializer)
def set_password(self, request, pk):
obj = self.get_object()
serializer = SetPasswordSerializer(data=request.DATA)
if serializer.is_valid():
obj.set_password(serializer.data['password'])
obj.save()
return Response({'status': 'password changed'})
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)