Ejemplo n.º 1
0
Archivo: views.py Proyecto: crs4/ACTIVE
    def get(self, request, pk, format=None):
        """
        Method used to retrieve all stored Instance objects associated to a EntityModel.
        Objects are returned in a serialized way.

        @param request: The HttpRequest used to retrieve all stored Instance objects.
        @type request: HttpRequest
        @param pk: The id of the Entitymodel used 
        @type pk: int
        @return: The HTTP response containing all stored Instance objects
        @rtype: HttpResponse
        """
        # retrieve the query parameters
        model_id = request.query_params.get("model_id", None)
        item_id = request.query_params.get("item_id", None)
        used = request.query_params.get("used", None)
        trusted = request.query_params.get("trusted", None)
        # apply the filter parameters
        instances = Instance.objects.all()
        if model_id is not None:
            instances = instances.filter(entity_model=model_id)
        if item_id is not None:
            instances = instances.filter(item__pk=item_id)
        if used is not None:
            instances = instances.filter(entity_model__isnull=used)
        if trusted is not None:
            instances = instances.filter(trusted=trusted)

        instances = Instance.objects.filter(entity_model=pk)
        paginator = InstancePagination()
        result = paginator.paginate_queryset(instances, request)
        serializer = InstanceSerializer(result, many=True)
        return paginator.get_paginated_response(serializer.data)
Ejemplo n.º 2
0
Archivo: views.py Proyecto: crs4/ACTIVE
    def get(self, request, format=None):
        """
        Method used to retrieve all stored Instance objects.
        Objects are returned in a serialized way. 

        @param request: The HttpRequest used to retrieve all stored Instance objects.
        @type request: HttpRequest
        @return: The HTTP response containing all stored Instance objects
        @rtype: HttpResponse
        """
        used = request.query_params.get("used", None)
        type = request.query_params.get("type", None)

        instances = None
        if used is not None and used == "false":
            instances = Instance.objects.filter(entity_model=None)
            if type is not None:
                instances = instances.filter(type=type)
        else:
            instances = Instance.objects.all()

        instances = instances.exclude(features="")
        paginator = InstancePagination()
        result = paginator.paginate_queryset(instances, request)
        serializer = InstanceSerializer(result, many=True)
        return paginator.get_paginated_response(serializer.data)