From 53ef1c54055d5657ca5f5e14b53a62a7e953ab3f Mon Sep 17 00:00:00 2001
From: Azhar Rais <dev@azharaiz.com>
Date: Fri, 30 Oct 2020 01:04:52 +0700
Subject: [PATCH] [REFACTOR] Move redundant pagination for Home and Detail to
 forum_pagination.html

---
 .../forum/forum_discussion_detail.html        | 32 +------------------
 forum/templates/forum/forum_home.html         | 32 +------------------
 forum/templates/forum/forum_pagination.html   | 31 ++++++++++++++++++
 3 files changed, 33 insertions(+), 62 deletions(-)
 create mode 100644 forum/templates/forum/forum_pagination.html

diff --git a/forum/templates/forum/forum_discussion_detail.html b/forum/templates/forum/forum_discussion_detail.html
index b2517c2..e0d40e7 100644
--- a/forum/templates/forum/forum_discussion_detail.html
+++ b/forum/templates/forum/forum_discussion_detail.html
@@ -132,37 +132,7 @@
         </div>
     </div>
 </div>
-<nav aria-label="Discussion Detail Pagination">
-    <ul class="pagination justify-content-center">
-        {% if page_obj.has_previous %}
-            <li class="page-item">
-                <a class="page-link" href="?page={{ page_obj.previous_page_number }}" tabindex="-1">Previous</a>
-            </li>
-        {% else %}
-            <li class="page-item disabled">
-                <a class="page-link" href="" tabindex="-1">Previous</a>
-            </li>
-        {% endif %}
-
-        {% for page in pages %}
-            {% if page == "..." %}
-                <li class="page-item disabled"><a class="page-link" href="">{{ page }}</a></li>
-            {% else %}
-                <li class="page-item"><a class="page-link" href="?page={{ page }}">{{ page }}</a></li>
-            {% endif %}
-        {% endfor %}
-
-        {% if page_obj.has_next %}
-            <li class="page-item">
-                <a class="page-link" href="?page={{ page_obj.next_page_number }}" tabindex="-1">Next</a>
-            </li>
-        {% else %}
-            <li class="page-item disabled">
-                <a class="page-link" href="" tabindex="-1">Next</a>
-            </li>
-        {% endif %}
-    </ul>
-</nav>
+{% include 'forum/forum_pagination.html' %}
 </div>
 {% endblock content %}
 {% block extra_scripts %}
diff --git a/forum/templates/forum/forum_home.html b/forum/templates/forum/forum_home.html
index 4c2ae90..ec7af76 100644
--- a/forum/templates/forum/forum_home.html
+++ b/forum/templates/forum/forum_home.html
@@ -31,36 +31,6 @@
         {% empty %}
             <h4 id="no-discussion">There is no discussion at the moment</h4>
         {% endfor %}
-        <nav aria-label="Page navigation example">
-            <ul class="pagination justify-content-center">
-                {% if page_obj.has_previous %}
-                    <li class="page-item">
-                        <a class="page-link" href="?page={{ page_obj.previous_page_number }}" tabindex="-1">Previous</a>
-                    </li>
-                {% else %}
-                    <li class="page-item disabled">
-                        <a class="page-link" href="" tabindex="-1">Previous</a>
-                    </li>
-                {% endif %}
-
-                {% for page in pages %}
-                    {% if page == "..." %}
-                        <li class="page-item disabled"><a class="page-link" href="">{{ page }}</a></li>
-                    {% else %}
-                        <li class="page-item"><a class="page-link" href="?page={{ page }}">{{ page }}</a></li>
-                    {% endif %}
-                {% endfor %}
-
-                {% if page_obj.has_next %}
-                    <li class="page-item">
-                        <a class="page-link" href="?page={{ page_obj.next_page_number }}" tabindex="-1">Next</a>
-                    </li>
-                {% else %}
-                    <li class="page-item disabled">
-                        <a class="page-link" href="" tabindex="-1">Next</a>
-                    </li>
-                {% endif %}
-            </ul>
-        </nav>
+        {% include 'forum/forum_pagination.html' %}
     </div>
 {% endblock content %}
\ No newline at end of file
diff --git a/forum/templates/forum/forum_pagination.html b/forum/templates/forum/forum_pagination.html
new file mode 100644
index 0000000..04287c5
--- /dev/null
+++ b/forum/templates/forum/forum_pagination.html
@@ -0,0 +1,31 @@
+<nav aria-label="Page navigation example">
+    <ul class="pagination justify-content-center">
+        {% if page_obj.has_previous %}
+            <li class="page-item">
+                <a class="page-link" href="?page={{ page_obj.previous_page_number }}" tabindex="-1">Previous</a>
+            </li>
+        {% else %}
+            <li class="page-item disabled">
+                <a class="page-link" href="" tabindex="-1">Previous</a>
+            </li>
+        {% endif %}
+
+        {% for page in pages %}
+            {% if page == "..." %}
+                <li class="page-item disabled"><a class="page-link" href="">{{ page }}</a></li>
+            {% else %}
+                <li class="page-item"><a class="page-link" href="?page={{ page }}">{{ page }}</a></li>
+            {% endif %}
+        {% endfor %}
+
+        {% if page_obj.has_next %}
+            <li class="page-item">
+                <a class="page-link" href="?page={{ page_obj.next_page_number }}" tabindex="-1">Next</a>
+            </li>
+        {% else %}
+            <li class="page-item disabled">
+                <a class="page-link" href="" tabindex="-1">Next</a>
+            </li>
+        {% endif %}
+    </ul>
+</nav>
\ No newline at end of file
-- 
GitLab