Return select field option text not ID
This commit is contained in:
parent
dc25d53af4
commit
0af1a32c48
@ -261,6 +261,15 @@ def get_custom_fields_context(
|
|||||||
field_instance.value,
|
field_instance.value,
|
||||||
replacement_text="-",
|
replacement_text="-",
|
||||||
)
|
)
|
||||||
|
elif (
|
||||||
|
field_instance.field.data_type == CustomField.FieldDataType.SELECT
|
||||||
|
and field_instance.field.extra_data["select_options"] is not None
|
||||||
|
):
|
||||||
|
options = field_instance.field.extra_data["select_options"]
|
||||||
|
value = pathvalidate.sanitize_filename(
|
||||||
|
options[int(field_instance.value)],
|
||||||
|
replacement_text="-",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
value = field_instance.value
|
value = field_instance.value
|
||||||
field_data["custom_fields"][
|
field_data["custom_fields"][
|
||||||
|
@ -1266,6 +1266,18 @@ class TestFilenameGeneration(DirectoriesMixin, TestCase):
|
|||||||
value_int=1234,
|
value_int=1234,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cf2 = CustomField.objects.create(
|
||||||
|
name="Select Field",
|
||||||
|
data_type=CustomField.FieldDataType.SELECT,
|
||||||
|
extra_data={"select_options": ["ChoiceOne", "ChoiceTwo"]},
|
||||||
|
)
|
||||||
|
|
||||||
|
CustomFieldInstance.objects.create(
|
||||||
|
document=doc_a,
|
||||||
|
field=cf2,
|
||||||
|
value_select=0,
|
||||||
|
)
|
||||||
|
|
||||||
with override_settings(
|
with override_settings(
|
||||||
FILENAME_FORMAT="""
|
FILENAME_FORMAT="""
|
||||||
{% if "Invoice" in custom_fields %}
|
{% if "Invoice" in custom_fields %}
|
||||||
@ -1280,6 +1292,20 @@ class TestFilenameGeneration(DirectoriesMixin, TestCase):
|
|||||||
"invoices/1234.pdf",
|
"invoices/1234.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
with override_settings(
|
||||||
|
FILENAME_FORMAT="""
|
||||||
|
{% if "Select Field" in custom_fields %}
|
||||||
|
{{ title }}_{{ custom_fields|get_cf_value:'Select Field' }}
|
||||||
|
{% else %}
|
||||||
|
{{ title }}
|
||||||
|
{% endif %}
|
||||||
|
""",
|
||||||
|
):
|
||||||
|
self.assertEqual(
|
||||||
|
generate_filename(doc_a),
|
||||||
|
"Some Title_ChoiceOne.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