Parcourir la source

Pagination works now

Marcos Dumay de Medeiros il y a 9 ans
Parent
commit
c060b1609a
1 fichiers modifiés avec 6 ajouts et 3 suppressions
  1. 6 3
      src/rapid/views.py

+ 6 - 3
src/rapid/views.py

@@ -130,10 +130,13 @@ class ListView(generic.list.ListView):
             """
             return self.page > self.number_of_edge_pages + self.number_of_middle_pages
 
+        def get_page(self, queryset):
+            return queryset[self.registers_per_page*self.page:self.registers_per_page*(self.page+1)-1]
+
     class View:
         order_param = 'order'
 
-        def __init__(self, request, action_name, model, queryset, fields):
+        def __init__(self, request, action_name, model, queryset, fields, pagination):
             self.request = request
             self.model = model
             self.action_name = action_name
@@ -149,7 +152,7 @@ class ListView(generic.list.ListView):
             order = request.GET.get(self.order_param)
             if order:
                 q = q.order_by(order)
-            self.queryset = q
+            self.queryset = pagination.get_page(q)
 
         def values(self):
             for o in self.queryset:
@@ -203,7 +206,7 @@ class ListView(generic.list.ListView):
                                       total_pages)
         context['pages'] = p
         context['model'] = ModelData(self.model, request, fields=self.fields)
-        context['view'] = self.View(request, self.action_name, self.model, object_list, self.fields)
+        context['view'] = self.View(request, self.action_name, self.model, object_list, self.fields, p)
         default_ordering = self.model._meta.ordering if hasattr(self.model._meta, 'ordering') else ''
         ordering = request.GET.get('order', default_ordering)
         offset = (page - 1) * self.registers_per_page