👔(backend) add code_editor column on Template
To save the template code editor content, we need to add a new column on the Template model. It is a JSONField that will store the code editor content. We could in the future make an implementation to save the code editor content in Minio.
This commit is contained in:
@@ -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"]
|
||||
|
||||
|
||||
|
||||
@@ -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')),
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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": {},
|
||||
}
|
||||
|
||||
@@ -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"}
|
||||
Reference in New Issue
Block a user