Skip to content

Commit

Permalink
Fixed Album Pagination Erasing Search Terms (#3528)
Browse files Browse the repository at this point in the history
* Fix keywords being erased when going to next page in list of albums

* Same as the previous commit on this branch, file was missing.

* Fix url building

---------

Co-authored-by: Ties <[email protected]>
  • Loading branch information
tvanonna and T8902 authored Jan 11, 2024
1 parent 5beb6a8 commit 3431d2a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
34 changes: 16 additions & 18 deletions website/thaliawebsite/templates/paginated_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@
<nav>
<ul class="pagination mt-4">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link"
href="{{ request.path }}?page={{ page_obj.previous_page_number }}">
<span aria-hidden="true">&laquo;</span>
<span class="sr-only">Previous</span>
</a>
</li>
<li class="page-item">
<a class="page-link" href="{{ base_url }}page={{ page_obj.previous_page_number }}">
<span aria-hidden="true">&laquo;</span>
<span class="sr-only">Previous</span>
</a>
</li>
{% endif %}
{% for page in page_range %}
<li class="page-item{% if page == page_obj.number %} active{% endif %}">
<a class="page-link" href="{{ request.path }}?page={{ page }}">{{ page }}
</a>
</li>
<li class="page-item{% if page == page_obj.number %} active{% endif %}">
<a class="page-link" href="{{ base_url }}page={{ page }}">{{ page }}
</a>
</li>
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link"
href="{{ request.path }}?page={{ page_obj.next_page_number }}">
<span aria-hidden="true">&raquo;</span>
<span class="sr-only">Next</span>
</a>
</li>
<li class="page-item">
<a class="page-link" href="{{ base_url }}page={{ page_obj.next_page_number }}">
<span aria-hidden="true">&raquo;</span>
<span class="sr-only">Next</span>
</a>
</li>
{% endif %}
</ul>
</nav>
Expand Down
9 changes: 9 additions & 0 deletions website/thaliawebsite/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PagedView(ListView):

def get_context_data(self, **kwargs) -> dict:
context = super().get_context_data(**kwargs)
print(kwargs)
page = context["page_obj"].number
paginator = context["paginator"]

Expand All @@ -48,9 +49,17 @@ def get_context_data(self, **kwargs) -> dict:

page_range = range(page_range_start, page_range_stop)

querydict = self.request.GET.copy()

if "page" in querydict:
del querydict["page"]

context.update(
{
"page_range": page_range,
"base_url": f"{self.request.path}?{querydict.urlencode()}&"
if querydict
else f"{self.request.path}?",
}
)

Expand Down

0 comments on commit 3431d2a

Please sign in to comment.