Skip to content

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

Improve rendering categories tree

Marcin Gębala11b4bf9c4524
diff --git a/saleor/dashboard/category/urls.py b/saleor/dashboard/category/urls.py
index 89d184425c..c2efdbb480 100644
--- a/saleor/dashboard/category/urls.py
+++ b/saleor/dashboard/category/urls.py
@@ -7,9 +7,11 @@ urlpatterns = patterns(
'',
url(r'^$',
views.category_list, name='categories'),
- url(r'^(?P<pk>[0-9]+)/update/$',
- views.category_details, name='category-update'),
+ url(r'^(?P<pk>[0-9]+)/$',
+ views.category_list, name='categories'),
url(r'^add/$',
views.category_details, name='category-add'),
+ url(r'^(?P<pk>[0-9]+)/update/$',
+ views.category_details, name='category-update'),
url(r'^(?P<pk>[0-9]+)/delete/$',
views.CategoryDeleteView.as_view(), name='category-delete'))
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
index a338179371..4aada837a7 100644
--- a/saleor/dashboard/category/views.py
+++ b/saleor/dashboard/category/views.py
@@ -11,9 +11,16 @@ from .forms import CategoryForm
@staff_member_required
-def category_list(request):
+def category_list(request, pk=None):
+ ctx = {}
categories = Category.objects.all()
- ctx = {'categories': categories}
+ if pk:
+ current_node = get_object_or_404(Category, pk=pk)
+ categories = current_node.get_siblings(
+ include_self=True) | current_node.get_descendants()
+ ctx['current_node'] = current_node
+ ctx['categories'] = categories
+ ctx['root_level'] = categories[0].get_level() if categories else 0
return TemplateResponse(request, 'dashboard/category/list.html', ctx)
diff --git a/saleor/dashboard/templates/dashboard/category/list.html b/saleor/dashboard/templates/dashboard/category/list.html
index cd5c2bc951..6d8ad00619 100644
--- a/saleor/dashboard/templates/dashboard/category/list.html
+++ b/saleor/dashboard/templates/dashboard/category/list.html
@@ -7,12 +7,13 @@
{% block content %}
<div class="row">
<div class="col-lg-12">
- <h1 class="page-header">{% trans "Categories" %}</h1>
+ <h1 class="page-header">{% trans "Categories" %}{% if current_node %}: {{ current_node }}{% endif %}</h1>
<a class="btn btn-default" href="{% url 'dashboard:category-add' %}">{% trans 'Add category' %}</a>
- <ul>
+ <ul class="category-list">
{% recursetree categories %}
<li>
- <a href="{% url 'dashboard:category-update' pk=node.pk %}">{{ node.name }}</a>
+ {% if node.level > root_level %}<a href="{% url 'dashboard:categories' pk=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">
{{ children }}
diff --git a/saleor/static/scss/dashboard.scss b/saleor/static/scss/dashboard.scss
index 78d17dd03e..9bc6322926 100644
--- a/saleor/static/scss/dashboard.scss
+++ b/saleor/static/scss/dashboard.scss
@@ -1 +1,6 @@
@import "app";
+.category-list {
+ ul {
+ padding-left: 25px;
+ }
+}