Ejemplo n.º 1
0
 def put(self, request, pk, format=None):
     try:
         data = request.data
     except ParseError as error:
         return Response('Invalid JSON - {0}'.format(error.detail),
                         status=status.HTTP_400_BAD_REQUEST)
     if 'username' not in data or 'password' not in data or \
        'first_name' not in data or 'last_name' not in data or \
        'is_superuser' not in data:
         return Response('Wrong credentials',
                         status=status.HTTP_401_UNAUTHORIZED)
     try:
         if not has_permisions(request):
             return HttpResponse('You do not have permission',
                                 status=status.HTTP_403_FORBIDDEN)
     except ParseError:
         return HttpResponse('Invalid HTTP request - {0}',
                             status=status.HTTP_400_BAD_REQUEST)
     user = User.objects.get(pk=pk)
     user.username = data['username']
     user.first_name = data['first_name']
     user.last_name = data['last_name']
     user.is_superuser = False if data['is_superuser'] == 'false' else True
     user.is_staff = False if data['is_superuser'] == 'false' else True
     if data['password']:
         user.set_password(data['password'])
     user.save()
     return HttpResponse(status=status.HTTP_200_OK)
Ejemplo n.º 2
0
 def put(self, request, pk, format=None):
     try:
         data = request.data
     except ParseError as error:
         return Response("Invalid JSON - {0}".format(error.detail), status=status.HTTP_400_BAD_REQUEST)
     if (
         "username" not in data
         or "password" not in data
         or "first_name" not in data
         or "last_name" not in data
         or "is_superuser" not in data
     ):
         return Response("Wrong credentials", status=status.HTTP_401_UNAUTHORIZED)
     try:
         if not has_permisions(request):
             return HttpResponse("You do not have permission", status=status.HTTP_403_FORBIDDEN)
     except ParseError:
         return HttpResponse("Invalid HTTP request - {0}", status=status.HTTP_400_BAD_REQUEST)
     user = User.objects.get(pk=pk)
     user.username = data["username"]
     user.first_name = data["first_name"]
     user.last_name = data["last_name"]
     user.is_superuser = False if data["is_superuser"] == "false" else True
     user.is_staff = False if data["is_superuser"] == "false" else True
     if data["password"]:
         user.set_password(data["password"])
     user.save()
     return HttpResponse(status=status.HTTP_200_OK)
Ejemplo n.º 3
0
    def post(self, request, format=None):
        try:
            data = request.data
        except ParseError as error:
            return Response('Invalid JSON - {0}'.format(error.detail),
                            status=status.HTTP_400_BAD_REQUEST)
        if 'username' not in data or 'password' not in data or \
           'first_name' not in data or 'last_name' not in data or \
           'is_superuser' not in data:
            return Response('Wrong credentials',
                            status=status.HTTP_401_UNAUTHORIZED)
        try:
            if not has_permisions(request):
                return HttpResponse('You do not have permission',
                                    status=status.HTTP_403_FORBIDDEN)
        except ParseError:
            return HttpResponse('Invalid HTTP request - {0}',
                                status=status.HTTP_400_BAD_REQUEST)
        user = User.objects.create_user(username=data['username'],
                                        password=data['password'])
        user.first_name = data['first_name']
        user.last_name = data['last_name']
        user.is_superuser = False if data['is_superuser'] == 'false' else True
        user.is_staff = False if data['is_superuser'] == 'false' else True

        acc = Account(user=user)  # by default rate field get '1.0' value
        if 'rate' in data:
            acc.rate = data['rate']

        user.save()
        acc.save()
        return HttpResponse(status=status.HTTP_200_OK)
