Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix attribute_choice_value_edit and attribute_choice_value_delete
michal4a457de2dadb
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.pyindex 1b7f2d37d6..c5a519f252 100644--- a/saleor/dashboard/product/forms.py+++ b/saleor/dashboard/product/forms.py@@ -277,17 +277,9 @@ class StockLocationForm(forms.ModelForm):class AttributeChoiceValueForm(forms.ModelForm):- attribute = forms.CharField(widget=TextInput,- required=True)- def __init__(self, *args, **kwargs):- self.attribute = kwargs.pop('attribute')- super(AttributeChoiceValueForm, self).__init__(*args, **kwargs)- if self.attribute:- self.fields['attribute'] = self.attribute-class Meta:model = AttributeChoiceValue- exclude = ('slug', )+ fields = ['name', 'color']def save(self, commit=True):self.instance.slug = slugify(self.instance.name)diff --git a/saleor/dashboard/product/urls.py b/saleor/dashboard/product/urls.pyindex 031e71bc23..b67d1c73c5 100644--- a/saleor/dashboard/product/urls.py+++ b/saleor/dashboard/product/urls.py@@ -75,12 +75,15 @@ urlpatterns = [views.attribute_edit, name='product-attribute-add'),url(r'attributes/(?P<pk>[0-9]+)/delete/$',views.attribute_delete, name='product-attribute-delete'),- url(r'attributes/(?P<attribute_pk>[0-9]+)/value/(?P<value_pk>[0-9]+)/update/$',- views.attribute_value_edit, name='product-attribute-value-update'),+ url(r'attributes/(?P<attribute_pk>[0-9]+)/value/(?P<value_pk>[0-9]+)/update/$', # noqa+ views.attribute_choice_value_edit,+ name='product-attribute-value-update'),url(r'attributes/(?P<attribute_pk>[0-9]+)/value/add/$',- views.attribute_value_edit, name='product-attribute-value-add'),- url(r'attributes//(?P<attribute_pk>[0-9]+)value/(?P<value_pk>[0-9]+)/delete/$',- views.attribute_value_delete, name='product-attribute-value-delete'),+ views.attribute_choice_value_edit,+ name='product-attribute-value-add'),+ url(r'attributes/(?P<attribute_pk>[0-9]+)/value/(?P<value_pk>[0-9]+)/delete/$', # noqa+ views.attribute_choice_value_delete,+ name='product-attribute-value-delete'),url(r'stocklocations/$', views.stock_location_list,name='product-stock-location-list'),diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.pyindex 7155d2ae2a..0484f3d1c5 100644--- a/saleor/dashboard/product/views.py+++ b/saleor/dashboard/product/views.py@@ -519,23 +519,24 @@ def attribute_delete(request, pk):return redirect('dashboard:product-attributes')return TemplateResponse(request,- 'dashboard/product/product_attribute/modal/confirm_delete.html',+ 'dashboard/product/product_attribute/modal/'+ 'attribute_confirm_delete.html',{'attribute': attribute})@superuser_required-def attribute_value_edit(request, attribute_pk, value_pk=None):- attribute = get_object_or_404(ProductAttribute, pk=attribute_pk)+def attribute_choice_value_edit(request, attribute_pk, value_pk=None):if value_pk:value = get_object_or_404(AttributeChoiceValue, pk=value_pk)else:value = AttributeChoiceValue(attribute_id=attribute_pk)- form = forms.AttributeChoiceValueForm(request.POST or None,- attribute=attribute, instance=value)+ form = forms.AttributeChoiceValueForm(+ request.POST or None, instance=value)if form.is_valid():value = form.save()msg = pgettext_lazy(- 'Dashboard message', 'Updated attribute\'s value') if value.pk else pgettext_lazy(+ 'Dashboard message', 'Updated attribute\'s value')\+ if value.pk else pgettext_lazy('Dashboard message', 'Added attribute\'s value')messages.success(request, msg)return redirect('dashboard:product-attribute-detail', pk=attribute_pk)@@ -547,20 +548,21 @@ def attribute_value_edit(request, attribute_pk, value_pk=None):@superuser_required-def attribute_value_delete(request, pk):- attribute = get_object_or_404(ProductAttribute, pk=pk)+def attribute_choice_value_delete(request, attribute_pk, value_pk):+ value = get_object_or_404(AttributeChoiceValue, pk=value_pk)if request.method == 'POST':- attribute.delete()+ value.delete()messages.success(request,pgettext_lazy('Dashboard message',- 'Deleted attribute %s') % (attribute.name,))- return redirect('dashboard:product-attributes')+ 'Removed attribute choice value %s') % (value.name,))+ return redirect('dashboard:product-attribute-detail', pk=attribute_pk)return TemplateResponse(request,- 'dashboard/product/product_attribute/modal/confirm_delete.html',- {'attribute': attribute})+ 'dashboard/product/product_attribute/modal/'+ 'attribute_choice_value_confirm_delete.html',+ {'value': value, 'attribute_pk': attribute_pk})@staff_member_requireddiff --git a/templates/dashboard/product/product_attribute/detail.html b/templates/dashboard/product/product_attribute/detail.htmlindex fe9b50a9f7..36b0255798 100644--- a/templates/dashboard/product/product_attribute/detail.html+++ b/templates/dashboard/product/product_attribute/detail.html@@ -63,7 +63,7 @@</div>{% if perms.product.edit_product %}<div class="data-table-header-action">- <a href="" class="btn-data-table btn btn-flat">{% trans "Add" %}</a>+ <a href="{% url 'dashboard:product-attribute-value-add' attribute_pk=attribute.pk %}"" class="btn-data-table btn btn-flat">{% trans "Add" %}</a></div>{% endif %}<div class="data-table-container">@@ -91,8 +91,11 @@{% endif %}</td>{% if perms.product.edit_product %}- <td class="right-align"><a href="{% url "dashboard:product-attribute-value-update" attribute_pk=attribute.pk value_pk=value.pk %}" class="btn btn-flat">{% trans "Edit" %}</a></td>- {% endif %}+ <td class="right-align">+ <a href="{% url 'dashboard:product-attribute-value-update' attribute_pk=attribute.pk value_pk=value.pk %}" class="btn btn-flat">{% trans 'Edit' context 'Attribute choice value edit action' %}</a>+ <a class="btn btn-flat modal-trigger-custom" href="#base-modal" data-href="{% url 'dashboard:product-attribute-value-delete' attribute_pk=attribute.pk value_pk=value.pk %}">{% trans 'Remove' context 'Attribute choice value edit action' %}</a>+ </td>+ {% endif %}</tr>{% endfor %}</tbody>diff --git a/templates/dashboard/product/product_attribute/modal/attribute_choice_value_confirm_delete.html b/templates/dashboard/product/product_attribute/modal/attribute_choice_value_confirm_delete.htmlnew file mode 100644index 0000000000..216c69344e--- /dev/null+++ b/templates/dashboard/product/product_attribute/modal/attribute_choice_value_confirm_delete.html@@ -0,0 +1,19 @@+{% extends "dashboard/base_modal_confirm_delete.html" %}++{% load i18n %}++{% block action_url %}+{% url "dashboard:product-attribute-value-delete" attribute_pk=attribute_pk value_pk=value.pk %}+{% endblock %}++{% block title %}+{% blocktrans trimmed context "Modal delete attribute text" %}+Delete attribute choice value {{ value }}+{% endblocktrans %}+{% endblock title %}++{% block content %}+{% blocktrans trimmed context "Modal delete attribute text" %}+Are you sure you want to delete attribute choice value <strong>{{ value }}</strong>?+{% endblocktrans %}+{% endblock content %}diff --git a/templates/dashboard/product/product_attribute/modal/confirm_delete.html b/templates/dashboard/product/product_attribute/modal/attribute_confirm_delete.htmlsimilarity index 100%rename from templates/dashboard/product/product_attribute/modal/confirm_delete.htmlrename to templates/dashboard/product/product_attribute/modal/attribute_confirm_delete.htmldiff --git a/templates/dashboard/product/product_attribute/values_add_edit.html b/templates/dashboard/product/product_attribute/values_add_edit.htmlindex 019481f880..6e31ec9340 100644--- a/templates/dashboard/product/product_attribute/values_add_edit.html+++ b/templates/dashboard/product/product_attribute/values_add_edit.html@@ -67,16 +67,15 @@<span class="card-title">{% trans "Attribute values" context "Attribute values form title" %}</span>- <div class="row">- <div class="col s12 l8" >- <div class="row">- {{ form.name|materializecss }}- </div>- <div class="row">- {{ form.color|materializecss }}+ {% for field in form %}+ <div class="row">+ <div class="col s12 l8" >+ <div class="row">+ {{ field|materializecss }}+ </div></div></div>- </div>+ {% endfor %}</div><div class="card-action right-align">{% if value.pk %}