mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Fixes export of custom field instances during a split manifest export (#4984)
This commit is contained in:
parent
92a920021d
commit
be2de4f15d
@ -238,18 +238,6 @@ class Command(BaseCommand):
|
|||||||
serializers.serialize("json", StoragePath.objects.all()),
|
serializers.serialize("json", StoragePath.objects.all()),
|
||||||
)
|
)
|
||||||
|
|
||||||
notes = json.loads(
|
|
||||||
serializers.serialize("json", Note.objects.all()),
|
|
||||||
)
|
|
||||||
if not self.split_manifest:
|
|
||||||
manifest += notes
|
|
||||||
|
|
||||||
documents = Document.objects.order_by("id")
|
|
||||||
document_map = {d.pk: d for d in documents}
|
|
||||||
document_manifest = json.loads(serializers.serialize("json", documents))
|
|
||||||
if not self.split_manifest:
|
|
||||||
manifest += document_manifest
|
|
||||||
|
|
||||||
manifest += json.loads(
|
manifest += json.loads(
|
||||||
serializers.serialize("json", MailAccount.objects.all()),
|
serializers.serialize("json", MailAccount.objects.all()),
|
||||||
)
|
)
|
||||||
@ -303,10 +291,24 @@ class Command(BaseCommand):
|
|||||||
serializers.serialize("json", CustomField.objects.all()),
|
serializers.serialize("json", CustomField.objects.all()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# These are treated specially and included in the per-document manifest
|
||||||
|
# if that setting is enabled. Otherwise, they are just exported to the bulk
|
||||||
|
# manifest
|
||||||
|
documents = Document.objects.order_by("id")
|
||||||
|
document_map: dict[int, Document] = {d.pk: d for d in documents}
|
||||||
|
document_manifest = json.loads(serializers.serialize("json", documents))
|
||||||
|
|
||||||
|
notes = json.loads(
|
||||||
|
serializers.serialize("json", Note.objects.all()),
|
||||||
|
)
|
||||||
|
|
||||||
|
custom_field_instances = json.loads(
|
||||||
|
serializers.serialize("json", CustomFieldInstance.objects.all()),
|
||||||
|
)
|
||||||
if not self.split_manifest:
|
if not self.split_manifest:
|
||||||
manifest += json.loads(
|
manifest += document_manifest
|
||||||
serializers.serialize("json", CustomFieldInstance.objects.all()),
|
manifest += notes
|
||||||
)
|
manifest += custom_field_instances
|
||||||
|
|
||||||
# 3. Export files from each document
|
# 3. Export files from each document
|
||||||
for index, document_dict in tqdm.tqdm(
|
for index, document_dict in tqdm.tqdm(
|
||||||
@ -412,6 +414,12 @@ class Command(BaseCommand):
|
|||||||
notes,
|
notes,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
content += list(
|
||||||
|
filter(
|
||||||
|
lambda d: d["fields"]["document"] == document_dict["pk"],
|
||||||
|
custom_field_instances,
|
||||||
|
),
|
||||||
|
)
|
||||||
manifest_name.write_text(
|
manifest_name.write_text(
|
||||||
json.dumps(content, indent=2, ensure_ascii=False),
|
json.dumps(content, indent=2, ensure_ascii=False),
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
|
@ -646,10 +646,13 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
|
|
||||||
with paperless_environment():
|
with paperless_environment():
|
||||||
self.assertEqual(Document.objects.count(), 4)
|
self.assertEqual(Document.objects.count(), 4)
|
||||||
|
self.assertEqual(CustomFieldInstance.objects.count(), 1)
|
||||||
Document.objects.all().delete()
|
Document.objects.all().delete()
|
||||||
|
CustomFieldInstance.objects.all().delete()
|
||||||
self.assertEqual(Document.objects.count(), 0)
|
self.assertEqual(Document.objects.count(), 0)
|
||||||
call_command("document_importer", "--no-progress-bar", self.target)
|
call_command("document_importer", "--no-progress-bar", self.target)
|
||||||
self.assertEqual(Document.objects.count(), 4)
|
self.assertEqual(Document.objects.count(), 4)
|
||||||
|
self.assertEqual(CustomFieldInstance.objects.count(), 1)
|
||||||
|
|
||||||
def test_folder_prefix(self):
|
def test_folder_prefix(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user