mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-21 10:29:29 -05:00
Simplify this
This commit is contained in:
parent
dcf40ba5eb
commit
45884989ed
src/documents
@ -181,22 +181,25 @@ def modify_custom_fields(
|
||||
if custom_field.data_type == CustomField.FieldDataType.DOCUMENTLINK:
|
||||
doc = Document.objects.get(id=doc_id)
|
||||
reflect_doclinks(doc, custom_field, value)
|
||||
remove_fields = CustomField.objects.filter(id__in=remove_custom_fields).distinct()
|
||||
for remove_field in remove_fields:
|
||||
if remove_field.data_type == CustomField.FieldDataType.DOCUMENTLINK:
|
||||
# Remove symmetrical links from target documents
|
||||
for doc_id in affected_docs:
|
||||
target_doc_instance = CustomFieldInstance.objects.filter(
|
||||
document_id=doc_id,
|
||||
field=remove_field,
|
||||
).first()
|
||||
if target_doc_instance and target_doc_instance.value:
|
||||
for target_doc_id in target_doc_instance.value:
|
||||
remove_doclink(
|
||||
document=Document.objects.get(id=doc_id),
|
||||
field=remove_field,
|
||||
target_doc_id=target_doc_id,
|
||||
)
|
||||
|
||||
# For doc link fields that are being removed, remove symmetrical links
|
||||
for doclink_field in CustomField.objects.filter(
|
||||
id__in=remove_custom_fields,
|
||||
data_type=CustomField.FieldDataType.DOCUMENTLINK,
|
||||
).distinct():
|
||||
for target_doc_instance in CustomFieldInstance.objects.filter(
|
||||
document_id__in=affected_docs,
|
||||
field=doclink_field,
|
||||
value_document_ids__isnull=False,
|
||||
):
|
||||
for target_doc_id in target_doc_instance.value:
|
||||
remove_doclink(
|
||||
document=Document.objects.get(id=target_doc_instance.document.id),
|
||||
field=doclink_field,
|
||||
target_doc_id=target_doc_id,
|
||||
)
|
||||
|
||||
# Finally, remove the custom fields
|
||||
CustomFieldInstance.objects.filter(
|
||||
document_id__in=affected_docs,
|
||||
field_id__in=remove_custom_fields,
|
||||
|
@ -312,7 +312,6 @@ class TestBulkEdit(DirectoriesMixin, TestCase):
|
||||
[self.doc3.id],
|
||||
)
|
||||
# assert reflect document link
|
||||
self.doc3.refresh_from_db()
|
||||
self.assertEqual(
|
||||
self.doc3.custom_fields.first().value,
|
||||
[self.doc2.id, self.doc1.id],
|
||||
@ -328,7 +327,6 @@ class TestBulkEdit(DirectoriesMixin, TestCase):
|
||||
add_custom_fields={},
|
||||
remove_custom_fields=[cf3.id],
|
||||
)
|
||||
self.doc1.refresh_from_db()
|
||||
self.assertNotIn(
|
||||
self.doc3.id,
|
||||
self.doc1.custom_fields.filter(field=cf3).first().value,
|
||||
|
Loading…
x
Reference in New Issue
Block a user