diff --git a/nextgisweb/feature_attachment/api.py b/nextgisweb/feature_attachment/api.py index ff1e489b92..88cba6ddc9 100644 --- a/nextgisweb/feature_attachment/api.py +++ b/nextgisweb/feature_attachment/api.py @@ -1,7 +1,7 @@ -import mimetypes import re from io import BytesIO from itertools import count +from mimetypes import guess_extension from tempfile import NamedTemporaryFile from typing import List, Optional from urllib.parse import quote_plus @@ -83,7 +83,7 @@ def download( fobj = FileObj.filter_by(id=fileobj_id).one() response = UnsafeFileResponse(fobj.filename(), content_type=mime_type, request=request) if name is None: - name = "" + name = f"unnamed{aid}{guess_extension(mime_type) or '.bin'}" response.content_disposition = f"filename*=utf-8''{quote_plus(name)}" return response @@ -191,7 +191,7 @@ def export(resource, request): name = obj.name if name is None or name.strip() == "": - extension = mimetypes.guess_extension(obj.mime_type) + extension = guess_extension(obj.mime_type) or ".bin" name = f"{att_idx:010d}{extension}" if name in feature_anames: diff --git a/nextgisweb/feature_attachment/locale/ru.po b/nextgisweb/feature_attachment/locale/ru.po index 07defc0c77..82bb025ccb 100644 --- a/nextgisweb/feature_attachment/locale/ru.po +++ b/nextgisweb/feature_attachment/locale/ru.po @@ -52,12 +52,12 @@ msgid "File name" msgstr "Имя файла" #: nodepkg/attachment-editor/AttachmentEditor.tsx:172 -#: nodepkg/attachment-table/AttachmentTable.tsx:66 +#: nodepkg/attachment-table/AttachmentTable.tsx:63 msgid "Size" msgstr "Размер" #: nodepkg/attachment-editor/AttachmentEditor.tsx:178 -#: nodepkg/attachment-table/AttachmentTable.tsx:81 +#: nodepkg/attachment-table/AttachmentTable.tsx:78 msgid "Description" msgstr "Описание" @@ -120,11 +120,11 @@ msgstr "Экспорт" msgid "Import" msgstr "Импорт" -#: nodepkg/attachment-table/AttachmentTable.tsx:48 -msgid "Empty filename" -msgstr "Пустое имя файла" +#: nodepkg/attachment-table/AttachmentTable.tsx:55 +msgid "Unnamed" +msgstr "Безымянный" -#: nodepkg/attachment-table/AttachmentTable.tsx:75 +#: nodepkg/attachment-table/AttachmentTable.tsx:72 msgid "MIME type" msgstr "Тип MIME" diff --git a/nextgisweb/feature_attachment/nodepkg/attachment-table/AttachmentTable.tsx b/nextgisweb/feature_attachment/nodepkg/attachment-table/AttachmentTable.tsx index a33c43bc62..e623ea2c73 100644 --- a/nextgisweb/feature_attachment/nodepkg/attachment-table/AttachmentTable.tsx +++ b/nextgisweb/feature_attachment/nodepkg/attachment-table/AttachmentTable.tsx @@ -44,9 +44,6 @@ export function AttachmentTable({ className: "name", title: gettext("File name"), render: (name: string, attachment: FeatureAttachment) => { - if (!name) { - name = "<" + gettext("Empty filename") + ">"; - } const href = routeURL("feature_attachment.download", { id: resourceId, fid: featureId, @@ -54,8 +51,8 @@ export function AttachmentTable({ }); return ( - - {name} + + {name || {gettext("Unnamed")}} ); }, @@ -123,6 +120,7 @@ export function AttachmentTable({ showHeader={!isSmall} size="small" tableLayout="auto" + bordered /> )}