2019-06-10 14:33:46 +02:00
|
|
|
import slugify
|
2018-03-25 15:40:37 +02:00
|
|
|
|
|
|
|
|
from django.core.files.storage import FileSystemStorage
|
2019-06-10 14:33:46 +02:00
|
|
|
from storages.backends.s3boto3 import S3Boto3Storage
|
2018-03-25 15:40:37 +02:00
|
|
|
|
|
|
|
|
|
2019-06-10 14:33:46 +02:00
|
|
|
def asciionly(name):
|
2018-03-25 15:40:37 +02:00
|
|
|
"""
|
|
|
|
|
Convert unicode characters in name to ASCII characters.
|
|
|
|
|
"""
|
2019-06-10 14:33:46 +02:00
|
|
|
return slugify.slugify(name, ok=slugify.SLUG_OK + ".", only_ascii=True)
|
2018-06-09 15:36:16 +02:00
|
|
|
|
2019-06-10 14:33:46 +02:00
|
|
|
|
|
|
|
|
class ASCIIFileSystemStorage(FileSystemStorage):
|
2018-03-25 15:40:37 +02:00
|
|
|
def get_valid_name(self, name):
|
2019-06-10 14:33:46 +02:00
|
|
|
return super().get_valid_name(asciionly(name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ASCIIS3Boto3Storage(S3Boto3Storage):
|
|
|
|
|
def get_valid_name(self, name):
|
|
|
|
|
return super().get_valid_name(asciionly(name))
|