示例#1
0
 def retrieve(self, request, *args, **kwargs):
     response = super(UserViewSet, self).retrieve(request, *args, **kwargs)
     circles = Circle.objects.filter(members=request.user,
                                     membership__is_active=True)
     data = {
         'user': response.data,
         'circles': CircleModelSerializer(circles, many=True).data
     }
     response.data = data
     return response
示例#2
0
    def retrieve(self, request, *args, **kwargs):
        # Add extra data to the response
        response = super(UserViewSet, self).retrieve(request, *args, **kwargs)
        circles = Circle.objects.filter(members=request.user,
                                        membership__is_active=True)
        data = {
            'user': response.data,
            'circles': CircleModelSerializer(circles, many=True).data
        }

        response.data = data
        return response


# class UserLoginAPIView(APIView):
# 	# User login API view

# 	def post(self, request, *args, **kwargs):
# 		# handle HTTP POST request
# 		serializer = UserLoginSerializer(data=request.data)
# 		serializer.is_valid(raise_exception=True)
# 		user, token = serializer.save()
# 		data = {
# 			'user'         : UserModelSerializer(user).data,
# 			'access_token' : token
# 		}
# 		return Response(data, status = status.HTTP_201_CREATED)

# class UserSignUpAPIView(APIView):
# 	# User signup API view

# 	def post(self, request, *args, **kwargs):
# 		# handle HTTP POST request
# 		serializer = UserSignUpSerializer(data=request.data)
# 		serializer.is_valid(raise_exception=True)
# 		user = serializer.save()
# 		data = UserModelSerializer(user).data
# 		return Response(data, status = status.HTTP_201_CREATED)

# class AccountVerificationAPIView(APIView):
# 	# Account verificaiton API view.

# 	def post(self, request, *args, **kwargs):
# 		#Handle HTTP POST request
# 		serializer = AccountVerificationSerializer(data=request.data)
# 		serializer.is_valid(raise_exception=True)
# 		serializer.save()
# 		data = {'message': 'Congratulation, now go share some rides!'}
# 		return Response(data, status = status.HTTP_200_OK)
示例#3
0
    def retrieve(self, request, *args, **kwargs):
        """Add extra data(Circles in which the user is member.) to the response."""

        response = super(UserManagementViewSet,
                         self).retrieve(request, args, kwargs)

        circles = Circle.objects.filter(members=request.user,
                                        membership__is_active=True)
        data = {
            'user': response.data,
            'circles': CircleModelSerializer(circles, many=True).data
        }
        response.data = data

        return response
示例#4
0
    def retrieve(self, request, *args, **kwargs):
        """
        Add extra data to the response

        :param request:
        :param args:
        :param kwargs:
        :return:
        """
        response = super().retrieve(request, *args, **kwargs)
        circles = Circle.objects.filter(members=request.user,
                                        membership__is_active=True)
        data = {
            'user': response.data,
            'circle': CircleModelSerializer(circles, many=True).data
        }
        response.data = data
        return response
示例#5
0
 def retrieve(
     self, request, *args, **kwargs
 ):  # No queremos cambiar el comportamiento normal del metodo, solo agregarle una funcionalidad extra.
     """Agrega datos adicionales a la respuesta"""
     response = super(UserViewSet, self).retrieve(
         request, *args, **kwargs
     )  # Primero recuperamos la respuesta que genera el metodo por defecto retrieve.
     circles = Circle.objects.filter(
         members=request.
         user,  # Este campo esta definido en circle, y recibe un user
         membership__is_active=
         True  # Trae las membresias en las que el usuario esta activo
     )
     data = {
         'user': response.data,
         'circle': CircleModelSerializer(circles, many=True).
         data  # Mandamos los circulos serilizados con many=True por que podria estar en mas de un circulo.
     }
     response.data = data
     return response