Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change promoting to modal action
michala1c41c9e6b71
diff --git a/saleor/dashboard/customer/forms.py b/saleor/dashboard/customer/forms.pydeleted file mode 100644index ac092d6d44..0000000000--- a/saleor/dashboard/customer/forms.py+++ /dev/null@@ -1,15 +0,0 @@-from django import forms--from ...userprofile.models import User---class StaffPromoteForm(forms.ModelForm):- def __init__(self, *args, **kwargs):- self.admin = kwargs.pop('admin', None)- super(StaffPromoteForm, self).__init__(*args, **kwargs)- if self.admin == self.instance or not self.admin.is_superuser:- self.fields['is_staff'].widget.attrs['disabled'] = True-- class Meta:- model = User- fields = ['is_staff']diff --git a/saleor/dashboard/customer/urls.py b/saleor/dashboard/customer/urls.pyindex ffcd04b134..f9f565f988 100644--- a/saleor/dashboard/customer/urls.py+++ b/saleor/dashboard/customer/urls.py@@ -5,5 +5,7 @@ from . import viewsurlpatterns = [url(r'^$', views.customer_list, name='customers'),- url(r'^(?P<pk>[0-9]+)/$', views.customer_details, name='customer-details')+ url(r'^(?P<pk>[0-9]+)/$', views.customer_details, name='customer-details'),+ 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 9ee44247bb..21f70347f0 100644--- a/saleor/dashboard/customer/views.py+++ b/saleor/dashboard/customer/views.py@@ -1,15 +1,16 @@from __future__ import unicode_literals+from django.contrib import messages+from django.contrib.auth.decorators import permission_requiredfrom django.db.models import Count, Max-from django.shortcuts import get_object_or_404+from django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponse-from django.contrib.auth.decorators import permission_required+from django.utils.translation import pgettext_lazyfrom ...core.utils import get_paginator_itemsfrom ...userprofile.models import Userfrom ...settings import DASHBOARD_PAGINATE_BY-from ..views import staff_member_required-from .forms import StaffPromoteForm+from ..views import staff_member_required, superuser_required@staff_member_required@@ -36,11 +37,21 @@ def customer_details(request, pk):'orders', 'addresses').select_related('default_billing_address', 'default_shipping_address')customer = get_object_or_404(queryset, pk=pk)- form = StaffPromoteForm(- request.POST or None, instance=customer, admin=request.user)- if form.is_valid():- form.save()customer_orders = customer.orders.all()- ctx = {'customer': customer, 'customer_orders': customer_orders,- 'form': form}+ ctx = {'customer': customer, 'customer_orders': customer_orders}return TemplateResponse(request, 'dashboard/customer/detail.html', ctx)+++@superuser_required+def customer_promote_to_staff(request, pk):+ customer = get_object_or_404(User, pk=pk)+ if request.method == 'POST':+ customer.is_staff = True+ msg = pgettext_lazy(+ 'Dashboard message',+ 'Customer %s promoted to staff member') % customer+ messages.success(request, msg)+ return redirect('dashboard:staff-list')+ return TemplateResponse(+ request, 'dashboard/customer/modal/confirm_promote.html',+ {'customer': customer})diff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.pyindex 694131d4fc..92dce2c82f 100644--- a/saleor/dashboard/staff/views.py+++ b/saleor/dashboard/staff/views.py@@ -5,7 +5,7 @@ from django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponsefrom django.utils.translation import pgettext_lazy-from saleor.dashboard.staff.emails import send_set_password_email+from emails import send_set_password_emailfrom .forms import StaffFormfrom ..views import superuser_requiredfrom ...core.utils import get_paginator_items@@ -32,6 +32,10 @@ def staff_details(request, pk):admin=request.user)if form.is_valid():form.save()+ msg = pgettext_lazy(+ 'Dashboard message', 'Updated staff member %s') % staff_member+ messages.success(request, msg)+ redirect('dashboard:staff-list')ctx = {'staff_member': staff_member, 'form': form}return TemplateResponse(request, 'dashboard/staff/detail.html', ctx)diff --git a/templates/dashboard/customer/detail.html b/templates/dashboard/customer/detail.htmlindex 9356756bc1..f8e35d4abd 100644--- a/templates/dashboard/customer/detail.html+++ b/templates/dashboard/customer/detail.html@@ -34,6 +34,24 @@</ul>{% endblock %}++{% block header_extra %}+ {% if customer.pk %}+ <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">+ <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>+ </ul>+ {% endif %}+{% endblock %}++{% block content %}<div class="row"><div class="col s12 l8">@@ -94,24 +112,6 @@<div class="col s12 l4"><div class="row">- <div class="col s12 m6 p6 l12">- <div class="card equal-height-on-med">- <div class="card-content">- <span class="card-title black-text">- {% trans "Staff member status" context "Customer staff member status card title" %}- </span>- <form method="post">- {% csrf_token %}- {{ form|materializecss }}- <div class="card-action right-align">- <button type="submit" class="btn waves-effect waves-light" {% if not user.is_superuser or user == customer %}disabled{% endif %}>- {% trans 'Update' context 'Dashboard update action' %}- </button>- </div>- </form>- </div>- </div>- </div><div class="col s12 m6 p6 l12"><div class="card equal-height-on-med"><div class="card-content">diff --git a/templates/dashboard/customer/modal/confirm_promote.html b/templates/dashboard/customer/modal/confirm_promote.htmlnew file mode 100644index 0000000000..fafd137312--- /dev/null+++ b/templates/dashboard/customer/modal/confirm_promote.html@@ -0,0 +1,29 @@+{% load i18n %}++<form action="{% block action_url %}#!{% endblock %}" method="post" novalidate>+ {% csrf_token %}+ <div class="modal-content">+ <div class="row">+ <div class="col s12">+ <h5>+ {% block title %}+ {% trans "Promote to staff member" context "Dashboard confirmation modal" %}+ {% endblock %}+ </h5>+ </div>+ </div>+ {% block content %}+ {% trans "Are you sure?" context "Dashboard confirmation modal" %}+ {% endblock %}+ </div>+ <div class="modal-footer">+ {% block footer %}+ <button type="submit" class="modal-action btn-flat">+ {% trans "Promote" context "Dashboard promote action" %}+ </button>+ <a href="#!" class="modal-action modal-close btn-flat">+ {% trans "Cancel" context "Dashboard cancel action" %}+ </a>+ {% endblock footer %}+ </div>+</form>diff --git a/templates/dashboard/staff/detail.html b/templates/dashboard/staff/detail.htmlindex d774a76cd5..628ee3b8ff 100644--- a/templates/dashboard/staff/detail.html+++ b/templates/dashboard/staff/detail.html@@ -70,6 +70,9 @@</div></div><div class="card-action right-align">+ <a href="{% url 'dashboard:staff-list' %}" class="btn btn-flat">+ {% trans "Cancel" context "Dashboard cancel action" %}+ </a><button type="submit" class="btn waves-effect waves-light">{% if staff_member %}{% trans 'Update' context 'Dashboard update action' %}