Skip to content

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

Add staff delete action

michald9f81eb98fe3
diff --git a/saleor/dashboard/group/views.py b/saleor/dashboard/group/views.py
index aa03f04d4f..6de243931f 100644
--- a/saleor/dashboard/group/views.py
+++ b/saleor/dashboard/group/views.py
@@ -63,6 +63,4 @@ def group_delete(request, pk):
)
return redirect('dashboard:group-list')
return TemplateResponse(
- request, 'dashboard/group/modal/confirm_delete.html',
- {'group': group}
- )
+ request, 'dashboard/group/modal/confirm_delete.html', {'group': group})
diff --git a/saleor/dashboard/staff/urls.py b/saleor/dashboard/staff/urls.py
index 2d588a4652..5ef027d5bc 100644
--- a/saleor/dashboard/staff/urls.py
+++ b/saleor/dashboard/staff/urls.py
@@ -5,6 +5,7 @@ from . import views
urlpatterns = [
url(r'^$', views.staff_list, name='staff-list'),
+ url(r'^staff-create/$', views.staff_create, name='staff-create'),
url(r'^(?P<pk>[0-9]+)/$', views.staff_details, name='staff-details'),
- url(r'^add/$', views.staff_create, name='staff-create'),
+ url(r'^(?P<pk>[0-9]+)/delete/$', views.staff_delete, name='staff-delete'),
]
diff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.py
index 15e5fe46b8..44efa7397f 100644
--- a/saleor/dashboard/staff/views.py
+++ b/saleor/dashboard/staff/views.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
+from django.contrib import messages
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.utils.translation import pgettext_lazy
@@ -37,12 +38,24 @@ def staff_details(request, pk):
def staff_create(request):
staff = User()
staff_form = StaffForm()
-
if staff_form.is_valid():
staff = staff_form.save()
msg = pgettext_lazy(
- 'Dashboard message', 'Added staff user %s') % staff
+ 'Dashboard message', 'Added staff member %s') % staff
+ messages.success(request, msg)
return redirect('dashboard:staff-list', pk=staff.pk)
-
ctx = {'form': staff_form}
return TemplateResponse(request, 'dashboard/staff/detail.html', ctx)
+
+
+@superuser_required
+def staff_delete(request, pk):
+ staff = get_object_or_404(User, pk=pk)
+ if request.method == 'POST':
+ staff.delete()
+ msg = pgettext_lazy(
+ 'Dashboard message', 'Deleted staff member %s') % staff
+ messages.success(request, msg)
+ return redirect('dashboard:staff-list')
+ return TemplateResponse(
+ request, 'dashboard/staff/modal/confirm_delete.html', {'staff': staff})
diff --git a/templates/dashboard/group/detail.html b/templates/dashboard/group/detail.html
index 5c52ced84d..65670a445f 100644
--- a/templates/dashboard/group/detail.html
+++ b/templates/dashboard/group/detail.html
@@ -50,7 +50,7 @@
<li>
<a href="#base-modal" data-href="{% url 'dashboard:group-delete' pk=group.pk %}"
class="modal-trigger-custom">
- {% trans "Remove group" context "Group form action" %}
+ {% trans 'Remove group' context 'Group form action' %}
</a>
</li>
</ul>
@@ -82,7 +82,11 @@
{% trans "Cancel" context "Dashboard cancel action" %}
</a>
<button type="submit" class="btn waves-effect waves-light">
- {% trans "Update" context "Dashboard update action" %}
+ {% if group.name %}
+ {% trans 'Update' context 'Dashboard update action' %}
+ {% else %}
+ {% trans 'Add' context 'Dashboard add action' %}
+ {% endif %}
</button>
</div>
</div>
diff --git a/templates/dashboard/group/modal/confirm_delete.html b/templates/dashboard/group/modal/confirm_delete.html
index 25556b901b..2e1499a3fa 100644
--- a/templates/dashboard/group/modal/confirm_delete.html
+++ b/templates/dashboard/group/modal/confirm_delete.html
@@ -2,6 +2,8 @@
{% load i18n %}
+{% block action_url %}{% url 'dashboard:group-delete' pk=group.pk %}{% endblock %}
+
{% block title %}
{% blocktrans trimmed context "Modal delete group text" %}
Delete group <strong>{{ group }}</strong>?
@@ -14,5 +16,5 @@
<p>Users might lose permissions related to this group.</p>
{% endblocktrans %}
{% endblock content %}
-
+
diff --git a/templates/dashboard/staff/detail.html b/templates/dashboard/staff/detail.html
index 9264842919..30ce5d7f9a 100644
--- a/templates/dashboard/staff/detail.html
+++ b/templates/dashboard/staff/detail.html
@@ -4,7 +4,12 @@
{% load staticfiles %}
{% block title %}
- {{ staff_member }} - {% trans "Customers" context "Dashboard customers list" %} - {{ block.super }}
+ {% if staff_member %}
+ {{ staff_member }}
+ {% else %}
+ {% trans "Add new staff member" context "Dashboard add group" %}
+ {% endif %}
+ - {% trans "Staff" context "Dashboard staff" %} - {{ block.super }}
{% endblock %}
{% block body_class %}body-customers{% endblock %}
@@ -28,10 +33,26 @@
<svg data-src="{% static "dashboard/images/arrow_left.svg" %}" fill="#fff" width="20px" height="20px" />
</a>
</li>
- <li><span class="breadcrumbs--elipsed-item">{{ staff_member }}</span></li>
+ <li><span class="breadcrumbs--elipsed-item">{% if staff_member %}{{ staff_member }}{% else %}{% trans 'Add staff member' context 'Dashboard add staff member action' %}{% endif %}</span></li>
</ul>
{% endblock %}
+{% block header_extra %}
+ {% if staff_member.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:staff-delete' pk=staff_member.pk %}"
+ class="modal-trigger-custom">
+ {% trans 'Remove staff member' context 'Staff member form action' %}
+ </a>
+ </li>
+ </ul>
+ {% endif %}
+{% endblock %}
+
{% block content %}
<div class="row">
<div class="col s12 l8">
@@ -39,7 +60,7 @@
<form class="card" method="post">
<div class="card-content">
<span class="card-title">
- {% trans 'User details' context "User details header" %}
+ {% trans 'User details' context 'User details header' %}
</span>
<div class="data">
{% csrf_token %}
@@ -50,7 +71,11 @@
</div>
<div class="card-action right-align">
<button type="submit" class="btn waves-effect waves-light">
- {% trans "Update" context "Dashboard update action" %}
+ {% if staff_member %}
+ {% trans 'Update' context 'Dashboard update action' %}
+ {% else %}
+ {% trans 'Add' context 'Dashboard create action' %}
+ {% endif %}
</button>
</div>
</form>
diff --git a/templates/dashboard/staff/modal/confirm_delete.html b/templates/dashboard/staff/modal/confirm_delete.html
new file mode 100644
index 0000000000..047944d17c
--- /dev/null
+++ b/templates/dashboard/staff/modal/confirm_delete.html
@@ -0,0 +1,17 @@
+{% extends "dashboard/base_modal_confirm_delete.html" %}
+
+{% load i18n %}
+
+{% block action_url %}{% url 'dashboard:staff-delete' pk=staff.pk %}{% endblock %}
+
+{% block title %}
+{% blocktrans trimmed context "Modal delete group text" %}
+ Delete staff member <strong>{{ staff }}</strong>?
+{% endblocktrans %}
+{% endblock %}
+
+{% block content %}
+{% blocktrans trimmed context "Modal delete group text" %}
+<p>Are you sure you want to delete staff member {{ staff }}?</p>
+{% endblocktrans %}
+{% endblock content %}