from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator

DEFAULT_PAGE_KEY = 'p'


def paginate(request, items, page_key=DEFAULT_PAGE_KEY, per_page=20):
    page = request.GET.get(page_key, 1)

    paginator = Paginator(items, per_page)
    try:
        page = paginator.page(page)
    except PageNotAnInteger:
        page = paginator.page(1)
    except EmptyPage:
        page = paginator.page(paginator.num_pages)

    return paginator, page

@@ -30,37 +30,8 @@
 port
- EmptyPage, PageNotAnInteger,
  Pag
@@ -37,16 +37,16 @@
 ginator%0A
+
 %0ADEFAULT
@@ -137,49 +137,8 @@
 0):%0A
-    page = request.GET.get(page_key, 1)%0A%0A
     
@@ -180,21 +180,8 @@
 ge)%0A
-    try:%0A    
     
@@ -201,154 +201,43 @@
 tor.
-page(page)%0A    except PageNotAnInteger:%0A        page = paginator.page(1)%0A    except EmptyPage:%0A        page = paginator.page(paginator.num_pages)%0A
+get_page(request.GET.get(page_key))
 %0A   

Simplify wagtail.utils.pagination using Paginator.get_page