Skip to content

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

Display and edit collection

Mira Szewczykd12ac9003f69
diff --git a/saleor/dashboard/collection/urls.py b/saleor/dashboard/collection/urls.py
index edc864deae..7d0bc6fd97 100644
--- a/saleor/dashboard/collection/urls.py
+++ b/saleor/dashboard/collection/urls.py
@@ -6,4 +6,6 @@ from . import views
urlpatterns = [
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'),
]
diff --git a/saleor/dashboard/collection/views.py b/saleor/dashboard/collection/views.py
index ac37cbc87d..48e2c63906 100644
--- a/saleor/dashboard/collection/views.py
+++ b/saleor/dashboard/collection/views.py
@@ -1,6 +1,6 @@
from django.template.response import TemplateResponse
from django.contrib import messages
-from django.shortcuts import redirect
+from django.shortcuts import redirect, get_object_or_404
from django.utils.translation import ugettext_lazy as _
from ...product.models import Collection
@@ -28,3 +28,14 @@ def collection_create(request):
return redirect('dashboard:collection-list')
ctx = {'collection': collection, 'form': form}
return TemplateResponse(request, 'dashboard/collection/detail.html', ctx)
+
+
+@staff_member_required
+def collection_update(request, collection_pk=None):
+ collection = get_object_or_404(Collection, pk=collection_pk)
+ form = CollectionForm(request.POST or None, instance=collection)
+ if form.is_valid():
+ collection = form.save()
+ messages.success(request, _('Updated collection %s') % collection)
+ ctx = {'collection': collection, 'form': form}
+ return TemplateResponse(request, 'dashboard/collection/detail.html', ctx)
diff --git a/templates/dashboard/collection/list.html b/templates/dashboard/collection/list.html
index 2877619f3b..3ad692d433 100644
--- a/templates/dashboard/collection/list.html
+++ b/templates/dashboard/collection/list.html
@@ -30,7 +30,7 @@
<ul class="collection list">
{% for collection in collections %}
<li class="collection-item list-item list-item--two-lines">
- <a class="list-item-name" href="#">
+ <a class="list-item-name" href="{% url 'dashboard:collection-update' collection.pk %}">
{{ collection }}
</a>
<p class="list-item-desc">