Ejemplo n.º 4
0
    def post(self, request, format=None):
        try:
            data = request.data
        except ParseError as error:
            return Response("Invalid JSON - {0}".format(error.detail), status=status.HTTP_400_BAD_REQUEST)
        if (
            "username" not in data
            or "password" not in data
            or "first_name" not in data
            or "last_name" not in data
            or "is_superuser" not in data
        ):
            return Response("Wrong credentials", status=status.HTTP_401_UNAUTHORIZED)
        try:
            if not has_permisions(request):
                return HttpResponse("You do not have permission", status=status.HTTP_403_FORBIDDEN)
        except ParseError:
            return HttpResponse("Invalid HTTP request - {0}", status=status.HTTP_400_BAD_REQUEST)
        user = User.objects.create_user(username=data["username"], password=data["password"])
        user.first_name = data["first_name"]
        user.last_name = data["last_name"]
        user.is_superuser = False if data["is_superuser"] == "false" else True
        user.is_staff = False if data["is_superuser"] == "false" else True

        acc = Account(user=user)  # by default rate field get '1.0' value
        if "rate" in data:
            acc.rate = data["rate"]

        user.save()
        acc.save()
        return HttpResponse(status=status.HTTP_200_OK)
Ejemplo n.º 5
0
 def delete(self, request, pk, format=None):
     try:
         if not has_permisions(request):
             return HttpResponse("You do not have permission", status=status.HTTP_403_FORBIDDEN)
     except ParseError:
         return HttpResponse("Invalid HTTP request - {0}", status=status.HTTP_400_BAD_REQUEST)
     user = User.objects.get(pk=pk)
     user.delete()
     return HttpResponse(status=status.HTTP_200_OK)
Ejemplo n.º 6
0
 def delete(self, request, pk, format=None):
     try:
         if not has_permisions(request):
             return HttpResponse('You do not have permission',
                                 status=status.HTTP_403_FORBIDDEN)
     except ParseError:
         return HttpResponse('Invalid HTTP request - {0}',
                             status=status.HTTP_400_BAD_REQUEST)
     user = User.objects.get(pk=pk)
     user.delete()
     return HttpResponse(status=status.HTTP_200_OK)
Ejemplo n.º 7
0
    def post(self, request, format=None):
        try:
            data = request.data
        except ParseError as error:
            return Response(
                'Invalid JSON - {0}'.format(error.detail),
                status=status.HTTP_400_BAD_REQUEST
            )
        if 'username' not in data or 'password' not in data or \
           'first_name' not in data or 'last_name' not in data or \
           'is_superuser' not in data:
            return Response(
                'Wrong credentials',
                status=status.HTTP_401_UNAUTHORIZED
            )
        try:
            if not has_permisions(request):
                return HttpResponse(
                    'You do not have permission',
                    status=status.HTTP_403_FORBIDDEN
                )
        except ParseError:
            return HttpResponse(
                'Invalid HTTP request - {0}',
                status=status.HTTP_400_BAD_REQUEST
            )
        user = User.objects.create_user(
            username=data['username'],
            password=data['password']
        )
        user.first_name = data['first_name']
        user.last_name = data['last_name']
        user.is_superuser = False if data['is_superuser'] == 'false' else True
        user.is_staff = False if data['is_superuser'] == 'false' else True

        acc = Account(user=user)  # by default rate field get '1.0' value
        if 'rate' in data:
            acc.rate = data['rate']

        user.save()
        acc.save()
        return HttpResponse(status=status.HTTP_200_OK)
Ejemplo n.º 8
0
 def put(self, request, pk, format=None):
     try:
         data = request.data
     except ParseError as error:
         return Response(
             'Invalid JSON - {0}'.format(error.detail),
             status=status.HTTP_400_BAD_REQUEST
         )
     if 'username' not in data or 'password' not in data or \
        'first_name' not in data or 'last_name' not in data or \
        'is_superuser' not in data:
         return Response(
             'Wrong credentials',
             status=status.HTTP_401_UNAUTHORIZED
         )
     try:
         if not has_permisions(request):
             return HttpResponse(
                 'You do not have permission',
                 status=status.HTTP_403_FORBIDDEN
             )
     except ParseError:
         return HttpResponse(
             'Invalid HTTP request - {0}',
             status=status.HTTP_400_BAD_REQUEST
         )
     user = User.objects.get(pk=pk)
     user.username = data['username']
     user.first_name = data['first_name']
     user.last_name = data['last_name']
     user.is_superuser = False if data['is_superuser'] == 'false' else True
     user.is_staff = False if data['is_superuser'] == 'false' else True
     if data['password']:
         user.set_password(data['password'])
     user.save()
     return HttpResponse(status=status.HTTP_200_OK)