diff --git a/src/backend/core/api/serializers.py b/src/backend/core/api/serializers.py index b9702b11d..df236908c 100644 --- a/src/backend/core/api/serializers.py +++ b/src/backend/core/api/serializers.py @@ -152,7 +152,6 @@ class Meta: model = models.Document fields = [ "id", - "content", "created_at", "creator", "depth", @@ -194,6 +193,7 @@ class Meta: "created_at", "creator", "depth", + "excerpt", "is_favorite", "link_role", "link_reach", diff --git a/src/backend/core/factories.py b/src/backend/core/factories.py index 5a77ad09e..2a6ad53a4 100644 --- a/src/backend/core/factories.py +++ b/src/backend/core/factories.py @@ -74,6 +74,7 @@ class Meta: parent = ParentNodeFactory() title = factory.Sequence(lambda n: f"document{n}") + excerpt = factory.Sequence(lambda n: f"excerpt{n}") content = factory.Sequence(lambda n: f"content{n}") creator = factory.SubFactory(UserFactory) link_reach = factory.fuzzy.FuzzyChoice( diff --git a/src/backend/core/migrations/0015_add_document_excerpt.py b/src/backend/core/migrations/0015_add_document_excerpt.py new file mode 100644 index 000000000..916e4be24 --- /dev/null +++ b/src/backend/core/migrations/0015_add_document_excerpt.py @@ -0,0 +1,23 @@ +# Generated by Django 5.1.4 on 2024-12-18 08:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0014_set_path_on_existing_documents'), + ] + + operations = [ + migrations.AddField( + model_name='document', + name='excerpt', + field=models.TextField(blank=True, max_length=300, null=True, verbose_name='excerpt'), + ), + migrations.AlterField( + model_name='user', + name='language', + field=models.CharField(choices="(('en-us', 'English'), ('fr-fr', 'French'), ('de-de', 'German'))", default='en-us', help_text='The language in which the user wants to see the interface.', max_length=10, verbose_name='language'), + ), + ] diff --git a/src/backend/core/models.py b/src/backend/core/models.py index 3ea7dca39..49c6823b1 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -326,6 +326,7 @@ class Document(MP_Node, BaseModel): """Pad document carrying the content.""" title = models.CharField(_("title"), max_length=255, null=True, blank=True) + excerpt = models.TextField(_("excerpt"), max_length=300, null=True, blank=True) link_reach = models.CharField( max_length=20, choices=LinkReachChoices.choices, diff --git a/src/backend/core/tests/documents/test_api_documents_children_create.py b/src/backend/core/tests/documents/test_api_documents_children_create.py index ffac8f2b7..775b132a3 100644 --- a/src/backend/core/tests/documents/test_api_documents_children_create.py +++ b/src/backend/core/tests/documents/test_api_documents_children_create.py @@ -2,7 +2,6 @@ Tests for Documents API endpoint in impress's core app: create """ -import random from uuid import uuid4 import pytest diff --git a/src/backend/core/tests/documents/test_api_documents_list.py b/src/backend/core/tests/documents/test_api_documents_list.py index 3464582f2..9f6263db4 100644 --- a/src/backend/core/tests/documents/test_api_documents_list.py +++ b/src/backend/core/tests/documents/test_api_documents_list.py @@ -59,7 +59,6 @@ def test_api_documents_list_format(): assert len(results) == 1 assert results[0] == { "id": str(document.id), - "content": document.content, "created_at": document.created_at.isoformat().replace("+00:00", "Z"), "creator": str(document.creator.id), "depth": 1, diff --git a/src/backend/core/tests/documents/test_api_documents_retrieve.py b/src/backend/core/tests/documents/test_api_documents_retrieve.py index f1315e939..239c9acb7 100644 --- a/src/backend/core/tests/documents/test_api_documents_retrieve.py +++ b/src/backend/core/tests/documents/test_api_documents_retrieve.py @@ -47,6 +47,7 @@ def test_api_documents_retrieve_anonymous_public_standalone(): "created_at": document.created_at.isoformat().replace("+00:00", "Z"), "creator": str(document.creator.id), "depth": 1, + "excerpt": document.excerpt, "is_favorite": False, "link_reach": "public", "link_role": document.link_role, @@ -99,6 +100,7 @@ def test_api_documents_retrieve_anonymous_public_parent(): "created_at": document.created_at.isoformat().replace("+00:00", "Z"), "creator": str(document.creator.id), "depth": 3, + "excerpt": document.excerpt, "is_favorite": False, "link_reach": document.link_reach, "link_role": document.link_role, @@ -184,6 +186,7 @@ def test_api_documents_retrieve_authenticated_unrelated_public_or_authenticated( "created_at": document.created_at.isoformat().replace("+00:00", "Z"), "creator": str(document.creator.id), "depth": 1, + "excerpt": document.excerpt, "is_favorite": False, "link_reach": reach, "link_role": document.link_role, @@ -243,6 +246,7 @@ def test_api_documents_retrieve_authenticated_public_or_authenticated_parent(rea "created_at": document.created_at.isoformat().replace("+00:00", "Z"), "creator": str(document.creator.id), "depth": 3, + "excerpt": document.excerpt, "is_favorite": False, "link_reach": document.link_reach, "link_role": document.link_role, @@ -350,6 +354,7 @@ def test_api_documents_retrieve_authenticated_related_direct(): "creator": str(document.creator.id), "created_at": document.created_at.isoformat().replace("+00:00", "Z"), "depth": 1, + "excerpt": document.excerpt, "is_favorite": False, "link_reach": document.link_reach, "link_role": document.link_role, @@ -409,6 +414,7 @@ def test_api_documents_retrieve_authenticated_related_parent(): "creator": str(document.creator.id), "created_at": document.created_at.isoformat().replace("+00:00", "Z"), "depth": 3, + "excerpt": document.excerpt, "is_favorite": False, "link_reach": "restricted", "link_role": document.link_role, @@ -558,6 +564,7 @@ def test_api_documents_retrieve_authenticated_related_team_members( "created_at": document.created_at.isoformat().replace("+00:00", "Z"), "creator": str(document.creator.id), "depth": 1, + "excerpt": document.excerpt, "is_favorite": False, "link_reach": "restricted", "link_role": document.link_role, @@ -617,6 +624,7 @@ def test_api_documents_retrieve_authenticated_related_team_administrators( "created_at": document.created_at.isoformat().replace("+00:00", "Z"), "creator": str(document.creator.id), "depth": 1, + "excerpt": document.excerpt, "is_favorite": False, "link_reach": "restricted", "link_role": document.link_role, @@ -677,6 +685,7 @@ def test_api_documents_retrieve_authenticated_related_team_owners( "created_at": document.created_at.isoformat().replace("+00:00", "Z"), "creator": str(document.creator.id), "depth": 1, + "excerpt": document.excerpt, "is_favorite": False, "link_reach": "restricted", "link_role": document.link_role,