python类user_passes_test()的实例源码

decorators.py 文件源码 项目:trydjango18 作者: lucifer-yqh 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def staff_member_required(view_func, redirect_field_name=REDIRECT_FIELD_NAME, login_url='admin:login'):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member, displaying the login page if necessary.
    """
    return user_passes_test(
        lambda u: u.is_active and u.is_staff,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )(view_func)
views.py 文件源码 项目:passport 作者: SRELabs 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def super_user_required(login_url='/error_403'):
    """
    check permission
    :param login_url:
    :return:
    """
    return user_passes_test(lambda u: u.is_superuser, login_url=login_url)
decorators.py 文件源码 项目:trydjango18 作者: wei0104 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def staff_member_required(view_func, redirect_field_name=REDIRECT_FIELD_NAME, login_url='admin:login'):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member, displaying the login page if necessary.
    """
    return user_passes_test(
        lambda u: u.is_active and u.is_staff,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )(view_func)
authentication.py 文件源码 项目:drastic-web 作者: UMD-DRASTIC 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def administrator_required(function=None,
                           redirect_field_name=REDIRECT_FIELD_NAME,
                           login_url=None):
    """
    Decorator for views that checks that the user is logged in and an
    administrator
    """
    actual_decorator = user_passes_test(
        lambda u: u.administrator,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if function:
        return actual_decorator(function)
    return actual_decorator
decorators.py 文件源码 项目:drapo 作者: andgein 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):
    """
    Decorator for views that checks that the user is logged in, redirecting
    to the log-in page if necessary.

    Based on django.contrib.auth.decorators.login_required
    """
    actual_decorator = user_passes_test(
        lambda u: u.is_authenticated() and u.is_email_confirmed,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if function:
        return actual_decorator(function)
    return actual_decorator
decorators.py 文件源码 项目:drapo 作者: andgein 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def staff_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):
    """
    Decorator for views that checks that the user is staff, redirecting
    to the log-in page if necessary.
    """
    actual_decorator = user_passes_test(
        lambda u: u.is_staff,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if function:
        return actual_decorator(function)
    return actual_decorator
decorators.py 文件源码 项目:hydra 作者: Our-Revolution 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def bsd_login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):
    """
    Decorator for views that checks that the user is logged in, redirecting
    to the log-in page if necessary.
    """
    actual_decorator = user_passes_test(
        lambda u: isinstance(u, Constituent),
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if function:
        return actual_decorator(function)
    return actual_decorator
decorators.py 文件源码 项目:ims 作者: ims-team 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def staff_member_required(view_func=None, redirect_field_name=REDIRECT_FIELD_NAME,
                          login_url='admin:login'):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member, redirecting to the login page if necessary.
    """
    actual_decorator = user_passes_test(
        lambda u: u.is_active and u.is_staff,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if view_func:
        return actual_decorator(view_func)
    return actual_decorator
decorators.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def staff_member_required(view_func=None, redirect_field_name=REDIRECT_FIELD_NAME,
                          login_url='admin:login'):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member, redirecting to the login page if necessary.
    """
    actual_decorator = user_passes_test(
        lambda u: u.is_active and u.is_staff,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if view_func:
        return actual_decorator(view_func)
    return actual_decorator
utils.py 文件源码 项目:economy-game 作者: Aearsis 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def player_required(view_func):
    """
    Decorator that ensures logged user is a player

    """
    player_decorator = user_passes_test(
        lambda u: hasattr(u, 'player'),
    )
    return player_decorator(view_func)
utils.py 文件源码 项目:economy-game 作者: Aearsis 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def team_required(view_func):
    """
    Decorator that ensures logged player has its own team -> request.team != None.
    User must be logged in (if not, redirect to login_url), and have a team (if not, redirect to core.team)

    """
    team_decorator = user_passes_test(
        lambda u: u.player.team is not None,
        login_url='/team/create/'
    )
    return player_required(team_decorator(view_func))
decorators.py 文件源码 项目:django-open-lecture 作者: DmLitov4 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def staff_member_required(view_func=None, redirect_field_name=REDIRECT_FIELD_NAME,
                          login_url='admin:login'):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member, redirecting to the login page if necessary.
    """
    actual_decorator = user_passes_test(
        lambda u: u.is_active and u.is_staff,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if view_func:
        return actual_decorator(view_func)
    return actual_decorator
decorators.py 文件源码 项目:travlr 作者: gauravkulkarni96 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def staff_member_required(view_func=None, redirect_field_name=REDIRECT_FIELD_NAME,
                          login_url='admin:login'):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member, redirecting to the login page if necessary.
    """
    actual_decorator = user_passes_test(
        lambda u: u.is_active and u.is_staff,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if view_func:
        return actual_decorator(view_func)
    return actual_decorator
views.py 文件源码 项目:django-keeper 作者: hirokiky 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def login_required(login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
    # FIXME: Ugly hack to extract process when django's user_passes_test.
    return user_passes_test(
        lambda u: False,
        login_url=login_url,
        redirect_field_name=redirect_field_name,
    )(lambda r: "dummy")
views.py 文件源码 项目:infonex_crm 作者: asterix135 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def has_management_permission(user):
    """
    Replacing with ManagementPermissionMixin

    used in def index (not as decorator)
    used in def manage_territory
    used in def add_master_list_select
    used in def add_personal_list_select
    used in def create_selection_widget
    used in def delete_master_list_select
    used in def delete_personal_list_select
    used in def load_staff_category_selects
    used in def load_staff_member_selects
    used in def update_user_assignments

    To be called by textdecorator @user_passes_test
    Also, any time you need to check if user has management permissions
    """
    if user.groups.filter(name='db_admin').exists():
        return True
    if user.groups.filter(name='management').exists():
        return True
    if user.is_superuser:
        return True
    return False


##################
# MAIN FUNCTIONS
##################
funcionpermisos.py 文件源码 项目:Aleph 作者: usernameistakenlol 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def group_required(*group_names):
    def in_groups(u):
        if u.is_authenticated():
            if bool(u.groups.filter(name__in=group_names)) | u.is_superuser:
                return True
        return False
    return user_passes_test(in_groups, login_url='/error/')
decorators.py 文件源码 项目:logo-gen 作者: jellene4eva 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def staff_member_required(view_func=None, redirect_field_name=REDIRECT_FIELD_NAME,
                          login_url='admin:login'):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member, redirecting to the login page if necessary.
    """
    actual_decorator = user_passes_test(
        lambda u: u.is_active and u.is_staff,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if view_func:
        return actual_decorator(view_func)
    return actual_decorator
decorators.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def staff_member_required(view_func=None, redirect_field_name=REDIRECT_FIELD_NAME,
                          login_url='admin:login'):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member, redirecting to the login page if necessary.
    """
    actual_decorator = user_passes_test(
        lambda u: u.is_active and u.is_staff,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if view_func:
        return actual_decorator(view_func)
    return actual_decorator
decorators.py 文件源码 项目:gmail_scanner 作者: brandonhub 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def staff_member_required(view_func=None, redirect_field_name=REDIRECT_FIELD_NAME,
                          login_url='admin:login'):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member, redirecting to the login page if necessary.
    """
    actual_decorator = user_passes_test(
        lambda u: u.is_active and u.is_staff,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if view_func:
        return actual_decorator(view_func)
    return actual_decorator
decorators.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def staff_member_required(view_func=None, redirect_field_name=REDIRECT_FIELD_NAME,
                          login_url='admin:login'):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member, redirecting to the login page if necessary.
    """
    actual_decorator = user_passes_test(
        lambda u: u.is_active and u.is_staff,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if view_func:
        return actual_decorator(view_func)
    return actual_decorator


问题


面经


文章

微信
公众号

扫码关注公众号