aboutsummaryrefslogtreecommitdiffstats
path: root/servo/lib
diff options
context:
space:
mode:
Diffstat (limited to 'servo/lib')
-rw-r--r--servo/lib/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/servo/lib/utils.py b/servo/lib/utils.py
index 6d1ee0b..8d4bb91 100644
--- a/servo/lib/utils.py
+++ b/servo/lib/utils.py
@@ -6,8 +6,24 @@ from django.db.models import Model
from django.core.cache import cache
from django.http import HttpResponse
from django.core.serializers.json import DjangoJSONEncoder
+from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
+def paginate(queryset, page, count=10):
+ """
+ Shortcut for paginating a queryset
+ """
+ paginator = Paginator(queryset, count)
+
+ try:
+ results = paginator.page(page)
+ except PageNotAnInteger:
+ results = paginator.page(1)
+ except EmptyPage:
+ results = paginator.page(paginator.num_pages)
+
+ return results
+
def csv_response(data):
"""
Shortcut for sending a CSV response