Fix Code Formatting

This commit is contained in:
masterjo75 2024-03-05 15:43:00 +01:00
parent 4f398c8e6f
commit ad77eaaa9e
3 changed files with 56 additions and 50 deletions

View File

@ -8,9 +8,9 @@ from django.conf import settings
from django.template.defaultfilters import slugify from django.template.defaultfilters import slugify
from django.utils import timezone from django.utils import timezone
from documents.models import Document
from documents.models import CustomField from documents.models import CustomField
from documents.models import CustomFieldInstance from documents.models import CustomFieldInstance
from documents.models import Document
logger = logging.getLogger("paperless.filehandling") logger = logging.getLogger("paperless.filehandling")
@ -197,36 +197,41 @@ def generate_filename(
local_added = timezone.localdate(doc.added) local_added = timezone.localdate(doc.added)
local_created = timezone.localdate(doc.created) local_created = timezone.localdate(doc.created)
placeholders = { placeholders = {
"title":pathvalidate.sanitize_filename(doc.title, replacement_text="-"), "title": pathvalidate.sanitize_filename(
"correspondent":correspondent, doc.title,
"document_type":document_type, replacement_text="-",
"created":local_created.isoformat(), ),
"created_year":local_created.strftime("%Y"), "correspondent": correspondent,
"created_year_short":local_created.strftime("%y"), "document_type": document_type,
"created_month":local_created.strftime("%m"), "created": local_created.isoformat(),
"created_month_name":local_created.strftime("%B"), "created_year": local_created.strftime("%Y"),
"created_month_name_short":local_created.strftime("%b"), "created_year_short": local_created.strftime("%y"),
"created_day":local_created.strftime("%d"), "created_month": local_created.strftime("%m"),
"added":local_added.isoformat(), "created_month_name": local_created.strftime("%B"),
"added_year":local_added.strftime("%Y"), "created_month_name_short": local_created.strftime("%b"),
"added_year_short":local_added.strftime("%y"), "created_day": local_created.strftime("%d"),
"added_month":local_added.strftime("%m"), "added": local_added.isoformat(),
"added_month_name":local_added.strftime("%B"), "added_year": local_added.strftime("%Y"),
"added_month_name_short":local_added.strftime("%b"), "added_year_short": local_added.strftime("%y"),
"added_day":local_added.strftime("%d"), "added_month": local_added.strftime("%m"),
"asn":asn, "added_month_name": local_added.strftime("%B"),
"tags":tags, "added_month_name_short": local_added.strftime("%b"),
"tag_list":tag_list, "added_day": local_added.strftime("%d"),
"owner_username":owner_username_str, "asn": asn,
"original_name":original_name, "tags": tags,
"doc_pk":f"{doc.pk:07}", "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(): 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): 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() path = filename_format.format(**placeholders).strip()
if settings.FILENAME_FORMAT_REMOVE_NONE: if settings.FILENAME_FORMAT_REMOVE_NONE:

View File

@ -1149,31 +1149,31 @@ class StoragePathSerializer(MatchingModelSerializer, OwnedObjectSerializer):
placeholders = { placeholders = {
"title": "title", "title": "title",
"correspondent": "correspondent", "correspondent": "correspondent",
"document_type":"document_type", "document_type": "document_type",
"created":"created", "created": "created",
"created_year":"created_year", "created_year": "created_year",
"created_year_short":"created_year_short", "created_year_short": "created_year_short",
"created_month":"created_month", "created_month": "created_month",
"created_month_name":"created_month_name", "created_month_name": "created_month_name",
"created_month_name_short":"created_month_name_short", "created_month_name_short": "created_month_name_short",
"created_day":"created_day", "created_day": "created_day",
"added":"added", "added": "added",
"added_year":"added_year", "added_year": "added_year",
"added_year_short":"added_year_short", "added_year_short": "added_year_short",
"added_month":"added_month", "added_month": "added_month",
"added_month_name":"added_month_name", "added_month_name": "added_month_name",
"added_month_name_short":"added_month_name_short", "added_month_name_short": "added_month_name_short",
"added_day":"added_day", "added_day": "added_day",
"asn":"asn", "asn": "asn",
"tags":"tags", "tags": "tags",
"tag_list":"tag_list", "tag_list": "tag_list",
"owner_username":"someone", "owner_username": "someone",
"original_name":"testfile", "original_name": "testfile",
"doc_pk":"doc_pk" "doc_pk": "doc_pk",
} }
for field in CustomField.objects.all(): for field in CustomField.objects.all():
placeholders['customfield' + f'{field.pk}'] = '-none-' placeholders["customfield" + f"{field.pk}"] = "-none-"
path.format(**placeholders) path.format(**placeholders)
except KeyError as err: except KeyError as err:

View File

@ -381,7 +381,8 @@ def validate_move(instance, old_path, new_path):
@receiver(models.signals.post_save, sender=CustomFieldInstance) @receiver(models.signals.post_save, sender=CustomFieldInstance)
def update_custom_field_instance(sender, instance: CustomFieldInstance, **kwargs): def update_custom_field_instance(sender, instance: CustomFieldInstance, **kwargs):
doc = Document.objects.get(pk=instance.document.pk) 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.m2m_changed, sender=Document.tags.through)
@receiver(models.signals.post_save, sender=Document) @receiver(models.signals.post_save, sender=Document)