Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add 'is_hidden'
michal662ceaca689b
diff --git a/saleor/core/context_processors.py b/saleor/core/context_processors.pyindex 0ac69a8934..c0050b4db0 100644--- a/saleor/core/context_processors.py+++ b/saleor/core/context_processors.py@@ -27,7 +27,7 @@ def default_currency(request):# request is a required parameter# pylint: disable=W0613def categories(request):- return {'categories': Category.tree.root_nodes().filter(hidden=False)}+ return {'categories': Category.tree.root_nodes().filter(is_hidden=False)}def search_enabled(request):diff --git a/saleor/dashboard/category/filters.py b/saleor/dashboard/category/filters.pyindex 7f48995ed6..55d922d815 100644--- a/saleor/dashboard/category/filters.py+++ b/saleor/dashboard/category/filters.py@@ -1,7 +1,8 @@from __future__ import unicode_literals+from django import formsfrom django.utils.translation import pgettext_lazy-from django_filters import OrderingFilter+from django_filters import CharFilter, ChoiceFilter, OrderingFilterfrom ...core.filters import SortedFilterSetfrom ...product.models import Category@@ -9,10 +10,23 @@ from ...product.models import CategorySORT_BY_FIELDS = {'name': pgettext_lazy('Category list sorting option', 'name'),'description': pgettext_lazy(- 'Category list sorting option', 'description')}+ 'Category list sorting option', 'description'),+ 'is_hidden': pgettext_lazy('Category list sorting option', 'is hidden')}++IS_HIDDEN_CHOICES = (+ ('1', pgettext_lazy('Is hidden filter choice', 'Hidden')),+ ('0', pgettext_lazy('Is hidden filter choice', 'Not hidden')))class CategoryFilter(SortedFilterSet):+ name = CharFilter(+ label=pgettext_lazy('Product list filter label', 'Name'),+ lookup_expr='icontains')+ is_hidden = ChoiceFilter(+ label=pgettext_lazy('Product list filter label', 'Is published'),+ choices=IS_HIDDEN_CHOICES,+ empty_label=pgettext_lazy('Filter empty choice label', 'All'),+ widget=forms.Select)sort_by = OrderingFilter(label=pgettext_lazy('Product list sorting filter label', 'Sort by'),fields=SORT_BY_FIELDS.keys(),diff --git a/saleor/dashboard/category/forms.py b/saleor/dashboard/category/forms.pyindex dd2ca3b0ea..f942cc9f2e 100644--- a/saleor/dashboard/category/forms.py+++ b/saleor/dashboard/category/forms.py@@ -2,6 +2,7 @@ from __future__ import unicode_literalsfrom django import formsfrom django.shortcuts import get_object_or_404+from django.utils.translation import pgettext_lazyfrom django.utils.text import slugifyfrom text_unidecode import unidecode@@ -12,8 +13,10 @@ class CategoryForm(forms.ModelForm):def __init__(self, *args, **kwargs):self.parent_pk = kwargs.pop('parent_pk')super(CategoryForm, self).__init__(*args, **kwargs)+ self.fields['is_hidden'].label = pgettext_lazy(+ 'Category form field label', 'Hide in site navigation')if self.instance.parent and self.instance.parent.hidden:- self.fields['hidden'].widget.attrs['disabled'] = True+ self.fields['is_hidden'].widget.attrs['disabled'] = Trueclass Meta:model = Category@@ -24,8 +27,8 @@ class CategoryForm(forms.ModelForm):if self.parent_pk:self.instance.parent = get_object_or_404(Category, pk=self.parent_pk)- if self.instance.parent and self.instance.parent.hidden:- self.instance.hidden = True+ if self.instance.parent and self.instance.parent.is_hidden:+ self.instance.is_hidden = Truesuper(CategoryForm, self).save(commit=commit)- self.instance.set_hidden_descendants(self.cleaned_data['hidden'])+ self.instance.set_is_hidden_descendants(self.cleaned_data['is_hidden'])return self.instancediff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.pyindex 61566462dd..0b22d3dfca 100644--- a/saleor/dashboard/category/views.py+++ b/saleor/dashboard/category/views.py@@ -19,7 +19,7 @@ from .forms import CategoryForm@staff_member_required@permission_required('product.view_category')def category_list(request):- categories = Category.tree.root_nodes()+ categories = Category.tree.root_nodes().order_by('name')category_filter = CategoryFilter(request.GET, queryset=categories)categories = get_paginator_items(category_filter.qs, settings.DASHBOARD_PAGINATE_BY,@@ -84,10 +84,13 @@ def category_edit(request, root_pk=None):def category_detail(request, pk):root = get_object_or_404(Category, pk=pk)path = root.get_ancestors(include_self=True) if root else []- categories = root.get_children()+ categories = root.get_children().order_by('name')+ category_filter = CategoryFilter(request.GET, queryset=categories)categories = get_paginator_items(- categories, settings.DASHBOARD_PAGINATE_BY, request.GET.get('page'))- ctx = {'categories': categories, 'path': path, 'root': root}+ category_filter.qs, settings.DASHBOARD_PAGINATE_BY,+ request.GET.get('page'))+ ctx = {'categories': categories, 'path': path, 'root': root,+ 'filter': category_filter}return TemplateResponse(request, 'dashboard/category/detail.html', ctx)diff --git a/saleor/product/migrations/0038_auto_20171205_0456.py b/saleor/product/migrations/0038_auto_20171205_0456.pynew file mode 100644index 0000000000..ccce2060e4--- /dev/null+++ b/saleor/product/migrations/0038_auto_20171205_0456.py@@ -0,0 +1,16 @@+# -*- coding: utf-8 -*-+# Generated by Django 1.11.5 on 2017-12-05 10:56+from __future__ import unicode_literals++from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [+ ('product', '0037_auto_20171129_1004'),+ ]++ operations = [+ migrations.RenameField(model_name='category', old_name='hidden', new_name='is_hidden'),+ ]diff --git a/saleor/product/models.py b/saleor/product/models.pyindex 1e5bf0ee91..e8c42c9057 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -38,8 +38,8 @@ class Category(MPTTModel):'self', null=True, blank=True, related_name='children',verbose_name=pgettext_lazy('Category field', 'parent'),on_delete=models.CASCADE)- hidden = models.BooleanField(- pgettext_lazy('Category field', 'hidden'), default=False)+ is_hidden = models.BooleanField(+ pgettext_lazy('Category field', 'is_hidden'), default=False)objects = models.Manager()tree = TreeManager()@@ -68,8 +68,8 @@ class Category(MPTTModel):nodes = [node for node in ancestors] + [self]return '/'.join([node.slug for node in nodes])- def set_hidden_descendants(self, hidden):- self.get_descendants().update(hidden=hidden)+ def set_is_hidden_descendants(self, is_hidden):+ self.get_descendants().update(is_hidden=is_hidden)@python_2_unicode_compatible@@ -180,7 +180,7 @@ class Product(models.Model, ItemRange):def get_first_category(self):for category in self.categories.all():- if not category.hidden:+ if not category.is_hidden:return categoryreturn Nonediff --git a/templates/dashboard/category/detail.html b/templates/dashboard/category/detail.htmlindex 9393582f72..da9f8d27da 100644--- a/templates/dashboard/category/detail.html+++ b/templates/dashboard/category/detail.html@@ -2,6 +2,7 @@{% load i18n %}{% load mptt_tags %}{% load materializecss %}+{% load get_sort_by_toggle from shop %}{% load staticfiles %}{% load utils %}@@ -43,7 +44,7 @@{% if path %}<li class="back-mobile"><a href="{% url 'dashboard:category-list' %}">- <svg data-src="{% static "dashboard/images/arrow_left.svg" %}" fill="#fff"+ <svg data-src="{% static 'dashboard/images/arrow_left.svg' %}" fill="#fff"width="20px" height="20px"/></a></li>@@ -91,6 +92,18 @@</div>{% endif %}</div>+ {% if root.is_hidden %}+ <div class="row">+ <div class="col s12 l8">+ <h4>+ {% trans "Hidden" context "Category field" %}+ </h4>+ {% blocktrans trimmed context "Category detail is hidden text" %}+ This category is hidden on storefront+ {% endblocktrans %}+ </div>+ </div>+ {% endif %}</div>{% if perms.product.edit_category %}<div class="card-action">@@ -105,72 +118,94 @@</div>{% endif %}</div>- </div>- </div>- {% endif %}-- <div class="row">- <div class="col s12 l9">- <div class="card">- <div class="card-content">- <span class="card-title">- {% trans "Subcategories" context "Title of the subcategories list" %}- </span>- </div>- <div class="data-table-header-action">- <a href="{% if root%}{% url 'dashboard:category-add' root_pk=root.pk %}{% else %}{% url 'dashboard:category-add' %}{% endif %}" class="btn-data-table btn btn-flat">- {% trans "Add" %}- </a>- </div>- <div class="data-table-container">- <table class="bordered highlight responsive data-table data-table-description">- <thead>- <tr>- <th>- {% trans "Name" context "Category list table header name" %}- </th>- <th>- {% trans "Description" context "Category list table header description" %}- </th>- <th></th>- </tr>- </thead>- <tbody>- {% for node in categories %}- <tr data-action-go="{% url 'dashboard:category-detail' pk=node.pk %}">- <td>- {{ node.name }}- </td>- <td class="nowrap">- {% if node.description %}- {{ node.description|truncatewords:6 }}- {% else %}- - {% endif %}- </td>- {% if perms.product.edit_category %}- <td class="right-align ignore-link">- <a href="{% url 'dashboard:category-edit' root_pk=node.pk %}" class="btn btn-flat">- {% trans 'Edit' context 'Category edit action' %}- </a>- <a class="btn btn-flat modal-trigger-custom"- data-href="{% url 'dashboard:category-delete' pk=node.pk %}"- href="#base-modal">- {% trans "Remove" context "Category list action link" %}- </a>- </td>- {% endif %}- </tr>- {% empty %}+ <div class="card">+ <div class="card-content">+ <span class="card-title">+ {% trans "Subcategories" context "Title of the subcategories list" %}+ </span>+ </div>+ <div class="data-table-header-action">+ <a href="{% if root%}{% url 'dashboard:category-add' root_pk=root.pk %}{% else %}{% url 'dashboard:category-add' %}{% endif %}" class="btn-data-table btn btn-flat">+ {% trans "Add" %}+ </a>+ </div>+ <div class="data-table-container">+ <table class="bordered highlight responsive data-table data-table-description">+ <thead><tr>- <td colspan="2">{% trans "No categories" context "Empty list of categories" %}</td>+ {% get_sort_by_toggle 'name' as toggle %}+ <th class="{% if toggle.is_active %}active{% endif %}">+ <a href="{{ toggle.url }}">+ <svg data-src="{{ toggle.sorting_icon }}" />+ {% trans "Name" context "Category list table header name" %}+ </a>+ </th>+ {% get_sort_by_toggle 'is_hidden' as toggle %}+ <th class="{% if toggle.is_active %}active{% endif %}">+ <a href="{{ toggle.url }}">+ <svg data-src="{{ toggle.sorting_icon }}" />+ {% trans "Is hidden" context "Category list table header hidden" %}+ </a>+ </th>+ {% get_sort_by_toggle 'description' as toggle %}+ <th class="wide {% if toggle.is_active %}active{% endif %}">+ <a href="{{ toggle.url }}">+ <svg data-src="{{ toggle.sorting_icon }}" />+ {% trans "Description" context "Category list table header description" %}+ </a>+ </th>+ <th></th></tr>- {% endfor %}- </tbody>- </table>+ </thead>+ <tbody>+ {% for node in categories %}+ <tr data-action-go="{% url 'dashboard:category-detail' pk=node.pk %}">+ <td>+ {{ node.name }}+ </td>+ <td>+ {% if node.is_hidden %}+ <span>+ {% trans 'Hidden' context 'Category list table is hidden flag' %}+ </span>+ {% else %}+ -+ {% endif %}+ </td>+ <td class="nowrap">+ {% if node.description %}+ {{ node.description|truncatewords:10 }}+ {% else %}+ + {% endif %}+ </td>+ {% if perms.product.edit_category %}+ <td class="right-align ignore-link">+ <a href="{% url 'dashboard:category-edit' root_pk=node.pk %}" class="btn btn-flat">+ {% trans 'Edit' context 'Category edit action' %}+ </a>+ <a class="btn btn-flat modal-trigger-custom"+ data-href="{% url 'dashboard:category-delete' pk=node.pk %}"+ href="#base-modal">+ {% trans "Remove" context "Category list action link" %}+ </a>+ </td>+ {% endif %}+ </tr>+ {% empty %}+ <tr>+ <td colspan="2">{% trans "No categories" context "Empty list of categories" %}</td>+ </tr>+ {% endfor %}+ </tbody>+ </table>+ </div></div>+ {% paginate categories %}+ </div>+ <div class="col s12 l3" id="filters">+ {% add_filters filter %}</div>- {% paginate categories %}</div>- </div>+ {% endif %}{% endblock %}diff --git a/templates/dashboard/category/form.html b/templates/dashboard/category/form.htmlindex 8d83e4155f..b1a49f316e 100644--- a/templates/dashboard/category/form.html+++ b/templates/dashboard/category/form.html@@ -103,7 +103,7 @@</div><div class="col s12 m4"><div class="row">- {{ form.hidden|materializecss:"input-field s12" }}+ {{ form.is_hidden|materializecss:"input-field s12" }}</div></div></div>diff --git a/templates/dashboard/category/list.html b/templates/dashboard/category/list.htmlindex 3cfc347522..01cb582de9 100644--- a/templates/dashboard/category/list.html+++ b/templates/dashboard/category/list.html@@ -46,11 +46,6 @@<div class="row"><div class="col s12 l9"><div class="card">- <div class="data-table-header-action">- <a href="{% if root%}{% url 'dashboard:category-add' root_pk=root.pk %}{% else %}{% url 'dashboard:category-add' %}{% endif %}" class="btn-data-table btn btn-flat">- {% trans "Add" %}- </a>- </div><div class="data-table-container"><table class="bordered highlight responsive data-table data-table-description"><thead>@@ -62,6 +57,13 @@{% trans "Name" context "Category list table header name" %}</a></th>+ {% get_sort_by_toggle 'is_hidden' as toggle %}+ <th class="{% if toggle.is_active %}active{% endif %}">+ <a href="{{ toggle.url }}">+ <svg data-src="{{ toggle.sorting_icon }}" />+ {% trans "Is hidden" context "Category list table header hidden" %}+ </a>+ </th>{% get_sort_by_toggle 'description' as toggle %}<th class="wide {% if toggle.is_active %}active{% endif %}"><a href="{{ toggle.url }}">@@ -76,6 +78,15 @@<td>{{ node.name }}</td>+ <td>+ {% if node.is_hidden %}+ <span>+ {% trans 'Hidden' context 'Category list table is hidden flag' %}+ </span>+ {% else %}+ -+ {% endif %}+ </td><td class="nowrap">{% if node.description %}{{ node.description|truncatewords:10 }}@@ -91,5 +102,8 @@</div>{% paginate categories %}</div>+ <div class="col s12 l3" id="filters">+ {% add_filters filter %}+ </div></div>{% endblock %}diff --git a/templates/dashboard/product/detail.html b/templates/dashboard/product/detail.htmlindex 1287d13183..41596b5fd2 100644--- a/templates/dashboard/product/detail.html+++ b/templates/dashboard/product/detail.html@@ -156,37 +156,37 @@{% endif %}</div>{% if perms.product.edit_product %}- <div class="col s12 l3">- <div id="status">- <div class="row">- <div class="col s12">- <div class="card">- <div class="card-content">- <form id="toggle-publish-form" action="{% url 'dashboard:product-publish' product.pk %}">- <div class="switch" id="product-is-published">- <label>- <input id="toggle-publish-switch" type="checkbox" {% if product.is_published %} checked {% endif %}>- <span class="lever"></span>- <span class="label">- {% if product.is_published %}- {% trans "Published" context "Product field" %}- {% else %}- {% trans "Draft" context "Product field" %}- {% endif %}- </span>- </label>- </div>- {% csrf_token %}- </form>- <h5>{% render_availability_status product %}</h5>+ <div class="col s12 l3">+ <div id="status">+ <div class="row">+ <div class="col s12">+ <div class="card">+ <div class="card-content">+ <form id="toggle-publish-form" action="{% url 'dashboard:product-publish' product.pk %}">+ <div class="switch" id="product-is-published">+ <label>+ <input id="toggle-publish-switch" type="checkbox" {% if product.is_published %} checked {% endif %}>+ <span class="lever"></span>+ <span class="label">+ {% if product.is_published %}+ {% trans "Published" context "Product field" %}+ {% else %}+ {% trans "Draft" context "Product field" %}+ {% endif %}+ </span>+ </label>+ </div>+ {% csrf_token %}+ </form>+ <h5>{% render_availability_status product %}</h5>+ </div></div></div></div></div></div>- </div>{% endif %}- <div class="col s12 l3">+ <div class="col s12 l3"><div id="images"><div class="row"><div class="col s12">@@ -211,8 +211,5 @@</div></div></div>- <div class="col s12 l9">-- </div></div>{% endblock %}