Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hub
ViralHostRangeDB
Commits
a4f043ae
Commit
a4f043ae
authored
Sep 30, 2019
by
Bryan BRANCOTTE
Browse files
Attempt to solve encoding issue on filename of
#102
parent
50821bf1
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/viralhostrange/viralhostrangedb/views.py
View file @
a4f043ae
...
...
@@ -2,6 +2,7 @@ import itertools
import
json
import
os
import
tempfile
import
unicodedata
import
pandas
as
pd
from
basetheme_bootstrap.user_preferences
import
get_user_preferences_for_user
...
...
@@ -842,6 +843,17 @@ def data_source_download(request, pk):
return
response
# http://source.mihelac.org/2011/02/6/rename-uploaded-files-ascii-character-set-django/
class
ASCIIFileSystemStorage
(
storage
.
FileSystemStorage
):
"""
Convert unicode characters in name to ASCII characters.
"""
def
get_valid_name
(
self
,
name
):
name
=
unicodedata
.
normalize
(
'NFKD'
,
name
).
encode
(
'ascii'
,
'ignore'
)
return
super
(
ASCIIFileSystemStorage
,
self
).
get_valid_name
(
name
)
@
method_decorator
(
login_required
,
name
=
'dispatch'
)
class
DataSourceWizard
(
wizard_views
.
NamedUrlSessionWizardView
):
def
get_upload_or_live_input
(
self
):
...
...
@@ -874,7 +886,7 @@ class DataSourceWizard(wizard_views.NamedUrlSessionWizardView):
"Upload"
:
upload_data
,
}
template_name
=
'viralhostrangedb/wizard_form.html'
file_storage
=
storage
.
FileSystemStorage
(
location
=
os
.
path
.
join
(
tempfile
.
gettempdir
(),
'viralhostrangedb_wizard'
))
file_storage
=
ASCII
FileSystemStorage
(
location
=
os
.
path
.
join
(
tempfile
.
gettempdir
(),
'viralhostrangedb_wizard'
))
def
get_context_data
(
self
,
form
,
step
=
None
,
**
kwargs
):
context
=
super
().
get_context_data
(
form
=
form
,
step
=
step
,
**
kwargs
)
...
...
Bryan BRANCOTTE
@bbrancot
mentioned in commit
ad03a318
·
Sep 30, 2019
mentioned in commit
ad03a318
mentioned in commit ad03a3183d53cce5e5674d336e5d148698a13026
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment