Make search stay active during page changes
This commit is contained in:
parent
1c56dd44f9
commit
3d263ca27c
@ -2,6 +2,7 @@ from django.shortcuts import render, redirect
|
|||||||
from django.urls import resolve, reverse
|
from django.urls import resolve, reverse
|
||||||
from django.contrib.auth import logout, login
|
from django.contrib.auth import logout, login
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.utils.http import urlencode
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from .navbar import NavBar
|
from .navbar import NavBar
|
||||||
from django.contrib.auth.forms import AuthenticationForm as AuthForm
|
from django.contrib.auth.forms import AuthenticationForm as AuthForm
|
||||||
@ -283,6 +284,7 @@ class ComponentView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
context['components'] = comp_paginator.get_page(comp_page_num)
|
context['components'] = comp_paginator.get_page(comp_page_num)
|
||||||
context['comp_form'] = ComponentForm()
|
context['comp_form'] = ComponentForm()
|
||||||
context['search_string'] = search
|
context['search_string'] = search
|
||||||
|
context['additional_get_params'] = urlencode({'search': self.request.GET.get('search', default='')}) if search else None
|
||||||
|
|
||||||
if not parameter_formset:
|
if not parameter_formset:
|
||||||
context['advanced_search_param_formset'] = ParameterSearchFormSet()
|
context['advanced_search_param_formset'] = ParameterSearchFormSet()
|
||||||
@ -367,6 +369,11 @@ class PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
context['search_string'] = search_string
|
context['search_string'] = search_string
|
||||||
context['packages'] = paginator.get_page(page_num)
|
context['packages'] = paginator.get_page(page_num)
|
||||||
context['new_pkg_form'] = PackageForm()
|
context['new_pkg_form'] = PackageForm()
|
||||||
|
get_params_for_paginator = None
|
||||||
|
if search_string:
|
||||||
|
get_params_for_paginator = urlencode({'search': search_string})
|
||||||
|
|
||||||
|
context['additional_get_params'] = get_params_for_paginator
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
@ -566,7 +573,8 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
context['add_storage_form'] = add_storage_form
|
context['add_storage_form'] = add_storage_form
|
||||||
context['delete_storage_error'] = None
|
context['delete_storage_error'] = None
|
||||||
context['add_stock_form'] = AddStockForm()
|
context['add_stock_form'] = AddStockForm()
|
||||||
|
if stock_search_input:
|
||||||
|
context['additional_params'] = urlencode({'search': stock_search_input})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def handle_add_storage_post(self, request, **kwargs):
|
def handle_add_storage_post(self, request, **kwargs):
|
||||||
|
@ -2,21 +2,21 @@
|
|||||||
<nav aria-label="{{aria_label}}">
|
<nav aria-label="{{aria_label}}">
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
{% if paginator.has_previous %}
|
{% if paginator.has_previous %}
|
||||||
<li class="page-item"><a class="page-link" href="?{{get_param}}={{paginator.previous_page_number}}">«</a></li>
|
<li class="page-item"><a class="page-link" href="?{{get_param}}={{paginator.previous_page_number}}{% if additional_params %}&{{additional_params}}{% endif %}">«</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="page-item disabled"><span class="page-link">«</span></li>
|
<li class="page-item disabled"><span class="page-link">«</span></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for i in paginator.paginator.page_range %}
|
{% for i in paginator.paginator.page_range %}
|
||||||
{% if i <= paginator.number|add:5 and i >= paginator.number|add:-5 %}
|
{% if i <= paginator.number|add:5 and i >= paginator.number|add:-5 %}
|
||||||
{% if i == paginator.number %}
|
{% if i == paginator.number %}
|
||||||
<li class="page-item active"><a class="page-link" href="?{{get_param}}={{i}}">{{i}}</a></li>
|
<li class="page-item active"><a class="page-link" href="?{{get_param}}={{i}}{% if additional_params %}&{{additional_params}}{% endif %}">{{i}}</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="page-item"><a class="page-link" href="?{{get_param}}={{i}}">{{i}}</a></li>
|
<li class="page-item"><a class="page-link" href="?{{get_param}}={{i}}{% if additional_params %}&{{additional_params}}{% endif %}">{{i}}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if paginator.has_next %}
|
{% if paginator.has_next %}
|
||||||
<li class="page-item"><a class="page-link" href="?{{get_param}}={{paginator.next_page_number}}">»</a></li>
|
<li class="page-item"><a class="page-link" href="?{{get_param}}={{paginator.next_page_number}}{% if additional_params %}&{{additional_params}}{% endif %}">»</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="page-item disabled"><span class="page-link">»</span></li>
|
<li class="page-item disabled"><span class="page-link">»</span></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% include 'paginator.html' with paginator=comptypes get_param='page' aria_label='Component Type Page Navigation' %}
|
{% include 'paginator.html' with paginator=comptypes get_param='page' aria_label='Component Type Page Navigation' additional_params=None %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% include 'paginator.html' with paginator=components get_param='comp_page' aria_label='Component Page Navigation' %}
|
{% include 'paginator.html' with paginator=components get_param='comp_page' aria_label='Component Page Navigation' additional_params=additional_get_params %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
{% include 'paginator.html' with paginator=packages get_param='page' aria_label='Package Page Navigation' %}
|
{% include 'paginator.html' with paginator=packages get_param='page' aria_label='Package Page Navigation' additional_params=additional_get_params %}
|
||||||
</div>
|
</div>
|
||||||
<div class="list-group mb-3">
|
<div class="list-group mb-3">
|
||||||
{% for pkg in packages %}
|
{% for pkg in packages %}
|
||||||
@ -42,7 +42,7 @@
|
|||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% include 'paginator.html' with paginator=packages get_param='page' aria_label='Package Page Navigation' %}
|
{% include 'paginator.html' with paginator=packages get_param='page' aria_label='Package Page Navigation' additional_params=additional_get_params %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user