mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Closes #7239: Redirect global search to filtered object list when an object type is selected
This commit is contained in:
parent
ab0a2abc54
commit
147a4cbfb0
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## v3.0.3 (FUTURE)
|
## v3.0.3 (FUTURE)
|
||||||
|
|
||||||
|
### Enhancements
|
||||||
|
|
||||||
|
* [#7239](https://github.com/netbox-community/netbox/issues/7239) - Redirect global search to filtered object list when an object type is selected
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
* [#7167](https://github.com/netbox-community/netbox/issues/7167) - Ensure consistent font size when using monospace formatting
|
* [#7167](https://github.com/netbox-community/netbox/issues/7167) - Ensure consistent font size when using monospace formatting
|
||||||
|
@ -26,7 +26,6 @@ from ipam.models import Aggregate, IPAddress, IPRange, Prefix, VLAN, VRF
|
|||||||
from netbox.constants import SEARCH_MAX_RESULTS, SEARCH_TYPES
|
from netbox.constants import SEARCH_MAX_RESULTS, SEARCH_TYPES
|
||||||
from netbox.forms import SearchForm
|
from netbox.forms import SearchForm
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from utilities.tables import paginate_table
|
|
||||||
from virtualization.models import Cluster, VirtualMachine
|
from virtualization.models import Cluster, VirtualMachine
|
||||||
|
|
||||||
|
|
||||||
@ -154,26 +153,18 @@ class HomeView(View):
|
|||||||
class SearchView(View):
|
class SearchView(View):
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
||||||
# No query
|
|
||||||
if 'q' not in request.GET:
|
|
||||||
return render(request, 'search.html', {
|
|
||||||
'form': SearchForm(),
|
|
||||||
})
|
|
||||||
|
|
||||||
form = SearchForm(request.GET)
|
form = SearchForm(request.GET)
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
|
||||||
|
# If an object type has been specified, redirect to the dedicated view for it
|
||||||
if form.cleaned_data['obj_type']:
|
if form.cleaned_data['obj_type']:
|
||||||
# Searching for a single type of object
|
object_type = form.cleaned_data['obj_type']
|
||||||
obj_types = [form.cleaned_data['obj_type']]
|
url = reverse(SEARCH_TYPES[object_type]['url'])
|
||||||
else:
|
return redirect(f"{url}?q={form.cleaned_data['q']}")
|
||||||
# Searching all object types
|
|
||||||
obj_types = SEARCH_TYPES.keys()
|
|
||||||
|
|
||||||
for obj_type in obj_types:
|
for obj_type in SEARCH_TYPES.keys():
|
||||||
|
|
||||||
queryset = SEARCH_TYPES[obj_type]['queryset'].restrict(request.user, 'view')
|
queryset = SEARCH_TYPES[obj_type]['queryset'].restrict(request.user, 'view')
|
||||||
filterset = SEARCH_TYPES[obj_type]['filterset']
|
filterset = SEARCH_TYPES[obj_type]['filterset']
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col col-12 col-lg-4 offset-lg-4">
|
<div class="col col-12 col-lg-6 offset-lg-3">
|
||||||
<form action="{% url 'search' %}" method="get" class="form form-horizontal">
|
<form action="{% url 'search' %}" method="get" class="form form-horizontal">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h5 class="card-header">
|
<h5 class="card-header">
|
||||||
|
Loading…
Reference in New Issue
Block a user