Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Provide named arguments for search result template

Jakub Draganekcef0c8ee2337
diff --git a/saleor/dashboard/search/views.py b/saleor/dashboard/search/views.py
index 1b5f482367..c35158b37b 100644
--- a/saleor/dashboard/search/views.py
+++ b/saleor/dashboard/search/views.py
@@ -1,10 +1,5 @@
-from django.conf import settings
from django.shortcuts import render
-from ...order.models import Order
-from ...product.models import Product
-from ...search.views import paginate_results
-from ...userprofile.models import User
from ..views import staff_member_required
from .forms import DashboardSearchForm
@@ -13,19 +8,20 @@ from .forms import DashboardSearchForm
def search(request):
form = DashboardSearchForm(data=request.GET or None)
query = ''
- queryset_map = {
- Product: Product.objects.prefetch_related('images'),
- Order: Order.objects.prefetch_related('user'),
- User: User.objects.all()}
+ users = []
+ products = []
+ orders = []
if form.is_valid():
results = form.search()
- #page = paginate_results(results, request.GET, settings.PAGINATE_BY)
+ users = results['users']
+ products = results['products']
+ orders = results['orders']
query = form.cleaned_data['q']
- else:
- results = []
ctx = {
'form': form,
'query': query,
- 'results': results,
+ 'products': products,
+ 'orders': orders,
+ 'users': users,
'query_string': '?q=%s' % query}
return render(request, 'dashboard/search/results.html', ctx)
diff --git a/templates/dashboard/search/results.html b/templates/dashboard/search/results.html
index be8a589167..809d71261c 100644
--- a/templates/dashboard/search/results.html
+++ b/templates/dashboard/search/results.html
@@ -31,12 +31,10 @@
<input type="hidden" class="validate" name="q" value="{% if query %}{{ query }}{% endif %}">
</form>
</div>
- {% if results %}
<ul class="collection list">
- {% for result_type, result_items in results.items %}
<li class="collection-item avatar list-item">
- {% if result_type == 'products' %}
- {% for product in result_items %}
+ {% if products or orders or users %}
+ {% for product in products %}
<a href="{% url 'dashboard:product-detail' pk=product.pk %}">
<img src="{% product_first_image product size="60x60" method="crop" %}"
srcset="{% product_first_image product size="60x60" method="crop" %} 1x, {% product_first_image product size="120x120" method="crop" %} 2x"
@@ -51,12 +49,11 @@
</p>
</a>
{% endfor %}
- {% elif result_type == 'orders' %}
- {% for order in result_items %}
+ {% for order in orders %}
<a href="{% url 'dashboard:order-details' order_pk=order.pk %}">
<i class="small material-icons circle">payment</i>
<span class="list-item-name">
- {% blocktrans trimmed with order_number=result.pk context "Dashboard order" %}
+ {% blocktrans trimmed with order_number=order.pk context "Dashboard order" %}
Order #{{ order_number }}
{% endblocktrans %}
</span>
@@ -74,8 +71,7 @@
</p>
</a>
{% endfor %}
- {% elif result_type == 'users' %}
- {% for user in result_items %}
+ {% for user in users %}
<a href="{% url 'dashboard:customer-details' pk=user.pk %}">
<i class="small material-icons circle">perm_identity</i>
<span class="list-item-name">
@@ -90,9 +86,7 @@
</p>
</a>
{% endfor %}
- {% endif %}
</li>
- {% endfor %}
</ul>
{% include "dashboard/includes/_pagination.html" with page_obj=results %}
{% elif query %}