Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add setting view
Mira Szewczyka8e3246318d1
diff --git a/saleor/dashboard/settings/forms.py b/saleor/dashboard/settings/forms.pynew file mode 100644index 0000000000..21ece0dd00--- /dev/null+++ b/saleor/dashboard/settings/forms.py@@ -0,0 +1,15 @@+from django import forms+from django.utils.translation import ugettext_lazy as _+from ...setting.models import Setting+++class SettingForm(forms.ModelForm):+ class Meta:+ model = Setting+ exclude = []++ def clean_name(self):+ name = self.cleaned_data['name']+ if len(name.split()) > 1:+ raise forms.ValidationError(_("Name cannot contains whitespaces"))+ return name\ No newline at end of filediff --git a/saleor/dashboard/settings/urls.py b/saleor/dashboard/settings/urls.pyindex f6cd299d61..f12f1a15d6 100644--- a/saleor/dashboard/settings/urls.py+++ b/saleor/dashboard/settings/urls.py@@ -4,4 +4,5 @@ from . import viewsurlpatterns = [url(r'^$', views.index, name='setting-index'),+ url(r'^add/$', views.create, name='setting-create'),]diff --git a/saleor/dashboard/settings/views.py b/saleor/dashboard/settings/views.pyindex 4364eebaa7..ad23501d74 100644--- a/saleor/dashboard/settings/views.py+++ b/saleor/dashboard/settings/views.py@@ -3,10 +3,21 @@ from django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponsefrom django.utils.translation import ugettext_lazy as _-from ...core.models import Setting+from ...setting.models import Setting+from .forms import SettingFormdef index(request):settings = Setting.objects.all()ctx = {'settings': settings}return TemplateResponse(request, 'dashboard/settings/index.html', ctx)+++def create(request):+ form = SettingForm(request.POST or None)+ if form.is_valid():+ setting = form.save()+ messages.success(request, _('Added setting %s') % setting)+ return redirect('dashboard:setting-index')+ ctx = {'form': form}+ return TemplateResponse(request, 'dashboard/settings/detail.html', ctx)diff --git a/templates/dashboard/settings/detail.html b/templates/dashboard/settings/detail.htmlnew file mode 100644index 0000000000..e5a3bcb225--- /dev/null+++ b/templates/dashboard/settings/detail.html@@ -0,0 +1,43 @@+{% extends 'dashboard/base.html' %}+{% load i18n %}+{% load materializecss %}++{% block title %}{% if setting.pk %}{{ setting }}{% else %}{% trans 'Add new setting' %}{% endif %} - {% trans 'Settings' %} - {{ block.super }}{% endblock %}++{% block body_class %}body-settings{% endblock %}++{% block menu_settings_class %}active{% endblock %}++{% block breadcrumbs %}+ <ul class="breadcrumbs breadcrumbs--history">+ <li><a href="{% url "dashboard:setting-index" %}" class="breadcrumb">{% trans "Settings" %}</a></li>+ <li class="back-mobile"><a href="{% url "dashboard:setting-index" %}" class="breadcrumb"><i class="material-icons">arrow_back</i></a></li>+ <li><span class="breadcrumbs--ellipsed-item">{% if setting.pk %}{{ setting }}{% else %}{% trans 'Add new setting' %}{% endif %}</span></li>+ </ul>+{% endblock %}++{% block content %}+ <form method="post" id="form-category" enctype="multipart/form-data" novalidate>+ {% csrf_token %}+ <div class="row">+ <div class="col l8">+ <div class="row">+ {{ form.name|materializecss }}+ {{ form.value_type|materializecss:"s4 m2" }}+ {{ form.value|materializecss:"s8 m10" }}+ </div>+ </div>+ </div>++ <div class="row">+ <div class="col s12 l8 right-align">+ <a href="{% url 'dashboard:setting-index' %}" class="btn-flat">{% trans "Cancel" %}</a>+ {% if setting.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/settings/index.html b/templates/dashboard/settings/index.htmlindex 37f7a8159d..d3015798f5 100644--- a/templates/dashboard/settings/index.html+++ b/templates/dashboard/settings/index.html@@ -16,7 +16,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 setting" %}"- href="#">+ href="{% url 'dashboard:setting-create' %}"><i class="material-icons">add</i></a></div>