]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
add document comments to dedicated manifest file when using 'split-manifest'
authorMatthieu Helleboid <mhelleboid@hotmail.com>
Fri, 20 Jan 2023 19:31:03 +0000 (20:31 +0100)
committerTrenton H <797416+stumpylog@users.noreply.github.com>
Tue, 24 Jan 2023 19:06:49 +0000 (11:06 -0800)
src/documents/management/commands/document_exporter.py

index 219217fd7802634f52f5c84f5f9f5a40684e9203..cdb8991390ec59188d5c7fd2721d6199e9712fb6 100644 (file)
@@ -220,9 +220,11 @@ class Command(BaseCommand):
                 serializers.serialize("json", StoragePath.objects.all()),
             )
 
-            manifest += json.loads(
+            comments = json.loads(
                 serializers.serialize("json", Comment.objects.all()),
             )
+            if not self.split_manifest:
+                manifest += comments
 
             documents = Document.objects.order_by("id")
             document_map = {d.pk: d for d in documents}
@@ -351,9 +353,14 @@ class Command(BaseCommand):
                     manifest_name = os.path.join("json", manifest_name)
                 manifest_name = (self.target / Path(manifest_name)).resolve()
                 manifest_name.parent.mkdir(parents=True, exist_ok=True)
-                manifest_name.write_text(
-                    json.dumps([document_manifest[index]], indent=2),
+                content = [document_manifest[index]]
+                content += list(
+                    filter(
+                        lambda d: d["fields"]["document"] == document_dict["pk"],
+                        comments,
+                    ),
                 )
+                manifest_name.write_text(json.dumps(content, indent=2))
                 if manifest_name in self.files_in_export_dir:
                     self.files_in_export_dir.remove(manifest_name)