16 lines
496 B
Python
16 lines
496 B
Python
from pathlib import PurePosixPath
|
|
|
|
from django.urls import reverse
|
|
|
|
|
|
def attachment_download_url(obj, request=None):
|
|
"""Never expose a storage URL: the download rechecks the request's ACL."""
|
|
if not obj.attachment:
|
|
return None
|
|
url = reverse("api:v1:request-attachment-download", kwargs={"pk": obj.pk})
|
|
return request.build_absolute_uri(url) if request else url
|
|
|
|
|
|
def attachment_filename(obj):
|
|
return PurePosixPath(obj.attachment.name).name if obj.attachment else None
|