Unverified Commit d4c0c7bd authored by Diederik van der Boor's avatar Diederik van der Boor
Browse files

Updates by django-upgrade, removes if django.VERSION >= (1, 10) checks

parent 0920f2bf
...@@ -4,7 +4,6 @@ import os ...@@ -4,7 +4,6 @@ import os
import posixpath import posixpath
import warnings import warnings
import django
from django.core import checks from django.core import checks
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import UploadedFile from django.core.files.uploadedfile import UploadedFile
...@@ -90,11 +89,8 @@ class PrivateFileField(models.FileField): ...@@ -90,11 +89,8 @@ class PrivateFileField(models.FileField):
path_parts.extend([self.storage.get_valid_name(dir) for dir in extra_dirs]) path_parts.extend([self.storage.get_valid_name(dir) for dir in extra_dirs])
path_parts.append(self._get_clean_filename(filename)) path_parts.append(self._get_clean_filename(filename))
if django.VERSION >= (1, 10):
filename = posixpath.join(*path_parts) filename = posixpath.join(*path_parts)
return self.storage.generate_filename(filename) return self.storage.generate_filename(filename)
else:
return os.path.join(*path_parts)
def _get_clean_filename(self, filename): def _get_clean_filename(self, filename):
# As of Django 1.10+, file names are no longer cleaned locally, but cleaned by the storage. # As of Django 1.10+, file names are no longer cleaned locally, but cleaned by the storage.
......
""" """
Possible functions for the ``PRIVATE_STORAGE_AUTH_FUNCTION`` setting. Possible functions for the ``PRIVATE_STORAGE_AUTH_FUNCTION`` setting.
""" """
import django
if django.VERSION >= (1, 10):
def allow_authenticated(private_file): def allow_authenticated(private_file):
return private_file.request.user.is_authenticated 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_superuser(private_file): def allow_staff(private_file):
request = private_file.request request = private_file.request
return request.user.is_authenticated and request.user.is_superuser return request.user.is_authenticated and request.user.is_staff
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_superuser(private_file): def allow_superuser(private_file):
request = private_file.request request = private_file.request
return request.user.is_authenticated() and request.user.is_superuser return request.user.is_authenticated and request.user.is_superuser
...@@ -122,7 +122,7 @@ class PrivateStorageView(View): ...@@ -122,7 +122,7 @@ class PrivateStorageView(View):
The filename, encoded to use in a ``Content-Disposition`` header. The filename, encoded to use in a ``Content-Disposition`` header.
""" """
# Based on https://www.djangosnippets.org/snippets/1710/ # 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: if 'WebKit' in user_agent:
# Support available for UTF-8 encoded strings. # Support available for UTF-8 encoded strings.
# This also matches Edgee. # This also matches Edgee.
......
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