Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Django Private Storage
Commits
e51a3fb9
Unverified
Commit
e51a3fb9
authored
May 17, 2021
by
Diederik van der Boor
Browse files
Drop Python 2 support and Django 1.8/1.9 support
parent
40400755
Changes
5
Hide whitespace changes
Inline
Side-by-side
private_storage/fields.py
View file @
e51a3fb9
#-*- coding: utf-8 -*-
from
__future__
import
unicode_literals
import
datetime
import
logging
import
os
...
...
@@ -23,12 +21,6 @@ from .storage import private_storage
logger
=
logging
.
getLogger
(
__name__
)
try
:
string_types
=
basestring
,
# Python 2
except
NameError
:
string_types
=
str
,
# Python 3
class
PrivateFileField
(
models
.
FileField
):
"""
Filefield with private storage, custom filename and size checks.
...
...
@@ -90,7 +82,7 @@ class PrivateFileField(models.FileField):
extra_dirs
=
upload_subfolder
(
instance
)
# Avoid mistakes by developers, no "s/u/b/p/a/t/h/"
if
isinstance
(
extra_dirs
,
str
ing_types
):
if
isinstance
(
extra_dirs
,
str
):
warnings
.
warn
(
"{}.{}.upload_subfolder should return a list"
" to avoid path-separator issues."
.
format
(
instance
.
__class__
.
__name__
,
self
.
name
),
UserWarning
)
...
...
private_storage/servers.py
View file @
e51a3fb9
...
...
@@ -4,7 +4,8 @@ Sending files efficiently for different kind of webservers.
import
os
import
sys
import
time
from
functools
import
wraps
from
functools
import
lru_cache
,
wraps
from
urllib.parse
import
quote
from
django.conf
import
settings
from
django.core.exceptions
import
ImproperlyConfigured
...
...
@@ -13,15 +14,6 @@ from django.utils.http import http_date
from
django.utils.module_loading
import
import_string
from
django.views.static
import
serve
,
was_modified_since
try
:
# python 3
from
urllib.parse
import
quote
from
functools
import
lru_cache
# Python 3
except
ImportError
:
# python 2
from
urllib
import
quote
from
django.utils.lru_cache
import
lru_cache
# Django <3
@
lru_cache
()
def
get_server_class
(
path
):
...
...
private_storage/storage/files.py
View file @
e51a3fb9
...
...
@@ -2,16 +2,12 @@
Django Storage interface, using the file system backend.
"""
from
django.core.files.storage
import
FileSystemStorage
from
django.urls
import
reverse_lazy
from
django.utils.deconstruct
import
deconstructible
from
django.utils.encoding
import
force_text
from
private_storage
import
appconfig
try
:
from
django.urls
import
reverse_lazy
# Added in Django 1.10
except
ImportError
:
from
django.core.urlresolvers
import
reverse_lazy
@
deconstructible
class
PrivateFileSystemStorage
(
FileSystemStorage
):
...
...
private_storage/views.py
View file @
e51a3fb9
...
...
@@ -2,6 +2,7 @@
Views to send private files.
"""
import
os
from
urllib.parse
import
quote
from
django.http
import
Http404
from
django.utils.module_loading
import
import_string
...
...
@@ -14,11 +15,6 @@ from .models import PrivateFile
from
.servers
import
get_server_class
from
.storage
import
private_storage
try
:
from
urllib.parse
import
quote
except
ImportError
:
from
urllib
import
quote
# Python 2
class
PrivateStorageView
(
View
):
"""
...
...
runtests.py
View file @
e51a3fb9
...
...
@@ -41,6 +41,7 @@ if not settings.configured:
},
},
],
DEFAULT_AUTO_FIELD
=
'django.db.models.BigAutoField'
,
AWS_PRIVATE_STORAGE_BUCKET_NAME
=
'foobar'
,
PRIVATE_STORAGE_ROOT
=
path
.
join
(
module_root
,
'test-media-root'
),
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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