mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	option to truncate content on /documents endpoint
This commit is contained in:
		| @@ -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 ? '...' : '') | ||||
|     ) | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -213,7 +213,8 @@ export class DocumentListViewService { | ||||
|         this.currentPageSize, | ||||
|         activeListViewState.sortField, | ||||
|         activeListViewState.sortReverse, | ||||
|         activeListViewState.filterRules | ||||
|         activeListViewState.filterRules, | ||||
|         { truncate_content: true } | ||||
|       ) | ||||
|       .subscribe({ | ||||
|         next: (result) => { | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon