diff --git a/app/enquiries/templates/enquiry_list.html b/app/enquiries/templates/enquiry_list.html index d4c47ff5..228d985d 100644 --- a/app/enquiries/templates/enquiry_list.html +++ b/app/enquiries/templates/enquiry_list.html @@ -52,21 +52,21 @@

Enquiries

    {%if previous is not None %}
  1. - Previous + Previous
  2. {%endif%} {% for page in page_range %} {% if page|stringformat:"s" == current_page %} -
  3. {{ page }}
  4. +
  5. {{ page }}
  6. {% else %} -
  7. {{ page }}
  8. +
  9. {{ page }}
  10. {% endif %} {% endfor %} {%if next is not None %}
  11. - Next + Next
  12. {%endif%}
diff --git a/app/enquiries/templatetags/enquiries_extras.py b/app/enquiries/templatetags/enquiries_extras.py index 9f7600cc..c4675ca3 100644 --- a/app/enquiries/templatetags/enquiries_extras.py +++ b/app/enquiries/templatetags/enquiries_extras.py @@ -91,3 +91,31 @@ def query_params_has_value(value, param_key, query_params): @register.simple_tag def query_params_value_selected(value, param_key, query_params, text='selected'): return f' {text}' if str(value) in query_params.getlist(param_key) else '' + + +@register.simple_tag +def query_params_with_pagination(query_params, page): + filter_params = '&'.join([f"{key}={value}" for key, value in query_params.items() if key != "page"]) + + if page and filter_params: + return f"page={page}&{filter_params}" + elif filter_params: + return filter_params + else: + return f"page={page}" + + +@register.simple_tag +def query_params_with_previous_page(query_params, current_page): + if current_page > 1: + current_page = current_page - 1 + + return query_params_with_pagination(query_params, current_page) + + +@register.simple_tag +def query_params_with_next_page(query_params, current_page, total_pages): + if current_page < total_pages: + current_page = int(current_page) + 1 + + return query_params_with_pagination(query_params, current_page)