

def allow_authenticated(private_file):
    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
    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
    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

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_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_superuser(private_file):
        request = private_file.request
        return request.user.is_authenticated() and request.user.is_superuser

Change the permission checks, provide distinct versions for Django 1.10+
Change the permission checks, provide distinct versions for Django 1.10+

+ import django
  
+ if django.VERSION >= (1, 10):
+     def allow_authenticated(private_file):
+         return private_file.request.user.is_authenticated
  
- def allow_authenticated(private_file):
-     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):
+     def allow_staff(private_file):
-     request = private_file.request
+         request = private_file.request
-     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
+ else:
+     def allow_authenticated(private_file):
+         return private_file.request.user.is_authenticated()
  
- def allow_superuser(private_file):
+     def allow_staff(private_file):
-     request = private_file.request
+         request = private_file.request
-     try:
+         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
-     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
  
Change the permission checks, provide distinct versions for Django 1.10+
## Code Before:


def allow_authenticated(private_file):
    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
    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
    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

## Instruction:
Change the permission checks, provide distinct versions for Django 1.10+
## Code After:
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_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_superuser(private_file):
        request = private_file.request
        return request.user.is_authenticated() and request.user.is_superuser
