def put(self, request, pk, format=None): user = self.get_object(pk) serializer = UserSerializer(user, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get_all_users(request): if not request.user.is_authenticated(): return Response('You are not logged in', status=status.HTTP_400_BAD_REQUEST) users = User.objects.all().exclude(username=request.user).order_by('date_joined') serializer = UserSerializer(users, many=True) return Response(serializer.data)
def retrieve(self, request, *args, **kwargs): user = self.get_object() serializer = UserSerializer(instance=user) return Response({ "time": time.time(), "data": serializer.data, })
def get(self, request, format=None): """ Complete list of users and its features. """ usuarios = Userpdu.objects.using('pdudb').all() serializer = UserSerializer(usuarios, many=True) return Response(serializer.data, status=status.HTTP_200_OK)
def get(self, request, usr=None, format=None): """ It shows a user with its features (no password shown) """ if (request.user.username != usr and not (request.user.is_superuser)): return Response(status=status.HTTP_401_UNAUTHORIZED) try: usuarios = Userpdu.objects.using('pdudb').get(user=usr) serializers = UserSerializer(usuarios) except: return Response('User dosen\'t exist', status=status.HTTP_404_NOT_FOUND) return Response(serializers.data, status=status.HTTP_200_OK)
def get_authenticated_user(request): if not request.user.is_authenticated(): return Response('You are not logged in', status=status.HTTP_400_BAD_REQUEST) serializer = UserSerializer(request.user) return Response(serializer.data)
def post(self, request, format=None): serializer = UserSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)