diff --git a/ram/portal/templates/consist.html b/ram/portal/templates/consist.html index 9e2fb85..ede03fb 100644 --- a/ram/portal/templates/consist.html +++ b/ram/portal/templates/consist.html @@ -112,13 +112,17 @@ Previous {% endif %} - {% for i in rolling_stock.paginator.page_range %} + {% for i in rolling_stock.paginator.get_elided_page_range %} {% if rolling_stock.number == i %}
  • {{ i }}
  • {% else %} -
  • {{ i }}
  • + {% if i == rolling_stock.paginator.ELLIPSIS %} +
  • {{ i }}
  • + {% else %} +
  • {{ i }}
  • + {% endif %} {% endif %} {% endfor %} {% if rolling_stock.has_next %} diff --git a/ram/portal/templates/consists.html b/ram/portal/templates/consists.html index af72f1c..168d2c4 100644 --- a/ram/portal/templates/consists.html +++ b/ram/portal/templates/consists.html @@ -70,13 +70,17 @@ Previous {% endif %} - {% for i in consist.paginator.page_range %} + {% for i in consist.paginator.get_elided_page_range %} {% if consist.number == i %}
  • {{ i }}
  • {% else %} -
  • {{ i }}
  • + {% if i == rolling_stock.paginator.ELLIPSIS %} +
  • {{ i }}
  • + {% else %} +
  • {{ i }}
  • + {% endif %} {% endif %} {% endfor %} {% if consist.has_next %} diff --git a/ram/portal/templates/home.html b/ram/portal/templates/home.html index b19f0cd..6b78909 100644 --- a/ram/portal/templates/home.html +++ b/ram/portal/templates/home.html @@ -19,13 +19,17 @@ Previous {% endif %} - {% for i in rolling_stock.paginator.page_range %} + {% for i in rolling_stock.paginator.get_elided_page_range %} {% if rolling_stock.number == i %}
  • {{ i }}
  • {% else %} -
  • {{ i }}
  • + {% if i == rolling_stock.paginator.ELLIPSIS %} +
  • {{ i }}
  • + {% else %} +
  • {{ i }}
  • + {% endif %} {% endif %} {% endfor %} {% if rolling_stock.has_next %} diff --git a/ram/portal/templates/search.html b/ram/portal/templates/search.html index 92f9c41..fd72f2a 100644 --- a/ram/portal/templates/search.html +++ b/ram/portal/templates/search.html @@ -17,13 +17,17 @@ Previous {% endif %} - {% for i in rolling_stock.paginator.page_range %} + {% for i in rolling_stock.paginator.get_elided_page_range %} {% if rolling_stock.number == i %}
  • {{ i }}
  • {% else %} -
  • {{ i }}
  • + {% if i == rolling_stock.paginator.ELLIPSIS %} +
  • {{ i }}
  • + {% else %} +
  • {{ i }}
  • + {% endif %} {% endif %} {% endfor %} {% if rolling_stock.has_next %} diff --git a/ram/portal/views.py b/ram/portal/views.py index 8686afa..c790da4 100644 --- a/ram/portal/views.py +++ b/ram/portal/views.py @@ -32,15 +32,8 @@ class GetHome(View): def get(self, request, page=1): site_conf = get_site_conf() rolling_stock = RollingStock.objects.order_by(*order_by_fields()) - paginator = Paginator(rolling_stock, site_conf.items_per_page) - - try: - rolling_stock = paginator.page(page) - except PageNotAnInteger: - rolling_stock = paginator.page(1) - except EmptyPage: - rolling_stock = paginator.page(paginator.num_pages) + rolling_stock = paginator.get_page(page) return render(request, "home.html", {"rolling_stock": rolling_stock}) @@ -82,13 +75,7 @@ class GetHomeFiltered(View): ) matches = len(rolling_stock) paginator = Paginator(rolling_stock, site_conf.items_per_page) - - try: - rolling_stock = paginator.page(page) - except PageNotAnInteger: - rolling_stock = paginator.page(1) - except EmptyPage: - rolling_stock = paginator.page(paginator.num_pages) + rolling_stock = paginator.get_page(page) return rolling_stock, matches @@ -161,13 +148,7 @@ class Consists(View): site_conf = get_site_conf() consist = Consist.objects.all() paginator = Paginator(consist, site_conf.items_per_page) - - try: - consist = paginator.page(page) - except PageNotAnInteger: - consist = paginator.page(1) - except EmptyPage: - consist = paginator.page(paginator.num_pages) + consist = paginator.get_page(page) return render(request, "consists.html", {"consist": consist}) @@ -181,13 +162,7 @@ class GetConsist(View): raise Http404 rolling_stock = consist.consist_item.all() paginator = Paginator(rolling_stock, site_conf.items_per_page) - - try: - rolling_stock = paginator.page(page) - except PageNotAnInteger: - rolling_stock = paginator.page(1) - except EmptyPage: - rolling_stock = paginator.page(paginator.num_pages) + rolling_stock = paginator.get_page(page) return render( request,