From faeb8d137b377eb8cafbcbb5fe14a1129ba3f2d3 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Wed, 17 Apr 2024 10:18:43 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=94(backend)=20add=20css=20and=20code?= =?UTF-8?q?=20in=20template=20serializer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to be able to update the css and code of a template from the update endpoint. This commit adds the css and code fields to the TemplateSerializer. --- src/backend/core/api/serializers.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/core/api/serializers.py b/src/backend/core/api/serializers.py index e6f9fb6a..a947702f 100644 --- a/src/backend/core/api/serializers.py +++ b/src/backend/core/api/serializers.py @@ -145,9 +145,19 @@ class TemplateSerializer(BaseResourceSerializer): class Meta: model = models.Template - fields = ["id", "title", "code_editor", "accesses", "abilities"] + fields = ["id", "title", "code_editor", "accesses", "abilities", "css", "code"] read_only_fields = ["id", "accesses", "abilities"] + def to_representation(self, instance): + """ + Modify the output of serialization. + """ + representation = super().to_representation(instance) + # Remove 'css' and 'code' from the representation + representation.pop("css", None) + representation.pop("code", None) + return representation + # pylint: disable=abstract-method class DocumentGenerationSerializer(serializers.Serializer):