Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature attachments with null values as filenames #787

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion nextgisweb/feature_attachment/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Expand Down Expand Up @@ -81,6 +82,8 @@ 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 = f"unnamed{aid}{guess_extension(mime_type) or '.bin'}"
response.content_disposition = f"filename*=utf-8''{quote_plus(name)}"
return response

Expand Down Expand Up @@ -188,7 +191,8 @@ def export(resource, request):

name = obj.name
if name is None or name.strip() == "":
name = f"{att_idx:010d}"
extension = guess_extension(obj.mime_type) or ".bin"
name = f"{att_idx:010d}{extension}"

if name in feature_anames:
# Make attachment's name unique
Expand Down
14 changes: 9 additions & 5 deletions nextgisweb/feature_attachment/locale/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ msgstr "Экспорт"
msgid "Import"
msgstr "Импорт"

#: nodepkg/attachment-table/AttachmentTable.tsx:55
msgid "Unnamed"
msgstr "Безымянный"

#: nodepkg/attachment-table/AttachmentTable.tsx:72
msgid "MIME type"
msgstr "Тип MIME"
Expand All @@ -144,23 +148,23 @@ msgstr "Некорректный идентификатор объекта дл
msgid "Invalid keyname for file '{}'."
msgstr "Некорректный ключ для файла '{}'."

#: util.py:74
#: util.py:75
msgid "Invalid name for file '{}'."
msgstr "Некорректное имя для файла '{}'."

#: util.py:80
#: util.py:82
msgid "Invalid MIME type for file '{}'."
msgstr "Некорректный MIME-тип для файла '{}'."

#: util.py:87
#: util.py:89
msgid "Invalid description for file '{}'."
msgstr "Некорректное описание для файла '{}'."

#: util.py:100
#: util.py:102
msgid "Could not determine feature ID for file '{}'."
msgstr "Не удалось определить идентификатор объекта для файла '{}'."

#: util.py:118
#: util.py:122
msgid "File '{}' isn't found in the archive."
msgstr "Файл '{}' не найден в архиве."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export function AttachmentTable({
});

return (
<a href={href} target="_blank" rel="noreferrer">
{name}
<a href={href} target="_blank">
{name || <i>{gettext("Unnamed")}</i>}
</a>
);
},
Expand Down Expand Up @@ -120,6 +120,7 @@ export function AttachmentTable({
showHeader={!isSmall}
size="small"
tableLayout="auto"
bordered
/>
)}
</div>
Expand Down