X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/aa974af0f752e8b3e23337764e0bbd5e140217d8..e75f306d2a639471d2a5eef2ff698acfcb1fbcb6:/contrib/penfield/utils.py?ds=sidebyside diff --git a/contrib/penfield/utils.py b/contrib/penfield/utils.py deleted file mode 100644 index 0318e5e..0000000 --- a/contrib/penfield/utils.py +++ /dev/null @@ -1,33 +0,0 @@ -from django.core.paginator import Paginator - - -def paginate(objects, per_page=None, page_number=1): - """ - Given a list of objects, return a (page, obj_list) tuple. - """ - try: - per_page = int(per_page) - except (TypeError, ValueError): - # Then either it wasn't set or it was set to an invalid value - return None, objects - - # There also shouldn't be pagination if the list is too short. Try count() - # first - good chance it's a queryset, where count is more efficient. - try: - if objects.count() <= per_page: - return None, objects - except AttributeError: - if len(objects) <= per_page: - return None, objects - - paginator = Paginator(objects, per_page) - try: - page_number = int(page_number) - except: - page_number = 1 - - # This will raise an EmptyPage error if the page number is out of range. - # This error is intentionally left for the calling function to handle. - page = paginator.page(page_number) - - return page, page.object_list \ No newline at end of file