]> git.p6c8.net - pcdenotes.git/commitdiff
Do pagination only if there is more than one page
authorPatrick Canterino <patrick@patrick-canterino.de>
Sun, 23 Jan 2022 21:02:33 +0000 (22:02 +0100)
committerPatrick Canterino <patrick@patrick-canterino.de>
Sun, 23 Jan 2022 21:02:33 +0000 (22:02 +0100)
notes/templates/note_list.html
notes/views.py

index e77bce06508c1a8954bfcda91d7f5fd8779da0b1..f1f5ee530c591805555fda26e262dfb9384f7f03 100644 (file)
@@ -9,13 +9,15 @@
   <p>No notes</p>
   {% endfor %}
 
-  <ul class="pagination mt-5">
-    {% for page in pages %}
-      {% ifnotequal page.number page_number %}
-        <li class="page-item"><a href="?page={{ page.number }}" class="page-link">{{ page.number }}</a></li>
-      {% else %}
-        <li class="page-item active"><span class="page-link">{{ page.number }}</span></li>
-      {% endifnotequal %}
-    {% endfor %}
-  </ul>
+  {% if page_count > 1 %}
+    <ul class="pagination mt-5">
+      {% for page in pages %}
+        {% ifnotequal page.number page_number %}
+          <li class="page-item"><a href="?page={{ page.number }}" class="page-link">{{ page.number }}</a></li>
+        {% else %}
+          <li class="page-item active"><span class="page-link">{{ page.number }}</span></li>
+        {% endifnotequal %}
+      {% endfor %}
+    </ul>
+  {% endif %}
 {% endblock %}
\ No newline at end of file
index a0a82bc7c68c2673feea3d174b7ae359063dadb3..793f9ed49649edfa89ddb36ee1d8a72d143e73a2 100644 (file)
@@ -17,10 +17,12 @@ def note_list(request):
         page_number = int(request.GET.get('page'))
     except:
         pass
+
+    page_count = paginator.num_pages
     
     notes_page = paginator.get_page(page_number)
 
-    return render(request, 'note_list.html', {'notes_page': notes_page, 'notes_count': notes_count, 'pages': paginator, 'page_number': page_number})
+    return render(request, 'note_list.html', {'notes_page': notes_page, 'notes_count': notes_count, 'pages': paginator, 'page_number': page_number, 'page_count': page_count})
 
 def note_detail(request, note_slug):
     note = get_object_or_404(Note, slug=note_slug, status=1)

patrick-canterino.de