Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add collection view
Mira Szewczykdc5f0f2e5a95
diff --git a/saleor/dashboard/collection/forms.py b/saleor/dashboard/collection/forms.pynew file mode 100644index 0000000000..1d3e28bde7--- /dev/null+++ b/saleor/dashboard/collection/forms.py@@ -0,0 +1,8 @@+from django import forms+from ...product.models import Collection+++class CollectionForm(forms.ModelForm):+ class Meta:+ model = Collection+ exclude = []diff --git a/saleor/dashboard/collection/urls.py b/saleor/dashboard/collection/urls.pyindex 3ff9b03756..edc864deae 100644--- a/saleor/dashboard/collection/urls.py+++ b/saleor/dashboard/collection/urls.py@@ -5,4 +5,5 @@ from . import viewsurlpatterns = [url(r'^$', views.collection_list, name='collection-list'),+ url(r'^add$', views.collection_create, name='collection-add'),]diff --git a/saleor/dashboard/collection/views.py b/saleor/dashboard/collection/views.pyindex 15ffa4a29f..ebd9aed082 100644--- a/saleor/dashboard/collection/views.py+++ b/saleor/dashboard/collection/views.py@@ -1,8 +1,12 @@from django.template.response import TemplateResponse+from django.contrib import messages+from django.shortcuts import redirect+from django.utils.translation import ugettext_lazy as _from ...product.models import Collectionfrom ...core.utils import get_paginator_itemsfrom ..views import staff_member_required+from .forms import CollectionForm@staff_member_required@@ -12,3 +16,15 @@ def collection_list(request):ctx = {'colections': collections}return TemplateResponse(request,'dashboard/collection/list.html', ctx)+++@staff_member_required+def collection_create(request):+ collection = Collection()+ form = CollectionForm(request.POST or None)+ if form.is_valid():+ collection = form.save()+ messages.success(request, _('Added collection %s') % collection)+ return redirect('dashboard:collection-list')+ ctx = {'collection': collection, 'form': form}+ return TemplateResponse(request, 'dashboard/collection/detail.html', ctx)diff --git a/templates/dashboard/collection/detail.html b/templates/dashboard/collection/detail.htmlnew file mode 100644index 0000000000..36dc5bab10--- /dev/null+++ b/templates/dashboard/collection/detail.html@@ -0,0 +1,51 @@+{% extends 'dashboard/base.html' %}+{% load materializecss %}+{% load i18n %}++{% block title %}+ {% if collection.pk %}{{ collection }}{% else %}{% trans 'Add new collection' %}{% endif %} - {% trans 'Collections' %} - {{ block.super }}{% endblock %}++{% block body_class %}body-collections{% endblock %}++{% block menu_collections_class %}active{% endblock %}++{% block page_title %}{% if collection.pk %}{{ collection }}{% else %}{% trans 'Add new collection' %}{% endif %}{% endblock %}++{% block breadcrumbs %}+ <ul class="breadcrumbs breadcrumbs--history">+ <li class="back-mobile">+ <a href="{% url 'dashboard:collection-list' %}" class="breadcrumbs--ellipsed-item">+ {% trans "Collection" %}+ </a>+ </li>+ <li>+ {% if collection.pk %}+ <span class="breadcrumbs--ellipsed-item">{{ collection }}</span>+ {% else %}+ <span class="breadcrumbs--ellipsed-item">{% trans 'Add new collection' %}</span>+ {% endif %}+ </li>+ </ul>+{% endblock %}++{% block content %}+ <form method="post" id="form-category" action="" novalidate>+ {% csrf_token %}+ <div class="row">+ {{ form.name|materializecss:"col l8" }}+ </div>+ <div class="row">+ {{ form.products|materializecss:"col l8" }}+ </div>+ <div class="row">+ <div class="col s12 l8 right-align">+ <a href="{% url 'dashboard:collection-list' %}" class="btn-flat">{% trans "Cancel" %}</a>+ {% if collection.pk %}+ <button type="submit" class="btn">{% trans "Update" %}</button>+ {% else %}+ <button type="submit" class="btn">{% trans "Create" %}</button>+ {% endif %}+ </div>+ </div>+ </form>+{% endblock %}\ No newline at end of filediff --git a/templates/dashboard/collection/list.html b/templates/dashboard/collection/list.htmlindex a1812438e4..141487a327 100644--- a/templates/dashboard/collection/list.html+++ b/templates/dashboard/collection/list.html@@ -17,7 +17,7 @@{% block header_extra %}<div class="fixed-action-btn"><a class="btn-fab btn-floating btn-large waves-effect waves-light teal" title="{% trans "Add collection" %}"- href="#">+ href="{% url 'dashboard:collection-add' %}"><i class="material-icons">add</i></a></div>