From 6d6ba89a9a20eb7854ddc71eba1ab42d4cf2a21b Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 3 Mar 2024 03:25:02 +0200 Subject: [PATCH] convert pagination into a macro --- files/templates/admin/dm_media.html | 2 +- files/templates/admin/image_posts.html | 2 +- files/templates/admin/removed_posts.html | 2 +- files/templates/admin/reported_posts.html | 2 +- files/templates/admin/shadowbanned.html | 2 +- files/templates/bank_statement.html | 2 +- files/templates/banned.html | 2 +- files/templates/blocks.html | 2 +- files/templates/comments.html | 1 - files/templates/group_memberships.html | 1 - files/templates/home.html | 9 ++-- files/templates/home_comments.html | 5 +- files/templates/log.html | 2 +- files/templates/notifications.html | 2 +- files/templates/owners.html | 2 +- files/templates/pagination.html | 64 ---------------------- files/templates/post.html | 3 +- files/templates/post_banned.html | 3 +- files/templates/post_listing.html | 1 - files/templates/search.html | 5 +- files/templates/settings/common.html | 1 - files/templates/transfers.html | 2 +- files/templates/user_cards.html | 2 +- files/templates/userpage/blockers.html | 2 +- files/templates/userpage/blocking.html | 2 +- files/templates/userpage/followers.html | 2 +- files/templates/userpage/following.html | 2 +- files/templates/userpage/header.html | 3 +- files/templates/userpage/muters.html | 2 +- files/templates/userpage/muting.html | 2 +- files/templates/userpage/userpage.html | 2 +- files/templates/userpage/views.html | 2 +- files/templates/userpage/voted_posts.html | 2 +- files/templates/userpage/voters.html | 2 +- files/templates/util/macros.html | 65 +++++++++++++++++++++++ 35 files changed, 99 insertions(+), 108 deletions(-) delete mode 100644 files/templates/pagination.html diff --git a/files/templates/admin/dm_media.html b/files/templates/admin/dm_media.html index 7593f4ce4..90446f53c 100644 --- a/files/templates/admin/dm_media.html +++ b/files/templates/admin/dm_media.html @@ -59,5 +59,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/admin/image_posts.html b/files/templates/admin/image_posts.html index da0e32d14..000fad3ea 100644 --- a/files/templates/admin/image_posts.html +++ b/files/templates/admin/image_posts.html @@ -17,5 +17,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/admin/removed_posts.html b/files/templates/admin/removed_posts.html index 6f7e4cdbb..de0be4e1c 100644 --- a/files/templates/admin/removed_posts.html +++ b/files/templates/admin/removed_posts.html @@ -28,5 +28,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/admin/reported_posts.html b/files/templates/admin/reported_posts.html index e4fa6be99..bbcd4ecae 100644 --- a/files/templates/admin/reported_posts.html +++ b/files/templates/admin/reported_posts.html @@ -30,5 +30,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/admin/shadowbanned.html b/files/templates/admin/shadowbanned.html index 51af63366..6f2729187 100644 --- a/files/templates/admin/shadowbanned.html +++ b/files/templates/admin/shadowbanned.html @@ -37,5 +37,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/bank_statement.html b/files/templates/bank_statement.html index 48b87533c..a15ca8085 100644 --- a/files/templates/bank_statement.html +++ b/files/templates/bank_statement.html @@ -38,7 +38,7 @@ {% endfor %} - {% include "pagination.html" %} + {{macros.pagination("pb-0 pl-0 pt-1")}} diff --git a/files/templates/banned.html b/files/templates/banned.html index 06928481f..b058d41e2 100644 --- a/files/templates/banned.html +++ b/files/templates/banned.html @@ -37,5 +37,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/blocks.html b/files/templates/blocks.html index d9e0ff336..8dfa4d410 100644 --- a/files/templates/blocks.html +++ b/files/templates/blocks.html @@ -37,5 +37,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/comments.html b/files/templates/comments.html index 0b09a3a3f..939f79c89 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -1,4 +1,3 @@ -{%- import 'util/macros.html' as macros with context -%} {% if not request.headers.get("xhr") %} {% if focused_comment %} diff --git a/files/templates/group_memberships.html b/files/templates/group_memberships.html index 277c178a7..dd4606dda 100644 --- a/files/templates/group_memberships.html +++ b/files/templates/group_memberships.html @@ -1,5 +1,4 @@ {% extends "default.html" %} -{%- import 'util/macros.html' as macros with context -%} {% block pagetitle %}!{{group}}{% endblock %} {% block content %}
diff --git a/files/templates/home.html b/files/templates/home.html index f20536ac5..479e3cf9f 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -89,8 +89,7 @@ - {%- import 'util/macros.html' as macros with context -%} - {{- macros.time_filter_buttons() -}} + {{- macros.time_filter_buttons() -}} {{- macros.sorting_buttons(POST_SORTS, True) -}}
{% endblock %} @@ -102,8 +101,8 @@ {% block PseudoSubmitForm %}{% endblock %} {% block content %} - {% if SITE_NAME == 'WPD' and listing %} - {% include "pagination.html" %} + {% if (SITE_NAME == 'WPD' and listing) or True %} + {{macros.pagination("pl-1 py-0")}} {% endif %}
@@ -117,7 +116,7 @@ {% block pagenav %} {% if listing %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endif %} {% if request.path == '/' and v %} diff --git a/files/templates/home_comments.html b/files/templates/home_comments.html index 140cf3eba..035ca5036 100644 --- a/files/templates/home_comments.html +++ b/files/templates/home_comments.html @@ -7,8 +7,7 @@ {% block content %}
- {%- import 'util/macros.html' as macros with context -%} - {{- macros.time_filter_buttons() -}} + {{- macros.time_filter_buttons() -}} {{- macros.sorting_buttons(COMMENT_SORTS) -}}
@@ -23,5 +22,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/log.html b/files/templates/log.html index 121e58d71..428a1b4ab 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -86,7 +86,7 @@
There's nothing here right now.
{% endfor %}
- {% include "pagination.html" %} + {{macros.pagination()}} diff --git a/files/templates/notifications.html b/files/templates/notifications.html index 9d0421124..5c495b225 100644 --- a/files/templates/notifications.html +++ b/files/templates/notifications.html @@ -130,7 +130,7 @@ {% block pagenav %} {% if notifications %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endif %} diff --git a/files/templates/owners.html b/files/templates/owners.html index a1c4efda5..0bae3f942 100644 --- a/files/templates/owners.html +++ b/files/templates/owners.html @@ -23,5 +23,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/pagination.html b/files/templates/pagination.html deleted file mode 100644 index 833bc37a6..000000000 --- a/files/templates/pagination.html +++ /dev/null @@ -1,64 +0,0 @@ - - diff --git a/files/templates/post.html b/files/templates/post.html index 95513032b..434f020c2 100644 --- a/files/templates/post.html +++ b/files/templates/post.html @@ -305,8 +305,7 @@
- {%- import 'util/macros.html' as macros with context -%} - {{- macros.sorting_buttons(COMMENT_SORTS, True) -}} + {{- macros.sorting_buttons(COMMENT_SORTS, True) -}}
{{macros.comment_reply_box(p.fullname, 'comment-reply-' + p.fullname, subwrapper_css_classes='mb-3', enable_cancel_button=false)}} diff --git a/files/templates/post_banned.html b/files/templates/post_banned.html index 60a9da4c1..56a58829a 100644 --- a/files/templates/post_banned.html +++ b/files/templates/post_banned.html @@ -49,8 +49,7 @@
- {%- import 'util/macros.html' as macros with context -%} - {{- macros.sorting_buttons(COMMENT_SORTS, True) -}} + {{- macros.sorting_buttons(COMMENT_SORTS, True) -}}
diff --git a/files/templates/post_listing.html b/files/templates/post_listing.html index f1eb675e5..dad9fdaca 100644 --- a/files/templates/post_listing.html +++ b/files/templates/post_listing.html @@ -1,4 +1,3 @@ -{%- import 'util/macros.html' as macros with context -%} {% if v %} {% include "modals/award.html" %} diff --git a/files/templates/search.html b/files/templates/search.html index f0c9af1e2..642e90f5a 100644 --- a/files/templates/search.html +++ b/files/templates/search.html @@ -103,8 +103,7 @@ {% if not '/users' in request.path %}
- {%- import 'util/macros.html' as macros with context -%} - {{- macros.time_filter_buttons() -}} + {{- macros.time_filter_buttons() -}} {% if "/posts" in request.path %} {{- macros.sorting_buttons(POST_SORTS) -}} {% else %} @@ -148,5 +147,5 @@
{% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/settings/common.html b/files/templates/settings/common.html index ca511efd7..893784817 100644 --- a/files/templates/settings/common.html +++ b/files/templates/settings/common.html @@ -1,4 +1,3 @@ -{%- import 'util/macros.html' as macros with context -%} {% macro toggle_section(title, id, name, flag, below_text, disabled) %}
diff --git a/files/templates/transfers.html b/files/templates/transfers.html index 94127a93b..468785417 100644 --- a/files/templates/transfers.html +++ b/files/templates/transfers.html @@ -13,7 +13,7 @@
{% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}}
Link copied to clipboard diff --git a/files/templates/user_cards.html b/files/templates/user_cards.html index ab66c913e..f301a3509 100644 --- a/files/templates/user_cards.html +++ b/files/templates/user_cards.html @@ -8,6 +8,6 @@
{% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} {% block navbar %}{% endblock %} diff --git a/files/templates/userpage/blockers.html b/files/templates/userpage/blockers.html index 48f2c2df6..b1bf7875e 100644 --- a/files/templates/userpage/blockers.html +++ b/files/templates/userpage/blockers.html @@ -23,7 +23,7 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} ({{total}} user{{macros.plural(total)}}) diff --git a/files/templates/userpage/blocking.html b/files/templates/userpage/blocking.html index aa4b92bcf..bd7d94b36 100644 --- a/files/templates/userpage/blocking.html +++ b/files/templates/userpage/blocking.html @@ -36,5 +36,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/userpage/followers.html b/files/templates/userpage/followers.html index 3bffc7282..333c0fc03 100644 --- a/files/templates/userpage/followers.html +++ b/files/templates/userpage/followers.html @@ -35,5 +35,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/userpage/following.html b/files/templates/userpage/following.html index ddcc1dc93..d2774e9ad 100644 --- a/files/templates/userpage/following.html +++ b/files/templates/userpage/following.html @@ -35,5 +35,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/userpage/header.html b/files/templates/userpage/header.html index 77dc6e45b..970c1423c 100644 --- a/files/templates/userpage/header.html +++ b/files/templates/userpage/header.html @@ -31,8 +31,7 @@
- {%- import 'util/macros.html' as macros with context -%} - {{- macros.time_filter_buttons() -}} + {{- macros.time_filter_buttons() -}} {% if "/posts" in request.path %} {{- macros.sorting_buttons(POST_SORTS) -}} {% else %} diff --git a/files/templates/userpage/muters.html b/files/templates/userpage/muters.html index 9c56b5954..6e46fdb79 100644 --- a/files/templates/userpage/muters.html +++ b/files/templates/userpage/muters.html @@ -23,5 +23,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/userpage/muting.html b/files/templates/userpage/muting.html index 7f4d74e66..ce2b0ca03 100644 --- a/files/templates/userpage/muting.html +++ b/files/templates/userpage/muting.html @@ -35,5 +35,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/userpage/userpage.html b/files/templates/userpage/userpage.html index 7aa913f37..0ff51effd 100644 --- a/files/templates/userpage/userpage.html +++ b/files/templates/userpage/userpage.html @@ -40,7 +40,7 @@ {% block pagenav %} {% if listing %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endif %} {% if request.path.endswith('/posts') %} diff --git a/files/templates/userpage/views.html b/files/templates/userpage/views.html index 1cf06905f..c550b0958 100644 --- a/files/templates/userpage/views.html +++ b/files/templates/userpage/views.html @@ -26,5 +26,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/userpage/voted_posts.html b/files/templates/userpage/voted_posts.html index b52fd24f8..7ed31337e 100644 --- a/files/templates/userpage/voted_posts.html +++ b/files/templates/userpage/voted_posts.html @@ -29,5 +29,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/userpage/voters.html b/files/templates/userpage/voters.html index 92ec83506..6f8a2aa4e 100644 --- a/files/templates/userpage/voters.html +++ b/files/templates/userpage/voters.html @@ -37,5 +37,5 @@ {% endblock %} {% block pagenav %} - {% include "pagination.html" %} + {{macros.pagination()}} {% endblock %} diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index c1f0329fe..2d7bcaa6f 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -439,3 +439,68 @@
{% endmacro %} + + +{% macro pagination(classes="pl-1 mt-4") %} +
    + {% if not size %} + {% set size = PAGE_SIZE %} + {% endif %} + {% set num_pages = (total / size) | round(0, 'ceil') | int %} + + {% set start_point = page - 2 %} + {% if start_point < 1 %} + {% set start_point = 1 %} + {% endif %} + + {% set end_point = start_point+4 %} + {% if end_point > num_pages %} + {% set start_point = start_point-(end_point-num_pages) %} + {% set end_point = num_pages %} + {% endif %} + + {% if start_point < 1 %} + {% set start_point = 1 %} + {% endif %} + + + {% if start_point > 1 %} +
  • + 1 +
  • + + {% if start_point == 3 %} +
  • + 2 +
  • + {% elif start_point != 2 %} +
  • + ... +
  • + {% set start_point = start_point + 1 %} + {% endif %} + {% endif %} + + {% for x in range(start_point, end_point+1) %} +
  • + {{x}} +
  • + {% endfor %} + + {% if end_point < num_pages %} + {% if end_point == num_pages-2 %} +
  • + {{num_pages-1}} +
  • + {% elif end_point != num_pages-1 %} +
  • + ... +
  • + {% endif %} + +
  • + {{num_pages}} +
  • + {% endif %} +
+{% endmacro %}