99
1010from s3file .storages import storage
1111
12- logger = logging .getLogger (' s3file' )
12+ logger = logging .getLogger (" s3file" )
1313
1414
1515class S3FileInputMixin :
1616 """FileInput that uses JavaScript to directly upload to Amazon S3."""
1717
1818 needs_multipart_form = False
19- upload_path = str (getattr (
20- settings , ' S3FILE_UPLOAD_PATH' , pathlib .PurePosixPath (' tmp' , ' s3file' )
21- ))
19+ upload_path = str (
20+ getattr ( settings , " S3FILE_UPLOAD_PATH" , pathlib .PurePosixPath (" tmp" , " s3file" ) )
21+ )
2222 upload_path = safe_join (str (storage .location ), upload_path )
2323 expires = settings .SESSION_COOKIE_AGE
2424
@@ -33,25 +33,24 @@ def client(self):
3333 def build_attrs (self , * args , ** kwargs ):
3434 attrs = super ().build_attrs (* args , ** kwargs )
3535
36- accept = attrs .get (' accept' )
36+ accept = attrs .get (" accept" )
3737 response = self .client .generate_presigned_post (
3838 self .bucket_name ,
39- str (pathlib .PurePosixPath (self .upload_folder , ' ${filename}' )),
39+ str (pathlib .PurePosixPath (self .upload_folder , " ${filename}" )),
4040 Conditions = self .get_conditions (accept ),
4141 ExpiresIn = self .expires ,
4242 )
4343
4444 defaults = {
45- 'data-fields-%s' % key : value
46- for key , value in response ['fields' ].items ()
45+ "data-fields-%s" % key : value for key , value in response ["fields" ].items ()
4746 }
48- defaults [' data-url' ] = response [' url' ]
47+ defaults [" data-url" ] = response [" url" ]
4948 defaults .update (attrs )
5049
5150 try :
52- defaults [' class' ] += ' s3file'
51+ defaults [" class" ] += " s3file"
5352 except KeyError :
54- defaults [' class' ] = ' s3file'
53+ defaults [" class" ] = " s3file"
5554 return defaults
5655
5756 def get_conditions (self , accept ):
@@ -60,9 +59,9 @@ def get_conditions(self, accept):
6059 ["starts-with" , "$key" , str (self .upload_folder )],
6160 {"success_action_status" : "201" },
6261 ]
63- if accept and ',' not in accept :
64- top_type , sub_type = accept .split ('/' , 1 )
65- if sub_type == '*' :
62+ if accept and "," not in accept :
63+ top_type , sub_type = accept .split ("/" , 1 )
64+ if sub_type == "*" :
6665 conditions .append (["starts-with" , "$Content-Type" , "%s/" % top_type ])
6766 else :
6867 conditions .append ({"Content-Type" : accept })
@@ -73,14 +72,14 @@ def get_conditions(self, accept):
7372
7473 @cached_property
7574 def upload_folder (self ):
76- return str (pathlib .PurePosixPath (
77- self .upload_path ,
78- base64 .urlsafe_b64encode (
79- uuid .uuid4 ().bytes
80- ).decode ('utf-8' ).rstrip ('=\n ' ),
81- )) # S3 uses POSIX paths
75+ return str (
76+ pathlib .PurePosixPath (
77+ self .upload_path ,
78+ base64 .urlsafe_b64encode (uuid .uuid4 ().bytes )
79+ .decode ("utf-8" )
80+ .rstrip ("=\n " ),
81+ )
82+ ) # S3 uses POSIX paths
8283
8384 class Media :
84- js = (
85- 's3file/js/s3file.js' if settings .DEBUG else 's3file/js/s3file.min.js' ,
86- )
85+ js = ("s3file/js/s3file.js" if settings .DEBUG else "s3file/js/s3file.min.js" ,)
0 commit comments