Skip to content

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

Drop HTML fields and migrate them to JSON

NyanKiyoshi491242667566
diff --git a/.isort.cfg b/.isort.cfg
index c763521e00..5c1e396cba 100644
--- a/.isort.cfg
+++ b/.isort.cfg
@@ -1,2 +1,2 @@
[settings]
-known_third_party = PIL,babel,bleach,bootstrap4,braintree,captcha,celery,dj_database_url,dj_email_url,django,django_babel,django_cache_url,django_countries,django_elasticsearch_dsl,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,elasticsearch_dsl,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_django_optimizer,graphql,graphql_jwt,graphql_relay,html5lib,i18naddress,impersonate,markdown,measurement,mptt,phonenumber_field,phonenumbers,prices,promise,pytest,razorpay,requests,six,social_core,storages,stripe,templated_email,text_unidecode,versatileimagefield
+known_third_party = PIL,babel,bleach,bootstrap4,braintree,captcha,celery,dj_database_url,dj_email_url,django,django_babel,django_cache_url,django_countries,django_elasticsearch_dsl,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,elasticsearch_dsl,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_django_optimizer,graphql,graphql_jwt,graphql_relay,html5lib,html_to_draftjs,i18naddress,impersonate,markdown,measurement,mptt,phonenumber_field,phonenumbers,prices,promise,pytest,razorpay,requests,six,social_core,storages,stripe,templated_email,text_unidecode,versatileimagefield
diff --git a/Pipfile b/Pipfile
index 0f611a82b8..2074815941 100644
--- a/Pipfile
+++ b/Pipfile
@@ -63,6 +63,7 @@ razorpay = ">=1.1.1"
stripe = "*"
"urllib3" = "*"
dataclasses = {version = "*",markers = "python_version < '3.7'"}
+html-to-draftjs = "*"
[dev-packages]
pytest = "*"
diff --git a/saleor/page/migrations/0008_raw_html_to_json.py b/saleor/page/migrations/0008_raw_html_to_json.py
new file mode 100644
index 0000000000..fa8897d6b9
--- /dev/null
+++ b/saleor/page/migrations/0008_raw_html_to_json.py
@@ -0,0 +1,31 @@
+# Generated by Django 2.2.3 on 2019-07-15 07:51
+
+from django.db import migrations
+from html_to_draftjs import html_to_draftjs
+
+
+def convert_pages_html_to_json(apps, schema_editor):
+ Page = apps.get_model("page", "Page")
+ qs = Page.objects.filter(content_json={})
+
+ for page in qs:
+ page.content_json = html_to_draftjs(page.content)
+ page.save(update_fields=["content_json"])
+
+ PageTranslation = apps.get_model("page", "PageTranslation")
+ qs = PageTranslation.objects.filter(content_json={})
+
+ for translation in qs:
+ translation.content_json = html_to_draftjs(translation.content)
+ translation.save(update_fields=["content_json"])
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [("page", "0007_auto_20190225_0252")]
+
+ operations = [
+ migrations.RunPython(convert_pages_html_to_json),
+ migrations.RemoveField(model_name="page", name="content"),
+ migrations.RemoveField(model_name="pagetranslation", name="content"),
+ ]
diff --git a/saleor/page/models.py b/saleor/page/models.py
index 61c3fd37c7..dc68b638c9 100644
--- a/saleor/page/models.py
+++ b/saleor/page/models.py
@@ -18,7 +18,6 @@ class PagePublishedQuerySet(PublishedQuerySet):
class Page(SeoModel, PublishableModel):
slug = models.SlugField(unique=True, max_length=100)
title = models.CharField(max_length=200)
- content = models.TextField(blank=True)
content_json = JSONField(blank=True, default=dict)
created = models.DateTimeField(auto_now_add=True)
@@ -47,7 +46,6 @@ class PageTranslation(SeoModelTranslation):
Page, related_name="translations", on_delete=models.CASCADE
)
title = models.CharField(max_length=255, blank=True)
- content = models.TextField(blank=True)
content_json = JSONField(blank=True, default=dict)
class Meta:
diff --git a/saleor/product/migrations/0096_raw_html_to_json.py b/saleor/product/migrations/0096_raw_html_to_json.py
new file mode 100644
index 0000000000..551147ce9f
--- /dev/null
+++ b/saleor/product/migrations/0096_raw_html_to_json.py
@@ -0,0 +1,31 @@
+# Generated by Django 2.2.3 on 2019-07-15 07:47
+
+from django.db import migrations
+from html_to_draftjs import html_to_draftjs
+
+
+def convert_products_html_to_json(apps, schema_editor):
+ Product = apps.get_model("product", "Product")
+ qs = Product.objects.filter(description_json={})
+
+ for product in qs:
+ product.description_json = html_to_draftjs(product.description)
+ product.save(update_fields=["description_json"])
+
+ ProductTranslation = apps.get_model("product", "ProductTranslation")
+ qs = ProductTranslation.objects.filter(description_json={})
+
+ for translation in qs:
+ translation.description_json = html_to_draftjs(translation.description)
+ translation.save(update_fields=["description_json"])
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [("product", "0095_auto_20190618_0842")]
+
+ operations = [
+ migrations.RunPython(convert_products_html_to_json),
+ migrations.RemoveField(model_name="product", name="description"),
+ migrations.RemoveField(model_name="producttranslation", name="description"),
+ ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 4b55f9abf4..6407f66dad 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -123,7 +123,6 @@ class Product(SeoModel, PublishableModel):
ProductType, related_name="products", on_delete=models.CASCADE
)
name = models.CharField(max_length=128)
- description = models.TextField(blank=True)
description_json = JSONField(blank=True, default=dict)
category = models.ForeignKey(
Category, related_name="products", on_delete=models.CASCADE
@@ -204,7 +203,6 @@ class ProductTranslation(SeoModelTranslation):
Product, related_name="translations", on_delete=models.CASCADE
)
name = models.CharField(max_length=128)
- description = models.TextField(blank=True)
description_json = JSONField(blank=True, default=dict)
class Meta: