diff --git a/src/backend/core/api/serializers.py b/src/backend/core/api/serializers.py index e6b9b99a..e6f9fb6a 100644 --- a/src/backend/core/api/serializers.py +++ b/src/backend/core/api/serializers.py @@ -145,7 +145,7 @@ class TemplateSerializer(BaseResourceSerializer): class Meta: model = models.Template - fields = ["id", "title", "accesses", "abilities"] + fields = ["id", "title", "code_editor", "accesses", "abilities"] read_only_fields = ["id", "accesses", "abilities"] diff --git a/src/backend/core/migrations/0001_initial.py b/src/backend/core/migrations/0001_initial.py index c7a572dd..4044bf77 100644 --- a/src/backend/core/migrations/0001_initial.py +++ b/src/backend/core/migrations/0001_initial.py @@ -42,6 +42,7 @@ class Migration(migrations.Migration): ('updated_at', models.DateTimeField(auto_now=True, help_text='date and time at which a record was last updated', verbose_name='updated on')), ('title', models.CharField(max_length=255, verbose_name='title')), ('description', models.TextField(blank=True, verbose_name='description')), + ('code_editor', models.JSONField(blank=True, default=dict, help_text='A JSON object with all the editor information', verbose_name='code editor')), ('code', models.TextField(blank=True, verbose_name='code')), ('css', models.TextField(blank=True, verbose_name='css')), ('is_public', models.BooleanField(default=False, help_text='Whether this template is public for anyone to use.', verbose_name='public')), diff --git a/src/backend/core/models.py b/src/backend/core/models.py index 887a2d55..37622113 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -326,6 +326,12 @@ class Template(BaseModel): title = models.CharField(_("title"), max_length=255) description = models.TextField(_("description"), blank=True) + code_editor = models.JSONField( + _("code editor"), + help_text=_("A JSON object with all the editor information"), + blank=True, + default=dict, + ) code = models.TextField(_("code"), blank=True) css = models.TextField(_("css"), blank=True) is_public = models.BooleanField( diff --git a/src/backend/core/tests/templates/test_api_templates_retrieve.py b/src/backend/core/tests/templates/test_api_templates_retrieve.py index 8ed186dd..c544ebd2 100644 --- a/src/backend/core/tests/templates/test_api_templates_retrieve.py +++ b/src/backend/core/tests/templates/test_api_templates_retrieve.py @@ -27,6 +27,7 @@ def test_api_templates_retrieve_anonymous_public(): }, "accesses": [], "title": template.title, + "code_editor": {}, } @@ -67,6 +68,7 @@ def test_api_templates_retrieve_authenticated_unrelated_public(): }, "accesses": [], "title": template.title, + "code_editor": {}, } @@ -131,6 +133,7 @@ def test_api_templates_retrieve_authenticated_related_direct(): "id": str(template.id), "title": template.title, "abilities": template.get_abilities(user), + "code_editor": {}, } @@ -244,6 +247,7 @@ def test_api_templates_retrieve_authenticated_related_team_members( "id": str(template.id), "title": template.title, "abilities": template.get_abilities(user), + "code_editor": {}, } @@ -339,6 +343,7 @@ def test_api_templates_retrieve_authenticated_related_team_administrators( "id": str(template.id), "title": template.title, "abilities": template.get_abilities(user), + "code_editor": {}, } @@ -438,4 +443,5 @@ def test_api_templates_retrieve_authenticated_related_team_owners( "id": str(template.id), "title": template.title, "abilities": template.get_abilities(user), + "code_editor": {}, } diff --git a/src/backend/core/tests/test_models_templates.py b/src/backend/core/tests/test_models_templates.py index dc295bc7..87b701c6 100644 --- a/src/backend/core/tests/test_models_templates.py +++ b/src/backend/core/tests/test_models_templates.py @@ -159,3 +159,8 @@ def test_models_templates_get_abilities_preset_role(django_assert_num_queries): "manage_accesses": False, "generate_document": True, } + +def test_models_templates_get_code_editor(): + """Check code_editor in the template model""" + template = factories.TemplateFactory(code_editor={"test": "ok"}) + assert template.code_editor == {"test": "ok"} \ No newline at end of file