Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Separate edit and create views in shipping app
Anna Siwik9699916a41a2
diff --git a/saleor/dashboard/shipping/urls.py b/saleor/dashboard/shipping/urls.pyindex e654c354ba..44748745ac 100644--- a/saleor/dashboard/shipping/urls.py+++ b/saleor/dashboard/shipping/urls.py@@ -4,7 +4,7 @@ from . import viewsurlpatterns = [url(r'^$', views.shipping_method_list, name='shipping-methods'),- url(r'^add/$', views.shipping_method_edit, name='shipping-method-add'),+ url(r'^add/$', views.shipping_method_add, name='shipping-method-add'),url(r'^(?P<pk>\d+)/update/$', views.shipping_method_edit,name='shipping-method-update'),url(r'^(?P<pk>\d+)/$', views.shipping_method_detail,@@ -13,7 +13,7 @@ urlpatterns = [views.shipping_method_delete, name='shipping-method-delete'),url(r'^(?P<shipping_method_pk>\d+)/country/add/$',- views.shipping_method_country_edit,+ views.shipping_method_country_add,name='shipping-method-country-add'),url(r'^(?P<shipping_method_pk>\d+)/country/(?P<country_pk>\d+)/update/$',views.shipping_method_country_edit,diff --git a/saleor/dashboard/shipping/views.py b/saleor/dashboard/shipping/views.pyindex 5f14d3aa32..6f401b2e8c 100644--- a/saleor/dashboard/shipping/views.py+++ b/saleor/dashboard/shipping/views.py@@ -28,25 +28,32 @@ def shipping_method_list(request):return TemplateResponse(request, 'dashboard/shipping/list.html', ctx)+@staff_member_required+@permission_required('shipping.edit_shipping')+def shipping_method_add(request):+ method = ShippingMethod()+ form = ShippingMethodForm(request.POST or None, instance=method)+ if form.is_valid():+ method = form.save()+ msg = pgettext_lazy('Dashboard message', 'Added shipping method')+ messages.success(request, msg)+ return redirect('dashboard:shipping-method-detail', pk=method.pk)+ ctx = {'form': form, 'shipping_method': form.instance}+ return TemplateResponse(request, 'dashboard/shipping/form.html', ctx)++@staff_member_required@permission_required('shipping.edit_shipping')def shipping_method_edit(request, pk=None):- if pk:- method = get_object_or_404(ShippingMethod, pk=pk)- else:- method = ShippingMethod()+ method = get_object_or_404(ShippingMethod, pk=pk)form = ShippingMethodForm(request.POST or None, instance=method)if form.is_valid():method = form.save()- msg = pgettext_lazy(- 'Dashboard message', 'Updated shipping method') \- if pk else pgettext_lazy(- 'Dashboard message', 'Added shipping method')+ msg = pgettext_lazy('Dashboard message', 'Updated shipping method')messages.success(request, msg)return redirect('dashboard:shipping-method-detail', pk=method.pk)ctx = {'form': form, 'shipping_method': method}- return TemplateResponse(- request, 'dashboard/shipping/form.html', ctx)+ return TemplateResponse(request, 'dashboard/shipping/form.html', ctx)@staff_member_required@@ -67,39 +74,52 @@ def shipping_method_delete(request, pk):shipping_method = get_object_or_404(ShippingMethod, pk=pk)if request.method == 'POST':shipping_method.delete()- messages.success(- request,- pgettext_lazy(- 'Dashboard message',- '%(shipping_method_name)s successfully removed') % {- 'shipping_method_name': shipping_method})+ msg = pgettext_lazy(+ 'Dashboard message',+ '%(shipping_method_name)s successfully removed') % {+ 'shipping_method_name': shipping_method}+ messages.success(request, msg)return redirect('dashboard:shipping-methods')ctx = {'shipping_method': shipping_method}return TemplateResponse(request, 'dashboard/shipping/modal/confirm_delete.html', ctx)+@staff_member_required+@permission_required('shipping.edit_shipping')+def shipping_method_country_add(request, shipping_method_pk):+ shipping_method = get_object_or_404(ShippingMethod, pk=shipping_method_pk)+ country = ShippingMethodCountry(shipping_method_id=shipping_method_pk)+ form = ShippingMethodCountryForm(request.POST or None, instance=country)+ if form.is_valid():+ country = form.save()+ msg = pgettext_lazy(+ 'Dashboard message', 'Added shipping price for %s') % (country,)+ messages.success(request, msg)+ return redirect(+ 'dashboard:shipping-method-detail', pk=shipping_method_pk)+ ctx = {+ 'form': form, 'shipping_method': shipping_method, 'country': country}+ return TemplateResponse(+ request, 'dashboard/shipping/country/form.html', ctx)++@staff_member_required@permission_required('shipping.edit_shipping')def shipping_method_country_edit(request, shipping_method_pk, country_pk=None):shipping_method = get_object_or_404(ShippingMethod, pk=shipping_method_pk)- if country_pk:- country = get_object_or_404(ShippingMethodCountry, pk=country_pk)- else:- country = ShippingMethodCountry(shipping_method_id=shipping_method_pk)+ country = get_object_or_404(ShippingMethodCountry, pk=country_pk)form = ShippingMethodCountryForm(request.POST or None, instance=country)if form.is_valid():country = form.save()msg = pgettext_lazy('Dashboard message',- 'Updated country shipping price %s') % (country,) \- if country_pk else pgettext_lazy(- 'Dashboard message', 'Added shipping price for %s') % (country,)+ 'Updated country shipping price %s') % (country,)messages.success(request, msg)return redirect('dashboard:shipping-method-detail', pk=shipping_method_pk)- ctx = {'form': form, 'shipping_method': shipping_method,- 'country': country}+ ctx = {+ 'form': form, 'shipping_method': shipping_method, 'country': country}return TemplateResponse(request, 'dashboard/shipping/country/form.html', ctx)@@ -111,14 +131,11 @@ def shipping_method_country_delete(country = get_object_or_404(ShippingMethodCountry, pk=country_pk)if request.method == 'POST':country.delete()- messages.success(- request,- pgettext_lazy(- 'Dashboard message',- 'Removed shipping method %s') %- (country,))+ msg = pgettext_lazy(+ 'Dashboard message', 'Removed shipping method %s') % (country,)+ messages.success(request, msg)return redirect('dashboard:shipping-method-detail', pk=shipping_method_pk)+ ctx = {'country': country, 'shipping_method_pk': shipping_method_pk}return TemplateResponse(- request, 'dashboard/shipping/modal/country_confirm_delete.html',- {'country': country, 'shipping_method_pk': shipping_method_pk})+ request, 'dashboard/shipping/modal/country_confirm_delete.html', ctx)