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

Fix encoding issue filefield #183

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 3 additions & 1 deletion binder/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import functools
from collections import defaultdict, namedtuple
from contextlib import ExitStack
from unidecode import unidecode

from PIL import Image
from inspect import getmro
Expand Down Expand Up @@ -2268,7 +2269,8 @@ def dispatch_file_field(self, request, pk=None, file_field=None):
raise BinderNotFound(file_field_name)

if 'download' in request.GET:
filename = self.filefield_get_name(instance=obj, request=request, file_field=file_field)
# unidecode in order to prevent weird utf-8 symbols from messing with our urls, causing issues
filename = unidecode(self.filefield_get_name(instance=obj, request=request, file_field=file_field))
if 'prefix' in request.GET:
filename = request.GET['prefix'] + ' - ' + filename
resp['Content-Disposition'] = 'attachment; filename="{}"'.format(filename)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'Pillow >= 3.2.0',
'django-request-id >= 1.0.0',
'requests >= 2.13.0',
'unidecode >= 1.2.0'
],
tests_require=[
'django-hijack >= 2.1.10',
Expand Down