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
4b69c2ea
Unverified
Commit
4b69c2ea
authored
Feb 06, 2018
by
Diederik van der Boor
Committed by
GitHub
Feb 06, 2018
Browse files
Merge pull request #18 from vmspike/master
Django 2.0 experimental support
parents
31136583
cc35a590
Changes
2
Hide whitespace changes
Inline
Side-by-side
private_storage/fields.py
View file @
4b69c2ea
...
...
@@ -11,6 +11,9 @@ from django.template.defaultfilters import filesizeformat
from
django.utils.translation
import
ugettext_lazy
as
_
from
.storage
import
private_storage
import
datetime
from
django.utils.encoding
import
force_str
,
force_text
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -68,3 +71,15 @@ class PrivateFileField(models.FileField):
subdirs
=
[
self
.
get_directory_name
()]
dirs
=
list
(
subdirs
)
+
[
self
.
get_filename
(
filename
)]
return
os
.
path
.
normpath
(
os
.
path
.
join
(
*
dirs
))
def
get_directory_name
(
self
):
'''
Added for compatibility with Django 2.0 where this method was removed
'''
return
os
.
path
.
normpath
(
force_text
(
datetime
.
datetime
.
now
().
strftime
(
force_str
(
self
.
upload_to
))))
def
get_filename
(
self
,
filename
):
'''
Added for compatibility with Django 2.0 where this method was removed
'''
return
os
.
path
.
normpath
(
self
.
storage
.
get_valid_name
(
os
.
path
.
basename
(
filename
)))
private_storage/permissions.py
View file @
4b69c2ea
...
...
@@ -4,14 +4,26 @@ Possible functions for the ``PRIVATE_STORAGE_AUTH_FUNCTION`` setting.
def
allow_authenticated
(
private_file
):
return
private_file
.
request
.
user
.
is_authenticated
()
try
:
return
private_file
.
request
.
user
.
is_authenticated
()
except
AttributeError
:
# Using user.is_authenticated() and user.is_anonymous() as a method is deprecated since Django 2.0
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
try
:
return
request
.
user
.
is_authenticated
()
and
request
.
user
.
is_staff
except
AttributeError
:
# Using user.is_authenticated() and user.is_anonymous() as a method is deprecated since Django 2.0
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
try
:
return
request
.
user
.
is_authenticated
()
and
request
.
user
.
is_superuser
except
AttributeError
:
# Using user.is_authenticated() and user.is_anonymous() as a method is deprecated since Django 2.0
return
request
.
user
.
is_authenticated
and
request
.
user
.
is_superuser
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