Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make pagination work with Simple Datagrid.

  • Loading branch information...
commit 2d3e8fbb77de26bde1c666773f1c86ba9303852a 1 parent b523534
@markotibold markotibold authored
Showing with 14 additions and 8 deletions.
  1. +6 −1 fiber/rest_api/serializers.py
  2. +8 −7 fiber/rest_api/views.py
View
7 fiber/rest_api/serializers.py
@@ -1,4 +1,4 @@
-from rest_framework import serializers
+from rest_framework import serializers, pagination
from fiber.models import Page, PageContentItem, ContentItem, File, Image
@@ -45,3 +45,8 @@ class ImageSerializer(serializers.ModelSerializer):
class Meta:
model = Image
read_only_fields = ('created', 'updated')
+
+
+class FiberPaginationSerializer(pagination.BasePaginationSerializer):
+ total_pages = serializers.Field(source='paginator.num_pages')
+ results_field = 'rows'
View
15 fiber/rest_api/views.py
@@ -31,7 +31,7 @@
from rest_framework.reverse import reverse
from rest_framework import views
-from .serializers import PageSerializer, PageContentItemSerializer, ContentItemSerializer, FileSerializer, ImageSerializer
+from .serializers import PageSerializer, PageContentItemSerializer, ContentItemSerializer, FileSerializer, ImageSerializer, FiberPaginationSerializer
class FiberListCreateAPIView(generics.ListCreateAPIView):
@@ -94,6 +94,7 @@ class ImageList(FiberListCreateAPIView):
model = Image
serializer_class = ImageSerializer
renderer_classes = (renderers.JSONRenderer, )
+ pagination_serializer_class = FiberPaginationSerializer
paginate_by = 5
@@ -118,12 +119,6 @@ def api_root(request, format='None'):
})
-class ListView(ListOrCreateModelView):
-
- permissions = (IsAdminUser, )
- renderers = API_RENDERERS
-
-
class PageTree(views.APIView):
def get(self, request, format=None):
@@ -133,6 +128,12 @@ def get(self, request, format=None):
return Response(Page.objects.create_jqtree_data(request.user))
+class ListView(ListOrCreateModelView):
+
+ permissions = (IsAuthenticated, )
+ renderers = API_RENDERERS
+
+
class PaginatedListView(PaginatorMixin, ListView):
limit = 5
Please sign in to comment.
Something went wrong with that request. Please try again.