Simplifies the validation

This commit is contained in:
Trenton H 2024-10-01 13:50:01 -07:00
parent 0f26114ca0
commit 507909bfd8

View File

@ -33,6 +33,7 @@ if settings.AUDIT_LOG_ENABLED:
from documents import bulk_edit from documents import bulk_edit
from documents.data_models import DocumentSource from documents.data_models import DocumentSource
from documents.file_handling import validate_template_and_render
from documents.models import Correspondent from documents.models import Correspondent
from documents.models import CustomField from documents.models import CustomField
from documents.models import CustomFieldInstance from documents.models import CustomFieldInstance
@ -1479,36 +1480,11 @@ class StoragePathSerializer(MatchingModelSerializer, OwnedObjectSerializer):
"set_permissions", "set_permissions",
) )
def validate_path(self, path): def validate_path(self, path: str):
try: result = validate_template_and_render(path)
path.format(
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",
)
except KeyError as err: if result is None:
raise serializers.ValidationError(_("Invalid variable detected.")) from err raise serializers.ValidationError(_("Invalid variable detected."))
return path return path