Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Split customer_edit to customer_edit and customer_create
michal3c3c998e90ee
diff --git a/saleor/dashboard/customer/forms.py b/saleor/dashboard/customer/forms.pyindex 76dc5f3b56..31acf87e19 100644--- a/saleor/dashboard/customer/forms.py+++ b/saleor/dashboard/customer/forms.py@@ -7,6 +7,7 @@ class CustomerForm(forms.ModelForm):def __init__(self, *args, **kwargs):self.user = kwargs.pop('user', None)super().__init__(*args, **kwargs)+ # disable 'is_active' checkbox if user edits his own accountif self.user == self.instance:self.fields['is_active'].disabled = Truediff --git a/saleor/dashboard/customer/urls.py b/saleor/dashboard/customer/urls.pyindex 5553f6306e..6dca905893 100644--- a/saleor/dashboard/customer/urls.py+++ b/saleor/dashboard/customer/urls.py@@ -5,7 +5,7 @@ from . import viewsurlpatterns = [url(r'^$', views.customer_list, name='customers'),- url(r'^create/$', views.customer_edit, name='customer-create'),+ url(r'^create/$', views.customer_create, 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'),diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.pyindex 18165e0919..1f10dac156 100644--- a/saleor/dashboard/customer/views.py+++ b/saleor/dashboard/customer/views.py@@ -43,22 +43,31 @@ def customer_details(request, pk):return TemplateResponse(request, 'dashboard/customer/detail.html', ctx)+@staff_member_required+@permission_required('userprofile.edit_user')+def customer_create(request):+ customer = User()+ form = CustomerForm(request.POST or None, instance=customer)+ if form.is_valid():+ form.save()+ msg = pgettext_lazy(+ 'Dashboard message', 'Added customer %s' % customer)+ 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_user')def customer_edit(request, pk=None):- if pk:- customer = get_object_or_404(User, pk=pk)- else:- customer = User()+ customer = get_object_or_404(User, pk=pk)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)+ 'Dashboard message', 'Updated customer %s' % customer)messages.success(request, msg)return redirect('dashboard:customer-details', pk=customer.pk)ctx = {'form': form, 'customer': customer}