Unverified Commit 4b69c2ea authored by Diederik van der Boor's avatar Diederik van der Boor Committed by GitHub
Browse files

Merge pull request #18 from vmspike/master

Django 2.0 experimental support
parents 31136583 cc35a590
......@@ -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)))
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment