Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

option to truncate content on /documents endpoint

Michael Shamoon3c48ce0225c0
diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts
index de6b94032..4ce1ef705 100644
--- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts
+++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts
@@ -119,6 +119,9 @@ export class DocumentCardLargeComponent implements OnInit {
}
get contentTrimmed() {
- return this.document.content.substr(0, 500)
+ return (
+ this.document.content.substr(0, 500) +
+ (this.document.content.length > 500 ? '...' : '')
+ )
}
}
diff --git a/src-ui/src/app/services/document-list-view.service.ts b/src-ui/src/app/services/document-list-view.service.ts
index 3eb036710..3c5dbca21 100644
--- a/src-ui/src/app/services/document-list-view.service.ts
+++ b/src-ui/src/app/services/document-list-view.service.ts
@@ -213,7 +213,8 @@ export class DocumentListViewService {
this.currentPageSize,
activeListViewState.sortField,
activeListViewState.sortReverse,
- activeListViewState.filterRules
+ activeListViewState.filterRules,
+ { truncate_content: true }
)
.subscribe({
next: (result) => {
diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py
index db282cacd..356dd0a69 100644
--- a/src/documents/serialisers.py
+++ b/src/documents/serialisers.py
@@ -234,6 +234,12 @@ class DocumentSerializer(DynamicFieldsModelSerializer):
else:
return None
+ def to_representation(self, instance):
+ doc = super().to_representation(instance)
+ if self.truncate_content:
+ doc["content"] = doc.get("content")[0:550]
+ return doc
+
def update(self, instance, validated_data):
if "created_date" in validated_data and "created" not in validated_data:
new_datetime = datetime.datetime.combine(
@@ -247,6 +253,11 @@ class DocumentSerializer(DynamicFieldsModelSerializer):
super().update(instance, validated_data)
return instance
+ def __init__(self, *args, **kwargs):
+ self.truncate_content = kwargs.pop("truncate_content", False)
+
+ super().__init__(*args, **kwargs)
+
class Meta:
model = Document
depth = 1
diff --git a/src/documents/views.py b/src/documents/views.py
index 10225be6f..eb6f205c1 100644
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -226,9 +226,11 @@ class DocumentViewSet(
fields = fields_param.split(",")
else:
fields = None
+ truncate_content = self.request.query_params.get("truncate_content", "False")
serializer_class = self.get_serializer_class()
kwargs.setdefault("context", self.get_serializer_context())
kwargs.setdefault("fields", fields)
+ kwargs.setdefault("truncate_content", truncate_content.lower() in ["true", "1"])
return serializer_class(*args, **kwargs)
def update(self, request, *args, **kwargs):