Example #1
0
    def get(self, request, table_id):
        """
        Lists all the rows of the given table id paginated. It is also possible to
        provide a search query.
        """

        table = TableHandler().get_table(request.user, table_id)
        TokenHandler().check_table_permissions(request, 'read', table, False)

        model = table.get_model()
        search = request.GET.get('search')
        order_by = request.GET.get('order_by')

        queryset = model.objects.all().enhance_by_fields().order_by('id')

        if search:
            queryset = queryset.search_all_fields(search)

        if order_by:
            queryset = queryset.order_by_fields_string(order_by)

        paginator = PageNumberPagination(
            limit_page_size=settings.ROW_PAGE_SIZE_LIMIT)
        page = paginator.paginate_queryset(queryset, request, self)
        serializer_class = get_row_serializer_class(model,
                                                    RowSerializer,
                                                    is_response=True)
        serializer = serializer_class(page, many=True)

        return paginator.get_paginated_response(serializer.data)
Example #2
0
    def get(self, request):
        """
        Lists all the users of a user, optionally filtering on username by the
        'search' get parameter, optionally sorting by the 'sorts' get parameter.
        """

        search = request.GET.get("search")
        sorts = request.GET.get("sorts")

        handler = UserAdminHandler()
        users = handler.get_users(request.user, search, sorts)

        paginator = PageNumberPagination(limit_page_size=100)
        page = paginator.paginate_queryset(users, request, self)
        serializer = UserAdminResponseSerializer(page, many=True)

        return paginator.get_paginated_response(serializer.data)
Example #3
0
    def get(self, request, table_id):
        """
        Lists all the rows of the given table id paginated. It is also possible to
        provide a search query.
        """

        table = TableHandler().get_table(table_id)
        table.database.group.has_user(request.user, raise_error=True)

        TokenHandler().check_table_permissions(request, 'read', table, False)
        search = request.GET.get('search')
        order_by = request.GET.get('order_by')
        include = request.GET.get('include')
        exclude = request.GET.get('exclude')
        fields = RowHandler().get_include_exclude_fields(
            table, include, exclude)

        model = table.get_model(fields=fields,
                                field_ids=[] if fields else None)
        queryset = model.objects.all().enhance_by_fields()

        if search:
            queryset = queryset.search_all_fields(search)

        if order_by:
            queryset = queryset.order_by_fields_string(order_by)

        filter_type = (FILTER_TYPE_OR
                       if str(request.GET.get('filter_type')).upper() == 'OR'
                       else FILTER_TYPE_AND)
        filter_object = {
            key: request.GET.getlist(key)
            for key in request.GET.keys()
        }
        queryset = queryset.filter_by_fields_object(filter_object, filter_type)

        paginator = PageNumberPagination(
            limit_page_size=settings.ROW_PAGE_SIZE_LIMIT)
        page = paginator.paginate_queryset(queryset, request, self)
        serializer_class = get_row_serializer_class(model,
                                                    RowSerializer,
                                                    is_response=True)
        serializer = serializer_class(page, many=True)

        return paginator.get_paginated_response(serializer.data)
Example #4
0
    def get(self, request):
        """
        Responds with paginated results related to queryset and the serializer
        defined on this class.
        """

        search = request.GET.get("search")
        sorts = request.GET.get("sorts")

        queryset = self.get_queryset(request)
        queryset = self._apply_sorts_or_default_sort(sorts, queryset)
        queryset = self._apply_search(search, queryset)

        paginator = PageNumberPagination(limit_page_size=100)
        page = paginator.paginate_queryset(queryset, request, self)
        serializer = self.get_serializer(request, page, many=True)

        return paginator.get_paginated_response(serializer.data)
Example #5
0
    def get(self, request, table_id):
        """
        Lists all the rows of the given table id paginated. It is also possible to
        provide a search query.
        """

        table = TableHandler().get_table(request.user, table_id)
        model = table.get_model()
        search = request.GET.get('search')

        queryset = model.objects.all().enhance_by_fields().order_by('id')

        if search:
            queryset = queryset.search_all_fields(search)

        paginator = PageNumberPagination()
        page = paginator.paginate_queryset(queryset, request, self)
        serializer_class = get_row_serializer_class(model,
                                                    RowSerializer,
                                                    is_response=True)
        serializer = serializer_class(page, many=True)

        return paginator.get_paginated_response(serializer.data)