fix: added description_binary as field name

This commit is contained in:
NarayanBavisetti 2024-05-15 16:54:52 +05:30
parent 70f21649ed
commit fde1c3fcbc
4 changed files with 9 additions and 11 deletions

View File

@ -105,12 +105,10 @@ class PageSerializer(BaseSerializer):
class PageDetailSerializer(PageSerializer):
description_html = serializers.CharField()
description_yjs = serializers.CharField()
class Meta(PageSerializer.Meta):
fields = PageSerializer.Meta.fields + [
"description_html",
"description_yjs",
]

View File

@ -398,7 +398,7 @@ class PagesDescriptionViewSet(BaseViewSet):
page = Page.objects.get(
pk=pk, workspace__slug=slug, project_id=project_id
)
binary_data = page.description_yjs
binary_data = page.description_binary
def stream_data():
if binary_data:
@ -419,7 +419,7 @@ class PagesDescriptionViewSet(BaseViewSet):
pk=pk, workspace__slug=slug, project_id=project_id
)
base64_data = request.data.get("description_yjs")
base64_data = request.data.get("description_binary")
if base64_data:
# Decode the base64 data to bytes
@ -427,8 +427,8 @@ class PagesDescriptionViewSet(BaseViewSet):
# Load the existing data into a YDoc
existing_doc = Y.YDoc()
if page.description_yjs:
Y.apply_update(existing_doc, page.description_yjs)
if page.description_binary:
Y.apply_update(existing_doc, page.description_binary)
# # Load the new data into a separate YDoc
# new_doc = Y.YDoc()
@ -444,7 +444,7 @@ class PagesDescriptionViewSet(BaseViewSet):
updated_binary_data = Y.encode_state_as_update(existing_doc)
# Store the updated binary data
page.description_yjs = updated_binary_data
page.description_binary = updated_binary_data
page.description_html = request.data.get("description_html")
page.save()
return Response({"message": "Updated successfully"})

View File

@ -1,4 +1,4 @@
# Generated by Django 4.2.11 on 2024-05-08 09:23
# Generated by Django 4.2.11 on 2024-05-15 11:21
from django.db import migrations, models
@ -6,13 +6,13 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('db', '0064_auto_20240409_1134'),
('db', '0065_auto_20240415_0937'),
]
operations = [
migrations.AddField(
model_name='page',
name='description_yjs',
name='description_binary',
field=models.BinaryField(null=True),
),
]

View File

@ -18,7 +18,7 @@ def get_view_props():
class Page(ProjectBaseModel):
name = models.CharField(max_length=255)
description = models.JSONField(default=dict, blank=True)
description_yjs = models.BinaryField(null=True)
description_binary = models.BinaryField(null=True)
description_html = models.TextField(blank=True, default="<p></p>")
description_stripped = models.TextField(blank=True, null=True)
owned_by = models.ForeignKey(