From ad77eaaa9edc631ea8391124163fff4c5103ca1d Mon Sep 17 00:00:00 2001 From: masterjo75 Date: Tue, 5 Mar 2024 15:43:00 +0100 Subject: [PATCH] Fix Code Formatting --- src/documents/file_handling.py | 57 +++++++++++++++++-------------- src/documents/serialisers.py | 46 ++++++++++++------------- src/documents/signals/handlers.py | 3 +- 3 files changed, 56 insertions(+), 50 deletions(-) diff --git a/src/documents/file_handling.py b/src/documents/file_handling.py index 2dce650a8..1de05fb43 100644 --- a/src/documents/file_handling.py +++ b/src/documents/file_handling.py @@ -8,9 +8,9 @@ from django.conf import settings from django.template.defaultfilters import slugify from django.utils import timezone -from documents.models import Document from documents.models import CustomField from documents.models import CustomFieldInstance +from documents.models import Document logger = logging.getLogger("paperless.filehandling") @@ -197,36 +197,41 @@ def generate_filename( local_added = timezone.localdate(doc.added) local_created = timezone.localdate(doc.created) placeholders = { - "title":pathvalidate.sanitize_filename(doc.title, replacement_text="-"), - "correspondent":correspondent, - "document_type":document_type, - "created":local_created.isoformat(), - "created_year":local_created.strftime("%Y"), - "created_year_short":local_created.strftime("%y"), - "created_month":local_created.strftime("%m"), - "created_month_name":local_created.strftime("%B"), - "created_month_name_short":local_created.strftime("%b"), - "created_day":local_created.strftime("%d"), - "added":local_added.isoformat(), - "added_year":local_added.strftime("%Y"), - "added_year_short":local_added.strftime("%y"), - "added_month":local_added.strftime("%m"), - "added_month_name":local_added.strftime("%B"), - "added_month_name_short":local_added.strftime("%b"), - "added_day":local_added.strftime("%d"), - "asn":asn, - "tags":tags, - "tag_list":tag_list, - "owner_username":owner_username_str, - "original_name":original_name, - "doc_pk":f"{doc.pk:07}", + "title": pathvalidate.sanitize_filename( + doc.title, + replacement_text="-", + ), + "correspondent": correspondent, + "document_type": document_type, + "created": local_created.isoformat(), + "created_year": local_created.strftime("%Y"), + "created_year_short": local_created.strftime("%y"), + "created_month": local_created.strftime("%m"), + "created_month_name": local_created.strftime("%B"), + "created_month_name_short": local_created.strftime("%b"), + "created_day": local_created.strftime("%d"), + "added": local_added.isoformat(), + "added_year": local_added.strftime("%Y"), + "added_year_short": local_added.strftime("%y"), + "added_month": local_added.strftime("%m"), + "added_month_name": local_added.strftime("%B"), + "added_month_name_short": local_added.strftime("%b"), + "added_day": local_added.strftime("%d"), + "asn": asn, + "tags": tags, + "tag_list": tag_list, + "owner_username": owner_username_str, + "original_name": original_name, + "doc_pk": f"{doc.pk:07}", } for field in CustomField.objects.all(): - placeholders['customfield' + f'{field.pk}'] = '-none-' + placeholders["customfield" + f"{field.pk}"] = no_value_default for field_instance in CustomFieldInstance.objects.filter(document=doc): - placeholders['customfield' + f'{field_instance.field.id}'] = field_instance.value + placeholders["customfield" + f"{field_instance.field.id}"] = ( + field_instance.value, + ) path = filename_format.format(**placeholders).strip() if settings.FILENAME_FORMAT_REMOVE_NONE: diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 08c7daee0..ed176d4f2 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -1149,31 +1149,31 @@ class StoragePathSerializer(MatchingModelSerializer, OwnedObjectSerializer): placeholders = { "title": "title", "correspondent": "correspondent", - "document_type":"document_type", - "created":"created", - "created_year":"created_year", - "created_year_short":"created_year_short", - "created_month":"created_month", - "created_month_name":"created_month_name", - "created_month_name_short":"created_month_name_short", - "created_day":"created_day", - "added":"added", - "added_year":"added_year", - "added_year_short":"added_year_short", - "added_month":"added_month", - "added_month_name":"added_month_name", - "added_month_name_short":"added_month_name_short", - "added_day":"added_day", - "asn":"asn", - "tags":"tags", - "tag_list":"tag_list", - "owner_username":"someone", - "original_name":"testfile", - "doc_pk":"doc_pk" - } + "document_type": "document_type", + "created": "created", + "created_year": "created_year", + "created_year_short": "created_year_short", + "created_month": "created_month", + "created_month_name": "created_month_name", + "created_month_name_short": "created_month_name_short", + "created_day": "created_day", + "added": "added", + "added_year": "added_year", + "added_year_short": "added_year_short", + "added_month": "added_month", + "added_month_name": "added_month_name", + "added_month_name_short": "added_month_name_short", + "added_day": "added_day", + "asn": "asn", + "tags": "tags", + "tag_list": "tag_list", + "owner_username": "someone", + "original_name": "testfile", + "doc_pk": "doc_pk", + } for field in CustomField.objects.all(): - placeholders['customfield' + f'{field.pk}'] = '-none-' + placeholders["customfield" + f"{field.pk}"] = "-none-" path.format(**placeholders) except KeyError as err: diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py index df63b1680..d65189059 100644 --- a/src/documents/signals/handlers.py +++ b/src/documents/signals/handlers.py @@ -381,7 +381,8 @@ def validate_move(instance, old_path, new_path): @receiver(models.signals.post_save, sender=CustomFieldInstance) def update_custom_field_instance(sender, instance: CustomFieldInstance, **kwargs): doc = Document.objects.get(pk=instance.document.pk) - update_filename_and_move_files(sender,doc) + update_filename_and_move_files(sender, doc) + @receiver(models.signals.m2m_changed, sender=Document.tags.through) @receiver(models.signals.post_save, sender=Document)