Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add customer from dashboard
michale28c1b23806a
diff --git a/saleor/dashboard/customer/forms.py b/saleor/dashboard/customer/forms.pynew file mode 100644index 0000000000..76dc5f3b56--- /dev/null+++ b/saleor/dashboard/customer/forms.py@@ -0,0 +1,15 @@+from django import forms++from ...userprofile.models import User+++class CustomerForm(forms.ModelForm):+ def __init__(self, *args, **kwargs):+ self.user = kwargs.pop('user', None)+ super().__init__(*args, **kwargs)+ if self.user == self.instance:+ self.fields['is_active'].disabled = True++ class Meta:+ model = User+ fields = ['email', 'is_active']diff --git a/saleor/dashboard/customer/urls.py b/saleor/dashboard/customer/urls.pyindex f9f565f988..5553f6306e 100644--- a/saleor/dashboard/customer/urls.py+++ b/saleor/dashboard/customer/urls.py@@ -5,7 +5,10 @@ from . import viewsurlpatterns = [url(r'^$', views.customer_list, name='customers'),+ url(r'^create/$', views.customer_edit, name='customer-create'),url(r'^(?P<pk>[0-9]+)/$', views.customer_details, name='customer-details'),+ url(r'^(?P<pk>[0-9]+)/update/$', views.customer_edit,+ name='customer-update'),url(r'^(?P<pk>[0-9]+)/promote/$', views.customer_promote_to_staff,name='customer-promote')]diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.pyindex 974c9feca8..18165e0919 100644--- a/saleor/dashboard/customer/views.py+++ b/saleor/dashboard/customer/views.py@@ -8,7 +8,9 @@ from django.utils.translation import pgettext_lazyfrom ...core.utils import get_paginator_itemsfrom ...userprofile.models import Userfrom ..views import staff_member_required+from ..emails import send_set_password_emailfrom .filters import UserFilter+from .forms import CustomerForm@staff_member_required@@ -41,6 +43,28 @@ def customer_details(request, pk):return TemplateResponse(request, 'dashboard/customer/detail.html', ctx)+@staff_member_required+@permission_required('userprofile.edit_user')+def customer_edit(request, pk=None):+ if pk:+ customer = get_object_or_404(User, pk=pk)+ else:+ customer = User()+ form = CustomerForm(request.POST or None, instance=customer)+ if form.is_valid():+ form.save()+ msg = pgettext_lazy(+ 'Dashboard message', 'Updated customer') \+ if pk else pgettext_lazy(+ 'Dashboard message', 'Added customer')+ if not pk:+ send_set_password_email(customer)+ messages.success(request, msg)+ return redirect('dashboard:customer-details', pk=customer.pk)+ ctx = {'form': form, 'customer': customer}+ return TemplateResponse(request, 'dashboard/customer/form.html', ctx)++@staff_member_required@permission_required('userprofile.edit_staff')@permission_required('userprofile.edit_user')diff --git a/saleor/dashboard/staff/emails.py b/saleor/dashboard/emails.pysimilarity index 100%rename from saleor/dashboard/staff/emails.pyrename to saleor/dashboard/emails.pydiff --git a/saleor/dashboard/shipping/views.py b/saleor/dashboard/shipping/views.pyindex c38e1749ba..5f14d3aa32 100644--- a/saleor/dashboard/shipping/views.py+++ b/saleor/dashboard/shipping/views.py@@ -39,7 +39,7 @@ def shipping_method_edit(request, pk=None):if form.is_valid():method = form.save()msg = pgettext_lazy(- 'dashboard message', 'Updated shipping method') \+ 'Dashboard message', 'Updated shipping method') \if pk else pgettext_lazy('Dashboard message', 'Added shipping method')messages.success(request, msg)diff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.pyindex cbfa810324..284f0642b9 100644--- a/saleor/dashboard/staff/views.py+++ b/saleor/dashboard/staff/views.py@@ -5,9 +5,9 @@ from django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponsefrom django.utils.translation import pgettext_lazy-from .emails import send_set_password_emailfrom .filters import StaffFilterfrom .forms import StaffForm+from ..emails import send_set_password_emailfrom ..views import staff_member_requiredfrom ...core.utils import get_paginator_itemsfrom ...userprofile.models import Userdiff --git a/templates/dashboard/customer/detail.html b/templates/dashboard/customer/detail.htmlindex 37f0fb6490..ff1f11af52 100644--- a/templates/dashboard/customer/detail.html+++ b/templates/dashboard/customer/detail.html@@ -34,38 +34,52 @@</ul>{% endblock %}--{% block header_extra %}- {% if customer.pk and not customer.is_staff and perms.userprofile.edit_staff and perms.userprofile.edit_user or perms.userprofile.impersonate_user %}- <a class="dropdown-button right" href="#" data-activates="context-menu" data-constrainwidth="false">- <svg data-src="{% static "dashboard/images/more-vert.svg" %}" height="24" width="24" />- </a>- <ul id="context-menu" class="dropdown-content">- {% if perms.userprofile.edit_user and perms.userprofile.edit_staff %}- <li>- <a href="#base-modal" data-href="{% url 'dashboard:customer-promote' pk=customer.pk %}"- class="modal-trigger-custom">- {% trans 'Promote to staff' context 'Customer promote to staff member action' %}- </a>- </li>- {% endif %}- {% if perms.userprofile.impersonate_user %}- <li>- <a href="{% url 'impersonate-start' uid=customer.pk %}">Impersonate customer</a>- </li>- {% endif %}- </ul>- {% endif %}-{% endblock %}--{% block content %}<div class="row">- <div class="col s12 l8">+ <div class="col m12 l8">+ <div class="card">+ <div class="card-content">+ <span class="card-title">+ {{ customer.email }}+ </span>+ <div class="row">+ {% if customer.date_joined %}+ <div class="col s12 m4 l12">+ <h4>+ {% trans "Date joined" context "Customer field" %}+ </h4>+ <p>+ {{ customer.date_joined }}+ </p>+ </div>+ {% endif %}+ </div>+ </div>+ <div class="card-action">+ {% if perms.userprofile.edit_user %}+ <a class="btn-flat waves-effect" href="{% url 'dashboard:customer-update' customer.pk %}">+ {% trans "Edit customer" context "Customer action" %}+ </a>+ {% endif %}+ {% if not customer.is_staff and perms.userprofile.edit_user and perms.userprofile.edit_staff %}+ <a href="#base-modal" data-href="{% url 'dashboard:customer-promote' pk=customer.pk %}"+ class="modal-trigger-custom">+ {% trans 'Promote to staff' context 'Customer promote to staff member action' %}+ </a>+ {% endif %}+ {% if perms.userprofile.impersonate_user %}+ <a href="{% url 'impersonate-start' uid=customer.pk %}">+ {% trans 'Impersonate customer' context 'Customer impersonate action' %}+ </a>+ {% endif %}+ </div>++ </div>+<div class="card"><div class="data-table-header{% if not customer_orders %} data-table-header--no-data{% endif %}"><h5 class="data-table-title">- {% trans "Order history" context "Customer orders table title" %}+ {% trans "Recent orders" context "Customer recent orders table title" %}</h5></div>{% if customer_orders %}@@ -117,6 +131,7 @@</div></div>+<div class="col s12 l4"><div class="row"><div class="col s12 m6 p6 l12">diff --git a/templates/dashboard/customer/form.html b/templates/dashboard/customer/form.htmlnew file mode 100644index 0000000000..7eb4b9c16c--- /dev/null+++ b/templates/dashboard/customer/form.html@@ -0,0 +1,79 @@+{% extends "dashboard/base.html" %}+{% load materializecss %}+{% load i18n %}+{% load staticfiles %}++{% block title %}+ {% if customer.pk %}+ {{ customer }}+ {% else %}+ {% trans "Add new customer" context "Dashboard add customer" %}+ {% endif %}+ - {% trans "Customer" context "Dashboard customer" %} - {{ block.super }}+{% endblock %}++{% block body_class %}body-customers{% endblock %}++{% block menu_customers_class %}active{% endblock %}++{% block header_menu %}+ {% url "dashboard:customers" as url %}+ {% include "dashboard/includes/_back-link.html" with url=url %}+{% endblock %}++{% block breadcrumbs %}+ <ul class="breadcrumbs breadcrumbs--history">+ <li>+ <a href="{% url "dashboard:customers" %}">+ {% trans "Customers" context "Dashboard customers list" %}+ </a>+ </li>+ <li class="back-mobile">+ <a href="{% url "dashboard:customers" %}">+ <svg data-src="{% static "dashboard/images/arrow_left.svg" %}" fill="#fff" width="20px" height="20px" />+ </a>+ </li>+ <li><span class="breadcrumbs--elipsed-item">{% if customer.pk %}{{ customer }}{% else %}{% trans 'Add customer' context 'Dashboard add customer action' %}{% endif %}</span></li>+ </ul>+{% endblock %}++{% block content %}+ <div class="row">+ <div class="col s12 l8">+ {% if form %}+ <form class="card" method="post">+ <div class="card-content">+ <span class="card-title">+ {% trans 'Customer details' context 'Customer details header' %}+ </span>+ <div class="data">+ {% csrf_token %}+ <div class="row">+ {{ form|materializecss }}+ </div>+ </div>+ </div>+ {% if perms.userprofile.edit_user %}+ <div class="card-action right-align">+ {% if customer.pk %}+ <a href="{% url 'dashboard:customer-details' pk=customer.pk %}" class="btn-flat waves-effect">+ {% trans "Cancel" context "Dashboard cancel action" %}+ </a>+ <button type="submit" class="btn waves-effect">+ {% trans 'Update' context 'Dashboard update action' %}+ </button>+ {% else %}+ <a href="{% url 'dashboard:customers' %}" class="btn-flat waves-effect">+ {% trans "Cancel" context "Dashboard cancel action" %}+ </a>+ <button type="submit" class="btn waves-effect">+ {% trans 'Add' context 'Dashboard add action' %}+ </button>+ {% endif %}+ </div>+ {% endif %}+ </form>+ {% endif %}+ </div>+ </div>+{% endblock %}diff --git a/templates/dashboard/customer/list.html b/templates/dashboard/customer/list.htmlindex c81571875b..add2f414e7 100644--- a/templates/dashboard/customer/list.html+++ b/templates/dashboard/customer/list.html@@ -2,6 +2,7 @@{% load i18n %}{% load prices_i18n %}{% load materializecss %}+{% load staticfiles %}{% load utils %}{% block title %}@@ -12,6 +13,18 @@{% block menu_customers_class %}active{% endblock %}+{% block header_extra %}+ {% if perms.userprofile.edit_staff %}+ <div class="btn-fab-fixed">+ <a class="btn-fab-default waves-effect waves-light"+ title="{% trans "Add customer" context "Customer list add button text" %}"+ href="{% url 'dashboard:customer-create' %}">+ <svg data-src="{% static "dashboard/images/add.svg" %}" />+ </a>+ </div>+ {% endif %}+{% endblock %}+{% block breadcrumbs %}<ul class="breadcrumbs"><li class="visible-s">diff --git a/templates/dashboard/staff/detail.html b/templates/dashboard/staff/detail.htmlindex 9baa367484..06826d18c5 100644--- a/templates/dashboard/staff/detail.html+++ b/templates/dashboard/staff/detail.html@@ -7,7 +7,7 @@{% if staff_member %}{{ staff_member }}{% else %}- {% trans "Add new staff member" context "Dashboard add group" %}+ {% trans "Add new staff member" context "Dashboard add staff member" %}{% endif %}- {% trans "Staff" context "Dashboard staff" %} - {{ block.super }}{% endblock %}