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)
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)
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)
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)
def get(self, request, view_id, field_options): """ Lists all the rows of a grid view, paginated either by a page or offset/limit. If the limit get parameter is provided the limit/offset pagination will be used else the page number pagination. Optionally the field options can also be included in the response if the the `field_options` are provided in the include GET parameter. """ search = request.GET.get('search') view_handler = ViewHandler() view = view_handler.get_view(view_id, GridView) view.table.database.group.has_user(request.user, raise_error=True, allow_if_template=True) model = view.table.get_model() queryset = model.objects.all().enhance_by_fields() # Applies the view filters and sortings to the queryset if there are any. queryset = view_handler.apply_filters(view, queryset) queryset = view_handler.apply_sorting(view, queryset) if search: queryset = queryset.search_all_fields(search) if 'count' in request.GET: return Response({'count': queryset.count()}) if LimitOffsetPagination.limit_query_param in request.GET: paginator = LimitOffsetPagination() else: 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) response = paginator.get_paginated_response(serializer.data) if field_options: # The serializer has the GridViewFieldOptionsField which fetches the # field options from the database and creates them if they don't exist, # but when added to the context the fields don't have to be fetched from # the database again when checking if they exist. context = { 'fields': [o['field'] for o in model._field_objects.values()] } serialized_view = GridViewSerializer(view, context=context).data response.data['field_options'] = serialized_view['field_options'] return response
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)
def get(self, request, view_id, field_options): """ Lists all the rows of a grid view, paginated either by a page or offset/limit. If the limit get parameter is provided the limit/offset pagination will be used else the page number pagination. Optionally the field options can also be included in the response if the the `field_options` are provided in the includes GET parameter. """ view = ViewHandler().get_view(request.user, view_id, GridView) model = view.table.get_model() queryset = model.objects.all().enhance_by_fields().order_by('id') if LimitOffsetPagination.limit_query_param in request.GET: paginator = LimitOffsetPagination() else: 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) response = paginator.get_paginated_response(serializer.data) if field_options: # The serializer has the GridViewFieldOptionsField which fetches the # field options from the database and creates them if they don't exist, # but when added to the context the fields don't have to be fetched from # the database again when checking if they exist. context = { 'fields': [o['field'] for o in model._field_objects.values()] } response.data.update( **GridViewSerializer(view, context=context).data) return response