-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
432 additions
and
569 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default_app_config = 's3file.apps.S3FileConfig' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.apps import AppConfig | ||
|
||
try: | ||
from storages.backends.s3boto3 import S3Boto3Storage | ||
except ImportError: | ||
from storages.backends.s3boto import S3BotoStorage as S3BotoStorage | ||
|
||
|
||
class S3FileConfig(AppConfig): | ||
name = 's3file' | ||
verbose_name = 'S3File' | ||
|
||
def ready(self): | ||
from django.forms import FileField | ||
from django.core.files.storage import default_storage | ||
|
||
if isinstance(default_storage, S3Boto3Storage): | ||
from .forms import S3FileInput | ||
|
||
FileField.widget = S3FileInput |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
|
||
from django.core.files.storage import default_storage | ||
|
||
try: | ||
from django.utils.deprecation import MiddlewareMixin | ||
except ImportError: | ||
MiddlewareMixin = object | ||
|
||
|
||
class S3FileMiddleware(MiddlewareMixin): | ||
@staticmethod | ||
def get_files_from_storage(paths): | ||
"""Return S3 file where the name does not include the path.""" | ||
for path in paths: | ||
f = default_storage.open(path) | ||
f.name = os.path.basename(path) | ||
yield f | ||
|
||
def process_request(self, request): | ||
file_fields = request.POST.getlist('s3file', []) | ||
for field_name in file_fields: | ||
paths = request.POST.getlist(field_name, []) | ||
request.FILES.setlist(field_name, list(self.get_files_from_storage(paths))) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.