Skip to content

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

Better category navigation

Marcin Gębala4868fd05bf1b
diff --git a/saleor/dashboard/category/urls.py b/saleor/dashboard/category/urls.py
index e4b8dfa177..33fb19e2ba 100644
--- a/saleor/dashboard/category/urls.py
+++ b/saleor/dashboard/category/urls.py
@@ -7,7 +7,7 @@ urlpatterns = patterns(
'',
url(r'^$',
views.category_list, name='categories'),
- url(r'^(?P<pk>[0-9]+)/$',
+ url(r'^(?P<root>[0-9]+)/$',
views.category_list, name='categories'),
url(r'^add/$',
views.category_details, name='category-add'),
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
index 7f31af1c4a..8a420ab14c 100644
--- a/saleor/dashboard/category/views.py
+++ b/saleor/dashboard/category/views.py
@@ -11,13 +11,12 @@ from .forms import CategoryForm
@staff_member_required
-def category_list(request, pk=None):
+def category_list(request, root=None):
ctx = {}
categories = Category.objects.all()
- if pk:
- current_node = get_object_or_404(Category, pk=pk)
- categories = current_node.get_siblings(
- include_self=True) | current_node.get_descendants()
+ if root:
+ current_node = get_object_or_404(Category, pk=root)
+ categories = current_node.get_descendants()
ctx['current_node'] = current_node
ctx['category_breadcrumbs'] = current_node.get_ancestors(include_self=True)
min_level = categories[0].get_level() if categories else 0
@@ -30,6 +29,7 @@ def category_list(request, pk=None):
@staff_member_required
def category_details(request, pk=None, parent_pk=None):
+ ctx = {}
if pk:
category = get_object_or_404(Category.objects.all(), pk=pk)
title = category.name
@@ -39,6 +39,7 @@ def category_details(request, pk=None, parent_pk=None):
initial = {}
if parent_pk:
initial['parent'] = parent_pk
+ ctx['parent_pk'] = parent_pk
form = CategoryForm(request.POST or None, instance=category, initial=initial)
if form.is_valid():
form.save()
@@ -51,7 +52,7 @@ def category_details(request, pk=None, parent_pk=None):
else:
if form.errors:
messages.error(request, _('Failed to save category'))
- ctx = {'category': category, 'form': form, 'title': title}
+ ctx.update({'category': category, 'form': form, 'title': title})
return TemplateResponse(request, 'dashboard/category/detail.html', ctx)
diff --git a/saleor/dashboard/templates/dashboard/category/list.html b/saleor/dashboard/templates/dashboard/category/list.html
index 0a0df7dd74..d81c6aebab 100644
--- a/saleor/dashboard/templates/dashboard/category/list.html
+++ b/saleor/dashboard/templates/dashboard/category/list.html
@@ -9,8 +9,7 @@
{% block page_title %}{% trans "Categories" %}{% endblock %}
{% block header_extra %}
- <a class="btn-fab btn-floating btn-large waves-effect waves-light teal"
- href="{% url 'dashboard:category-add' %}">
+ <a class="btn-fab btn-floating btn-large waves-effect waves-light teal" href="{% url 'dashboard:category-add' %}">
<i class="mdi-content-add"></i>
</a>
{% endblock %}
@@ -18,7 +17,7 @@
{% block content %}
<div class="row">
<div class="col-lg-12">
- <h1 class="page-header">{% trans "Categories" %}{% if current_node.parent %}: {{ current_node.parent }}{% endif %}</h1>
+ <h1 class="page-header">{% trans "Categories" %}{% if current_node %}: {{ current_node }}{% endif %}</h1>
{% if current_node %}
<h6>
@@ -27,17 +26,17 @@
{% if forloop.last %}
<span> / {{ item.name }}</span>
{% else %}
- <span> / <a href="{% url 'dashboard:categories' pk=item.pk %}">{{ item.name }}</a></span>
+ <span> / <a href="{% url 'dashboard:categories' root=item.pk %}">{{ item.name }}</a></span>
{% endif %}
{% endfor %}
</h6>
{% endif %}
- <a class="btn btn-default" href="{% if current_node.parent %}{% url 'dashboard:category-add' parent_pk=current_node.parent.pk %}{% else %}{% url 'dashboard:category-add' %}{% endif %}">{% trans 'Add category' %}</a>
+ <a class="btn btn-default" href="{% if current_node %}{% url 'dashboard:category-add' parent_pk=current_node.pk %}{% else %}{% url 'dashboard:category-add' %}{% endif %}">{% trans 'Add category' %}</a>
<ul class="category-list">
{% recursetree categories %}
<li>
- {% if node.level > min_level %}<a href="{% url 'dashboard:categories' pk=node.pk %}">{{ node.name }}</a>{% else %}{{ node.name }}{% endif %}
+ {% if node.level == min_level %}<a href="{% url 'dashboard:categories' root=node.pk %}">{{ node.name }}</a>{% else %}{{ node.name }}{% endif %}
<small><a href="{% url 'dashboard:category-update' pk=node.pk %}">Edit</a></small>
{% if not node.is_leaf_node %}
<ul class="children">