aboutsummaryrefslogtreecommitdiffstats
path: root/servo/lib
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-11-11 15:24:37 +0200
committerFilipp Lepalaan <filipp@mac.com>2015-11-11 15:24:37 +0200
commitc95f56283781cbe3f372eeaccb804d2708606d6e (patch)
tree58f37aada00ab5e4efba312ff780efa83a450839 /servo/lib
parent1049e8d11c80a1838255ab37b07282a5c5d82c5b (diff)
downloadServo-c95f56283781cbe3f372eeaccb804d2708606d6e.tar.gz
Servo-c95f56283781cbe3f372eeaccb804d2708606d6e.tar.bz2
Servo-c95f56283781cbe3f372eeaccb804d2708606d6e.zip
Added paginator
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