Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Delete collection view
Mira Szewczykcc734d15a558
diff --git a/saleor/dashboard/collection/urls.py b/saleor/dashboard/collection/urls.pyindex ddc2b8db1a..323652c0b1 100644--- a/saleor/dashboard/collection/urls.py+++ b/saleor/dashboard/collection/urls.py@@ -4,8 +4,10 @@ from . import viewsurlpatterns = [- url(r'^/$', views.collection_list, name='collection-list'),+ url(r'^$', views.collection_list, name='collection-list'),url(r'^add/$', views.collection_create, name='collection-add'),url(r'^(?P<collection_pk>[0-9]+)/edit/$',views.collection_update, name='collection-update'),+ url(r'^(?P<collection_pk>[0-9]+)/delete/$',+ views.collection_delete, name='collection-delete'),]diff --git a/saleor/dashboard/collection/views.py b/saleor/dashboard/collection/views.pyindex 48e2c63906..9d5615cd53 100644--- a/saleor/dashboard/collection/views.py+++ b/saleor/dashboard/collection/views.py@@ -1,5 +1,7 @@from django.template.response import TemplateResponsefrom django.contrib import messages+from django.core.urlresolvers import reverse+from django.http import JsonResponsefrom django.shortcuts import redirect, get_object_or_404from django.utils.translation import ugettext_lazy as _@@ -39,3 +41,18 @@ def collection_update(request, collection_pk=None):messages.success(request, _('Updated collection %s') % collection)ctx = {'collection': collection, 'form': form}return TemplateResponse(request, 'dashboard/collection/detail.html', ctx)+++@staff_member_required+def collection_delete(request, collection_pk=None):+ collection = get_object_or_404(Collection, pk=collection_pk)+ if request.method == 'POST':+ collection.delete()+ messages.success(request, _("Deleted collection %s") % collection)+ if request.is_ajax():+ response = {'redirectUrl': reverse('dashboard:collection-list')}+ return JsonResponse(response)+ return redirect('dashboard:collection-list')+ ctx = {'collection': collection}+ return TemplateResponse(request, 'dashboard/collection/modal_delete.html',+ ctx)diff --git a/templates/dashboard/collection/detail.html b/templates/dashboard/collection/detail.htmlindex 36dc5bab10..4fa08e8a61 100644--- a/templates/dashboard/collection/detail.html+++ b/templates/dashboard/collection/detail.html@@ -28,6 +28,21 @@</ul>{% endblock %}+{% block header_extra %}+ {% if collection.pk %}+ <a class="dropdown-button" href="#" data-activates="collection-delete" data-constrainwidth="false">+ <i class="material-icons">arrow_drop_down</i>+ </a>+ <ul id="collection-delete" class="dropdown-content">+ <li>+ <a class="modal-trigger-custom" data-href="{% url 'dashboard:collection-delete' collection.pk %}" href="#base-modal">+ {% trans "Remove collection" %}+ </a>+ </li>+ </ul>+ {% endif %}+{% endblock %}+{% block content %}<form method="post" id="form-category" action="" novalidate>{% csrf_token %}diff --git a/templates/dashboard/collection/modal_delete.html b/templates/dashboard/collection/modal_delete.htmlnew file mode 100644index 0000000000..f6c861540d--- /dev/null+++ b/templates/dashboard/collection/modal_delete.html@@ -0,0 +1,22 @@+{% load i18n %}++<form method="post" id="form-category" class="form-async" action="{% url 'dashboard:collection-delete' collection.pk %}" novalidate>+ {% csrf_token %}+ <div class="modal-content">+ <div class="row">+ <div class="col s12">+ <h5>+ {% blocktrans with collection=collection %}+ Are you sure you want to delete the collection {{ collection }}?+ {% endblocktrans %}+ </h5>+ </div>+ </div>++ </div>++ <div class="modal-footer">+ <button type="submit" class="modal-action btn-flat blue-text">{% trans "Delete" %}</button>+ <a href="#!" class="modal-action modal-close btn-flat blue-text">{% trans "Cancel" %}</a>+ </div>+</form>