from django.contrib.auth.decorators import user_passes_test
from django.contrib.auth import REDIRECT_FIELD_NAME
from .models import User


def read_write_permission_required(function=None, redirect_field_name=
    REDIRECT_FIELD_NAME, login_url=None):
    """
    Decorator for views that checks that the user has read and write permission, redirecting
    to the log-in page if necessary.
    """
    actual_decorator = user_passes_test(lambda u: u.permissions == User.
        READ_WRITE, login_url=login_url, redirect_field_name=
        redirect_field_name)
    if function:
        return actual_decorator(function)
    return actual_decorator


def admin_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME,
    login_url=None):
    """
    Decorator for views that checks that the user is an admin, redirecting
    to the log-in page if necessary.
    """
    actual_decorator = user_passes_test(lambda u: u.is_admin, login_url=
        login_url, redirect_field_name=redirect_field_name)
    if function:
        return actual_decorator(function)
    return actual_decorator

953913b6c2a97944f878d066a6f94f55c7afeddd
<mask token>

<mask token>


def read_write_permission_required(function=None, redirect_field_name=
    REDIRECT_FIELD_NAME, login_url=None):
    """
    Decorator for views that checks that the user has read and write permission, redirecting
    to the log-in page if necessary.
    """
    actual_decorator = user_passes_test(lambda u: u.permissions == User.
        READ_WRITE, login_url=login_url, redirect_field_name=
        redirect_field_name)
    if function:
        return actual_decorator(function)
    return actual_decorator


<mask token>

<mask token>


def read_write_permission_required(function=None, redirect_field_name=
    REDIRECT_FIELD_NAME, login_url=None):
    """
    Decorator for views that checks that the user has read and write permission, redirecting
    to the log-in page if necessary.
    """
    actual_decorator = user_passes_test(lambda u: u.permissions == User.
        READ_WRITE, login_url=login_url, redirect_field_name=
        redirect_field_name)
    if function:
        return actual_decorator(function)
    return actual_decorator


def admin_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME,
    login_url=None):
    """
    Decorator for views that checks that the user is an admin, redirecting
    to the log-in page if necessary.
    """
    actual_decorator = user_passes_test(lambda u: u.is_admin, login_url=
        login_url, redirect_field_name=redirect_field_name)
    if function:
        return actual_decorator(function)
    return actual_decorator

from django.contrib.auth.decorators import user_passes_test
from django.contrib.auth import REDIRECT_FIELD_NAME
from .models import User


def read_write_permission_required(function=None, redirect_field_name=
    REDIRECT_FIELD_NAME, login_url=None):
    """
    Decorator for views that checks that the user has read and write permission, redirecting
    to the log-in page if necessary.
    """
    actual_decorator = user_passes_test(lambda u: u.permissions == User.
        READ_WRITE, login_url=login_url, redirect_field_name=
        redirect_field_name)
    if function:
        return actual_decorator(function)
    return actual_decorator


def admin_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME,
    login_url=None):
    """
    Decorator for views that checks that the user is an admin, redirecting
    to the log-in page if necessary.
    """
    actual_decorator = user_passes_test(lambda u: u.is_admin, login_url=
        login_url, redirect_field_name=redirect_field_name)
    if function:
        return actual_decorator(function)
    return actual_decorator
