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.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:

View File

@ -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:

View File

@ -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)