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
d4c0c7bd
Unverified
Commit
d4c0c7bd
authored
May 15, 2023
by
Diederik van der Boor
Browse files
Updates by django-upgrade, removes if django.VERSION >= (1, 10) checks
parent
0920f2bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
private_storage/fields.py
View file @
d4c0c7bd
...
...
@@ -4,7 +4,6 @@ import os
import
posixpath
import
warnings
import
django
from
django.core
import
checks
from
django.core.exceptions
import
ValidationError
from
django.core.files.uploadedfile
import
UploadedFile
...
...
@@ -90,11 +89,8 @@ class PrivateFileField(models.FileField):
path_parts
.
extend
([
self
.
storage
.
get_valid_name
(
dir
)
for
dir
in
extra_dirs
])
path_parts
.
append
(
self
.
_get_clean_filename
(
filename
))
if
django
.
VERSION
>=
(
1
,
10
):
filename
=
posixpath
.
join
(
*
path_parts
)
return
self
.
storage
.
generate_filename
(
filename
)
else
:
return
os
.
path
.
join
(
*
path_parts
)
filename
=
posixpath
.
join
(
*
path_parts
)
return
self
.
storage
.
generate_filename
(
filename
)
def
_get_clean_filename
(
self
,
filename
):
# As of Django 1.10+, file names are no longer cleaned locally, but cleaned by the storage.
...
...
private_storage/permissions.py
View file @
d4c0c7bd
"""
Possible functions for the ``PRIVATE_STORAGE_AUTH_FUNCTION`` setting.
"""
import
django
if
django
.
VERSION
>=
(
1
,
10
):
def
allow_authenticated
(
private_file
):
return
private_file
.
request
.
user
.
is_authenticated
def
allow_staff
(
private_file
):
request
=
private_file
.
request
return
request
.
user
.
is_authenticated
and
request
.
user
.
is_staff
def
allow_authenticated
(
private_file
):
return
private_file
.
request
.
user
.
is_authenticated
def
allow_superuser
(
private_file
):
request
=
private_file
.
request
return
request
.
user
.
is_authenticated
and
request
.
user
.
is_superuser
else
:
def
allow_authenticated
(
private_file
):
return
private_file
.
request
.
user
.
is_authenticated
()
def
allow_staff
(
private_file
):
request
=
private_file
.
request
return
request
.
user
.
is_authenticated
()
and
request
.
user
.
is_staff
def
allow_staff
(
private_file
):
request
=
private_file
.
request
return
request
.
user
.
is_authenticated
and
request
.
user
.
is_staff
def
allow_superuser
(
private_file
):
request
=
private_file
.
request
return
request
.
user
.
is_authenticated
()
and
request
.
user
.
is_superuser
def
allow_superuser
(
private_file
):
request
=
private_file
.
request
return
request
.
user
.
is_authenticated
and
request
.
user
.
is_superuser
private_storage/views.py
View file @
d4c0c7bd
...
...
@@ -122,7 +122,7 @@ class PrivateStorageView(View):
The filename, encoded to use in a ``Content-Disposition`` header.
"""
# Based on https://www.djangosnippets.org/snippets/1710/
user_agent
=
self
.
request
.
META
.
get
(
'HTTP_USER_AGENT
'
,
''
)
user_agent
=
self
.
request
.
headers
.
get
(
'user-agent
'
,
''
)
if
'WebKit'
in
user_agent
:
# Support available for UTF-8 encoded strings.
# This also matches Edgee.
...
...
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