Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Extend AttributeValue name and text to allow for longer translations
Ania Warzechac32d64b75857
diff --git a/saleor/attribute/migrations/0030_auto_20230823_1702.py b/saleor/attribute/migrations/0030_auto_20230823_1702.pynew file mode 100644index 0000000000..e762535ca9--- /dev/null+++ b/saleor/attribute/migrations/0030_auto_20230823_1702.py@@ -0,0 +1,32 @@+# Generated by Django 3.2.20 on 2023-08-23 17:02++from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("attribute", "0029_alter_attribute_unit"),+ ]++ operations = [+ migrations.AlterField(+ model_name="attributetranslation",+ name="name",+ field=models.CharField(max_length=255),+ ),+ migrations.AlterField(+ model_name="attributevalue",+ name="name",+ field=models.CharField(max_length=255),+ ),+ migrations.AlterField(+ model_name="attributevalue",+ name="value",+ field=models.CharField(blank=True, default="", max_length=255),+ ),+ migrations.AlterField(+ model_name="attributevaluetranslation",+ name="name",+ field=models.CharField(max_length=255),+ ),+ ]diff --git a/saleor/attribute/models/base.py b/saleor/attribute/models/base.pyindex 91736f21a8..23b8c75bc7 100644--- a/saleor/attribute/models/base.py+++ b/saleor/attribute/models/base.py@@ -189,7 +189,7 @@ class AttributeTranslation(Translation):attribute = models.ForeignKey(Attribute, related_name="translations", on_delete=models.CASCADE)- name = models.CharField(max_length=100)+ name = models.CharField(max_length=255)class Meta:unique_together = (("language_code", "attribute"),)@@ -214,9 +214,9 @@ class AttributeTranslation(Translation):class AttributeValue(SortableModel, ModelWithExternalReference):- name = models.CharField(max_length=250)+ name = models.CharField(max_length=255)# keeps hex code color value in #RRGGBBAA format- value = models.CharField(max_length=100, blank=True, default="")+ value = models.CharField(max_length=255, blank=True, default="")slug = models.SlugField(max_length=255, allow_unicode=True)file_url = models.URLField(null=True, blank=True)content_type = models.CharField(max_length=50, null=True, blank=True)@@ -278,7 +278,7 @@ class AttributeValueTranslation(Translation):attribute_value = models.ForeignKey(AttributeValue, related_name="translations", on_delete=models.CASCADE)- name = models.CharField(max_length=100)+ name = models.CharField(max_length=255)rich_text = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)plain_text = models.TextField(blank=True,diff --git a/saleor/graphql/translations/mutations/attribute_value_bulk_translate.py b/saleor/graphql/translations/mutations/attribute_value_bulk_translate.pyindex 35010d6a78..48d664ec2d 100644--- a/saleor/graphql/translations/mutations/attribute_value_bulk_translate.py+++ b/saleor/graphql/translations/mutations/attribute_value_bulk_translate.py@@ -142,8 +142,8 @@ class AttributeValueBulkTranslate(BaseBulkTranslateMutation):if input_data.get("name") is None:if instance.attribute.input_type == AttributeInputType.RICH_TEXT:input_data["name"] = truncatechars(- clean_editor_js(input_data["rich_text"], to_string=True), 100+ clean_editor_js(input_data["rich_text"], to_string=True), 255)elif instance.attribute.input_type == AttributeInputType.PLAIN_TEXT:- input_data["name"] = truncatechars(input_data["plain_text"], 100)+ input_data["name"] = truncatechars(input_data["plain_text"], 255)return input_datadiff --git a/saleor/graphql/translations/mutations/attribute_value_translate.py b/saleor/graphql/translations/mutations/attribute_value_translate.pyindex 369c7b776f..e0b3801672 100644--- a/saleor/graphql/translations/mutations/attribute_value_translate.py+++ b/saleor/graphql/translations/mutations/attribute_value_translate.py@@ -42,8 +42,8 @@ class AttributeValueTranslate(BaseTranslateMutation):if "name" not in input_data.keys() or input_data["name"] is None:if instance.attribute.input_type == AttributeInputType.RICH_TEXT:input_data["name"] = truncatechars(- clean_editor_js(input_data["rich_text"], to_string=True), 100+ clean_editor_js(input_data["rich_text"], to_string=True), 255)elif instance.attribute.input_type == AttributeInputType.PLAIN_TEXT:- input_data["name"] = truncatechars(input_data["plain_text"], 100)+ input_data["name"] = truncatechars(input_data["plain_text"], 255)return input_datadiff --git a/saleor/graphql/translations/tests/test_translations.py b/saleor/graphql/translations/tests/test_translations.pyindex 3808c12fb3..7f41941460 100644--- a/saleor/graphql/translations/tests/test_translations.py+++ b/saleor/graphql/translations/tests/test_translations.py@@ -955,7 +955,7 @@ def test_product_create_translation_validates_name_length(product_id = graphene.Node.to_global_id("Product", product.id)variables = {"productId": product_id,- "input": {"description": None, "name": "Long" * 100},+ "input": {"description": None, "name": "Long" * 255},}response = staff_api_client.post_graphql(PRODUCT_TRANSLATE_MUTATION,@@ -1171,7 +1171,7 @@ def test_product_variant_translation_mutation_validates_inputs_length(PRODUCT_VARIANT_TRANSLATE_MUTATION,{"productVariantId": translatable_content_id,- "input": {"name": "Wariant PL" * 100},+ "input": {"name": "Wariant PL" * 255},},permissions=[permission_manage_translations],)@@ -1356,7 +1356,7 @@ def test_collection_translation_mutation_validates_inputs_length(COLLECTION_TRANSLATE_MUTATION,{"collectionId": collection_id,- "input": {"description": description, "name": "long" * 100},+ "input": {"description": description, "name": "long" * 255},},permissions=[permission_manage_translations],)@@ -2277,7 +2277,7 @@ def test_rich_text_attribute_value_update_translation_only_rich_text_long_text(attribute_value_id = graphene.Node.to_global_id("AttributeValue", attribute_value.id)- expected_base_text = "Nowy Opis. " * 100+ expected_base_text = "Nowy Opis. " * 255expected_rich_text = json.dumps(dummy_editorjs(expected_base_text))# when@@ -2294,7 +2294,7 @@ def test_rich_text_attribute_value_update_translation_only_rich_text_long_text(data = get_graphql_content(response)["data"]["attributeValueTranslate"]assert data["attributeValue"]["translation"]["language"]["code"] == "PL"assert (- data["attributeValue"]["translation"]["name"] == expected_base_text[:99] + "…"+ data["attributeValue"]["translation"]["name"] == expected_base_text[:254] + "…")assert data["attributeValue"]["translation"]["richText"] == expected_rich_text@@ -2467,7 +2467,7 @@ def test_plain_text_attribute_value_update_translation_only_plain_text_long_textattribute_value_id = graphene.Node.to_global_id("AttributeValue", attribute_value.id)- expected_base_text = "Nowy Opis. " * 100+ expected_base_text = "Nowy Opis. " * 255# whenresponse = staff_api_client.post_graphql(@@ -2483,7 +2483,7 @@ def test_plain_text_attribute_value_update_translation_only_plain_text_long_textdata = get_graphql_content(response)["data"]["attributeValueTranslate"]assert data["attributeValue"]["translation"]["language"]["code"] == "PL"assert (- data["attributeValue"]["translation"]["name"] == expected_base_text[:99] + "…"+ data["attributeValue"]["translation"]["name"] == expected_base_text[:254] + "…")assert data["attributeValue"]["translation"]["plainText"] == expected_base_text@@ -2975,7 +2975,7 @@ def test_shop_translation_validates_values_lengths(response = staff_api_client.post_graphql(SHOP_SETTINGS_TRANSLATE_MUTATION,- {"input": {"headerText": "Nagłówek PL" * 100}},+ {"input": {"headerText": "Nagłówek PL" * 255}},permissions=[permission_manage_translations],)data = get_graphql_content(response)["data"]["shopSettingsTranslate"]