Skip to content

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

Add messages

Paweł Kowalewski3caf05f675e6
diff --git a/saleor/dashboard/category/urls.py b/saleor/dashboard/category/urls.py
index 629a45d69e..dc6dc3b6e3 100644
--- a/saleor/dashboard/category/urls.py
+++ b/saleor/dashboard/category/urls.py
@@ -4,9 +4,9 @@ from . import views
urlpatterns = [
url(r'^$',
- views.category_root_nodes_list, name='category-root-list'),
+ views.category_list, name='category-list'),
url(r'^(?P<root_pk>[0-9]+)/$',
- views.category_children_nodes_list, name='category-children-list'),
+ views.category_list, name='category-list'),
url(r'^add/$',
views.category_create, name='category-add'),
url(r'^(?P<root_pk>[0-9]+)/add/$',
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
index 550687864f..692aad6287 100644
--- a/saleor/dashboard/category/views.py
+++ b/saleor/dashboard/category/views.py
@@ -9,29 +9,15 @@ from .forms import CategoryForm
@staff_member_required
-def category_root_nodes_list(request):
+def category_list(request, root_pk=None):
+ root = None
+ path = None
categories = Category.tree.root_nodes()
- ctx = {'categories': categories, 'path': [], 'root': None, 'form': None}
- return TemplateResponse(request, 'dashboard/category/list.html', ctx)
-
-
-@staff_member_required
-def category_children_nodes_list(request, root_pk):
- root = get_object_or_404(Category, pk=root_pk)
- category = get_object_or_404(Category,
- pk=root.parent.pk) if root.parent else None
- form = CategoryForm(request.POST or None, instance=root,
- initial={'parent': category})
- if form.is_valid():
- category = form.save()
- messages.success(request, _('Updated category %s') % category)
- if root:
- return redirect('dashboard:category-children-list', root_pk=root.pk)
- else:
- return redirect('dashboard:category-root-list')
- path = root.get_ancestors(include_self=True) if root else []
- categories = root.get_children()
- ctx = {'categories': categories, 'path': path, 'root': root, 'form': form}
+ if root_pk:
+ root = get_object_or_404(Category, pk=root_pk)
+ path = root.get_ancestors(include_self=True) if root else []
+ categories = root.get_children()
+ ctx = {'categories': categories, 'path': path, 'root': root}
return TemplateResponse(request, 'dashboard/category/list.html', ctx)
@@ -43,9 +29,9 @@ def category_create(request, root_pk=None):
category = form.save()
messages.success(request, _('Added category %s') % category)
if root_pk:
- return redirect('dashboard:category-children-list', root_pk=root_pk)
+ return redirect('dashboard:category-list', root_pk=root_pk)
else:
- return redirect('dashboard:category-root-list')
+ return redirect('dashboard:category-list')
ctx = {'category': category, 'form': form}
return TemplateResponse(request, 'dashboard/category/detail.html', ctx)
@@ -76,10 +62,13 @@ def category_delete(request, pk):
if request.method == 'POST':
category.delete()
messages.success(request, _('Deleted category %s') % category)
+ root_pk = None
if category.parent:
- return redirect('dashboard:category-children-list', root_pk=category.parent.pk)
+ root_pk = category.parent.pk
+ if root_pk:
+ return redirect('dashboard:category-list', root_pk=root_pk)
else:
- return redirect('dashboard:category-root-list')
+ return redirect('dashboard:category-list')
ctx = {'category': category,
'descendants': list(category.get_descendants()),
'products_count': len(category.products.all())}
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 17e1f894c1..a2ad41e147 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -18,7 +18,6 @@ class OrderNoteForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(OrderNoteForm, self).__init__(*args, **kwargs)
- self.fields['content'].label = ''
class ManagePaymentForm(forms.Form):
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index ab53cd187a..13f7f9a313 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -65,7 +65,7 @@ def order_add_note(request, order_pk):
form.save()
msg = _('Added note')
order.create_history_entry(comment=msg, user=request.user)
- return redirect('dashboard:order-details', order_pk=order_pk)
+ messages.success(request, msg)
elif form.errors:
status = 400
ctx = {'order': order, 'form': form}
@@ -127,8 +127,8 @@ def orderline_change_quantity(request, order_pk, line_pk):
delivery_group__order=order), pk=line_pk)
form = ChangeQuantityForm(request.POST or None, instance=item)
status = 200
+ old_quantity = item.quantity
if form.is_valid():
- old_quantity = item.quantity
with transaction.atomic():
form.save()
msg = _(
@@ -137,7 +137,7 @@ def orderline_change_quantity(request, order_pk, line_pk):
'product': item.product, 'old_quantity': old_quantity,
'new_quantity': item.quantity}
order.create_history_entry(comment=msg, user=request.user)
- return redirect('dashboard:order-details', order_pk=order_pk)
+ messages.success(request, msg)
elif form.errors:
status = 400
ctx = {'order': order, 'object': item, 'form': form}
@@ -165,7 +165,7 @@ def orderline_split(request, order_pk, line_pk):
'how_many': how_many, 'item': item, 'old_group': old_group,
'new_group': target_group}
order.create_history_entry(comment=msg, user=request.user)
- return redirect('dashboard:order-details', order_pk=order_pk)
+ messages.success(request, msg)
elif form.errors:
status = 400
ctx = {'order': order, 'object': item, 'form': form}
diff --git a/saleor/dashboard/templates/dashboard/base.html b/saleor/dashboard/templates/dashboard/base.html
index 1eb751136a..bf33a74843 100644
--- a/saleor/dashboard/templates/dashboard/base.html
+++ b/saleor/dashboard/templates/dashboard/base.html
@@ -63,7 +63,7 @@
<ul>
<li class="subnav-products"><a href="{% url 'dashboard:product-list' %}">{% trans "Products" %}</a></li>
<li class="subnav-attributes"><a href="{% url 'dashboard:product-attributes' %}">{% trans "Attributes" %}</a></li>
- <li class="subnav-categories"><a href="{% url 'dashboard:category-root-list' %}">{% trans "Categories" %}</a></li>
+ <li class="subnav-categories"><a href="{% url 'dashboard:category-list' %}">{% trans "Categories" %}</a></li>
</ul>
</div>
</li>
@@ -88,9 +88,7 @@
<main class="main">
<div class="container">
- {% if messages %}
- {% include "dashboard/includes/_messages.html" %}
- {% endif %}
+ {% include "dashboard/includes/_messages.html" %}
{% block content %}
{% endblock %}
diff --git a/saleor/dashboard/templates/dashboard/category/category_confirm_delete.html b/saleor/dashboard/templates/dashboard/category/category_confirm_delete.html
index 9b7e8cef98..a93b709375 100644
--- a/saleor/dashboard/templates/dashboard/category/category_confirm_delete.html
+++ b/saleor/dashboard/templates/dashboard/category/category_confirm_delete.html
@@ -50,7 +50,7 @@
<div class="form-group">
<div class="col-md-6">
<button class="btn btn-danger" type="submit"><i class="glyphicon glyphicon-trash"></i> {% trans "Delete" %}</button>
- <a class="btn btn-default" href="{% url 'dashboard:category-children-list' root_pk=category.pk %}"><i class="glyphicon glyphicon-remove"></i> {% trans "Cancel" %}</a>
+ <a class="btn btn-default" href="{% url 'dashboard:category-list' root_pk=category.pk %}"><i class="glyphicon glyphicon-remove"></i> {% trans "Cancel" %}</a>
</div>
</div>
</form>
diff --git a/saleor/dashboard/templates/dashboard/category/detail.html b/saleor/dashboard/templates/dashboard/category/detail.html
index d956b8a0b4..aab091da47 100644
--- a/saleor/dashboard/templates/dashboard/category/detail.html
+++ b/saleor/dashboard/templates/dashboard/category/detail.html
@@ -11,10 +11,10 @@
{% block breadcrumbs %}
<ul class="breadcrumbs breadcrumbs--with-menu">
- <li><a href="{% url 'dashboard:category-root-list' %}">{% trans "Categories" %}</a></li>
+ <li><a href="{% url 'dashboard:category-list' %}">{% trans "Categories" %}</a></li>
{% if path %}
{% for node in path %}
- <li><a href="{% url 'dashboard:category-children-list' root_pk=node.pk %}">{{ node.name }}</a></li>
+ <li><a href="{% url 'dashboard:category-list' root_pk=node.pk %}">{{ node.name }}</a></li>
{% endfor %}
{% endif %}
<li>{% if category.pk %}{{ category }}{% else %}{% trans 'Add new category' %}{% endif %}</li>
@@ -40,9 +40,9 @@
<div class="row">
<div class="col s12 l8 right-align">
{% if category.parent %}
- <a href="{% url 'dashboard:category-children-list' root_pk=category.parent.pk %}" class="btn-flat">{% trans "Cancel" %}</a>
+ <a href="{% url 'dashboard:category-list' root_pk=category.parent.pk %}" class="btn-flat">{% trans "Cancel" %}</a>
{% else %}
- <a href="{% url 'dashboard:category-root-list' %}" class="btn-flat">{% trans "Cancel" %}</a>
+ <a href="{% url 'dashboard:category-list' %}" class="btn-flat">{% trans "Cancel" %}</a>
{% endif %}
{% if category.pk %}
<button type="submit" class="btn">{% trans "Update" %}</button>
diff --git a/saleor/dashboard/templates/dashboard/category/list.html b/saleor/dashboard/templates/dashboard/category/list.html
index c44a2c77df..76a848b665 100644
--- a/saleor/dashboard/templates/dashboard/category/list.html
+++ b/saleor/dashboard/templates/dashboard/category/list.html
@@ -10,9 +10,9 @@
{% block header_menu %}
{% if root %}
{% if root.parent %}
- {% url 'dashboard:category-children-list' root_pk=root.parent.pk as url %}
+ {% url 'dashboard:category-list' root_pk=root.parent.pk as url %}
{% else %}
- {% url 'dashboard:category-root-list' as url %}
+ {% url 'dashboard:category-list' as url %}
{% endif %}
{% include "dashboard/includes/_back-link.html" with url=url %}
{% else %}
@@ -50,7 +50,7 @@
{% block breadcrumbs %}
<ul class="breadcrumbs breadcrumbs--with-menu breadcrumbs--ellipsed">
- <li>{% if path %}<a href="{% url 'dashboard:category-root-list' %}">{% trans "Categories" %}</a>{% else %}{% trans "Categories" %}{% endif %}</li>
+ <li>{% if path %}<a href="{% url 'dashboard:category-list' %}">{% trans "Categories" %}</a>{% else %}{% trans "Categories" %}{% endif %}</li>
{% if path %}
{% for node in path %}
{% if forloop.last %}
@@ -61,7 +61,7 @@
</li>
{% else %}
<li>
- <a title="{{ node.name }}" href="{% url 'dashboard:category-children-list' root_pk=node.pk %}">
+ <a title="{{ node.name }}" href="{% url 'dashboard:category-list' root_pk=node.pk %}">
<span class="breadcrumbs--ellipsed-item">{{ node.name }}</span>
</a>
</li>
@@ -80,7 +80,7 @@
{% if categories %}
{% for node in categories %}
<li class="collection-item list-item list-item--two-lines">
- <a class="list-item-name" href="{% url 'dashboard:category-children-list' root_pk=node.pk %}">
+ <a class="list-item-name" href="{% url 'dashboard:category-list' root_pk=node.pk %}">
{{ node.name }}
</a>
@@ -112,7 +112,7 @@
{% if root %}
<div id="modal-category-delete" class="modal">
- <form action="{% url "dashboard:category-delete" pk=root.pk %}" method="post" class="form-async">
+ <form action="{% url "dashboard:category-delete" pk=root.pk %}" method="post">
{% csrf_token %}
<div class="modal-content">
<h5>{% trans "Are you sure?" %}</h5>
diff --git a/saleor/dashboard/templates/dashboard/includes/_messages.html b/saleor/dashboard/templates/dashboard/includes/_messages.html
index a7660fa2b8..39fe8c8290 100644
--- a/saleor/dashboard/templates/dashboard/includes/_messages.html
+++ b/saleor/dashboard/templates/dashboard/includes/_messages.html
@@ -1,23 +1,13 @@
{% load i18n %}
-<div id="messages">
{% if messages %}
{% for message in messages %}
- <div class="row">
- <div class="col s12 center-align">
- <div class="toast toast--static">
- <span>
- {% if 'safe' in message.tags %}
- {{ message|safe }}
- {% else %}
- {{ message }}
- {% endif %}
- </span>
-
- <a class="btn-flat teal-text">{% trans "Dismiss" %}</a>
- </div>
- </div>
+ <div class="toast toast--fixed toast--hidden message">
+ {% if 'safe' in message.tags %}
+ {{ message|safe }}
+ {% else %}
+ {{ message }}
+ {% endif %}
</div>
{% endfor %}
{% endif %}
-</div>
diff --git a/saleor/dashboard/templates/dashboard/order/modal_address_edit.html b/saleor/dashboard/templates/dashboard/order/modal_address_edit.html
index 544ffbeb4d..8755e0e04f 100644
--- a/saleor/dashboard/templates/dashboard/order/modal_address_edit.html
+++ b/saleor/dashboard/templates/dashboard/order/modal_address_edit.html
@@ -1,7 +1,7 @@
{% load i18n %}
{% load materializecss %}
-<form class="form-async" role="form" method="post" action="{% url 'dashboard:address-edit' order_pk=order.pk address_type="shipping" %}">
+<form class="form-async" role="form" method="post" action="{% url 'dashboard:address-edit' order_pk=order.pk address_type=address_type %}">
{% csrf_token %}
<div class="modal-content">
<h5>
diff --git a/saleor/dashboard/templates/dashboard/product/product_form.html b/saleor/dashboard/templates/dashboard/product/product_form.html
index 6b31fd40c4..a94e1c1035 100644
--- a/saleor/dashboard/templates/dashboard/product/product_form.html
+++ b/saleor/dashboard/templates/dashboard/product/product_form.html
@@ -140,12 +140,10 @@
{% if variants %}
<thead>
<tr>
- {% if attributes %}
- <th class="bulk-checkbox">
- <input type="checkbox" id="select-all-variants" class="filled-in select-all switch-actions">
- <label for="select-all-variants"></label>
- </th>
- {% endif %}
+ <th class="bulk-checkbox">
+ <input type="checkbox" id="select-all-variants" class="filled-in select-all switch-actions">
+ <label for="select-all-variants"></label>
+ </th>
<th>{% trans "SKU" %}</th>
{% for attribute in attributes %}
<th>{{ attribute.display|capfirst }}</th>
@@ -158,12 +156,10 @@
<tbody>
{% for variant in variants %}
<tr>
- {% if attributes %}
- <td class="bulk-checkbox">
- <input id="id_variants_{{ variant.id }}" name="items" type="checkbox" value="{{ variant.id }}" class="filled-in switch-actions">
- <label for="id_variants_{{ variant.id }}"></label>
- </td>
- {% endif %}
+ <td class="bulk-checkbox">
+ <input id="id_variants_{{ variant.id }}" name="items" type="checkbox" value="{{ variant.id }}" class="filled-in switch-actions">
+ <label for="id_variants_{{ variant.id }}"></label>
+ </td>
<td><a class="light-blue-text text-lighten-1" title="{% trans "Edit variant" %}"
href="{% url 'dashboard:variant-update' product_pk=product.pk variant_pk=variant.pk %}">
{{ variant.sku }}
@@ -338,7 +334,7 @@
</div>
</div>
{% else %}
- <p class="deep-purple-text">{% trans "This product has no images yet." %}</p>
+ <p>{% trans "This product has no images yet." %}</p>
{% endif %}
<script type="application/template" id="template">
diff --git a/saleor/settings.py b/saleor/settings.py
index 4f6dccd2db..edf84ab2d5 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -252,3 +252,5 @@ if AWS_STATIC_BUCKET_NAME:
if AWS_MEDIA_BUCKET_NAME:
DEFAULT_FILE_STORAGE = 'offsite_storage.storages.S3MediaStorage'
THUMBNAIL_DEFAULT_STORAGE = DEFAULT_FILE_STORAGE
+
+MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
diff --git a/saleor/static/js_src/dashboard.js b/saleor/static/js_src/dashboard.js
index 651924f4b1..1f85dc2b3f 100644
--- a/saleor/static/js_src/dashboard.js
+++ b/saleor/static/js_src/dashboard.js
@@ -42,6 +42,23 @@ $(document).ready(function() {
e.preventDefault();
});
+ var $messages = $('.message');
+ var timeout = 0;
+ var offset = 100;
+ var firstMessageOffset = 250;
+ setTimeout(function() {
+ $messages.each(function () {
+ var that = this;
+ setTimeout(function () {
+ $(that).removeClass('toast--hidden');
+ }, timeout + offset);
+ timeout += 3000;
+ setTimeout(function () {
+ $(that).addClass('toast--hidden');
+ }, timeout - offset);
+ });
+ }, firstMessageOffset);
+
$(document).on('submit', '.form-async', function(e) {
var that = this;
$.ajax({
diff --git a/saleor/static/scss/widget/_toast.scss b/saleor/static/scss/widget/_toast.scss
index 5e50741d35..c0fe7d379d 100644
--- a/saleor/static/scss/widget/_toast.scss
+++ b/saleor/static/scss/widget/_toast.scss
@@ -1,7 +1,32 @@
@mixin toast {
- &--static {
+ height: auto;
+ line-height: inherit;
+ padding: {
+ top: 12px;
+ bottom: 11px;
+ }
+
+ &--fixed {
+ bottom: 0;
display: inline-block;
float: none;
+ left: 50%;
+ min-width: 300px;
+
+ top: auto;
+ transform: translateX(-50%);
+ z-index: 9999;
+
+ .js & {
+ position: fixed;
+ transition: transform $transition-duration;
+ }
+ }
+
+ &--hidden {
+ .js & {
+ transform: translate(-50%, 100%);
+ }
}
}