mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-19 10:19:27 -05:00
Merge branch 'dev' into beta
This commit is contained in:
commit
7098ec9bf5
@ -364,9 +364,17 @@ class CannotMoveFilesException(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(models.signals.post_save, sender=CustomFieldInstance)
|
||||||
@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)
|
||||||
def update_filename_and_move_files(sender, instance: Document, **kwargs):
|
def update_filename_and_move_files(
|
||||||
|
sender,
|
||||||
|
instance: Document | CustomFieldInstance,
|
||||||
|
**kwargs,
|
||||||
|
):
|
||||||
|
if isinstance(instance, CustomFieldInstance):
|
||||||
|
instance = instance.document
|
||||||
|
|
||||||
def validate_move(instance, old_path, new_path):
|
def validate_move(instance, old_path, new_path):
|
||||||
if not os.path.isfile(old_path):
|
if not os.path.isfile(old_path):
|
||||||
# Can't do anything if the old file does not exist anymore.
|
# Can't do anything if the old file does not exist anymore.
|
||||||
|
@ -82,7 +82,7 @@ def get_cf_value(
|
|||||||
name: str,
|
name: str,
|
||||||
default: str | None = None,
|
default: str | None = None,
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
if name in custom_field_data:
|
if name in custom_field_data and custom_field_data[name]["value"] is not None:
|
||||||
return custom_field_data[name]["value"]
|
return custom_field_data[name]["value"]
|
||||||
elif default is not None:
|
elif default is not None:
|
||||||
return default
|
return default
|
||||||
@ -235,8 +235,10 @@ def get_custom_fields_context(
|
|||||||
field_instance.field.data_type,
|
field_instance.field.data_type,
|
||||||
replacement_text="-",
|
replacement_text="-",
|
||||||
)
|
)
|
||||||
|
if field_instance.value is None:
|
||||||
|
value = None
|
||||||
# String types need to be sanitized
|
# String types need to be sanitized
|
||||||
if field_instance.field.data_type in {
|
elif field_instance.field.data_type in {
|
||||||
CustomField.FieldDataType.MONETARY,
|
CustomField.FieldDataType.MONETARY,
|
||||||
CustomField.FieldDataType.STRING,
|
CustomField.FieldDataType.STRING,
|
||||||
CustomField.FieldDataType.URL,
|
CustomField.FieldDataType.URL,
|
||||||
|
@ -1322,7 +1322,7 @@ class TestFilenameGeneration(DirectoriesMixin, TestCase):
|
|||||||
extra_data={"select_options": ["ChoiceOne", "ChoiceTwo"]},
|
extra_data={"select_options": ["ChoiceOne", "ChoiceTwo"]},
|
||||||
)
|
)
|
||||||
|
|
||||||
CustomFieldInstance.objects.create(
|
cfi1 = CustomFieldInstance.objects.create(
|
||||||
document=doc_a,
|
document=doc_a,
|
||||||
field=cf2,
|
field=cf2,
|
||||||
value_select=0,
|
value_select=0,
|
||||||
@ -1351,7 +1351,7 @@ class TestFilenameGeneration(DirectoriesMixin, TestCase):
|
|||||||
with override_settings(
|
with override_settings(
|
||||||
FILENAME_FORMAT="""
|
FILENAME_FORMAT="""
|
||||||
{% if "Select Field" in custom_fields %}
|
{% if "Select Field" in custom_fields %}
|
||||||
{{ title }}_{{ custom_fields | get_cf_value('Select Field') }}
|
{{ title }}_{{ custom_fields | get_cf_value('Select Field', 'Default Value') }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ title }}
|
{{ title }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -1362,6 +1362,15 @@ class TestFilenameGeneration(DirectoriesMixin, TestCase):
|
|||||||
"Some Title_ChoiceOne.pdf",
|
"Some Title_ChoiceOne.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Check for handling Nones well
|
||||||
|
cfi1.value_select = None
|
||||||
|
cfi1.save()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
generate_filename(doc_a),
|
||||||
|
"Some Title_Default Value.pdf",
|
||||||
|
)
|
||||||
|
|
||||||
cf.name = "Invoice Number"
|
cf.name = "Invoice Number"
|
||||||
cfi.value_int = 4567
|
cfi.value_int = 4567
|
||||||
cfi.save()
|
cfi.save()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user