当前位置: 首页>>代码示例>>Python>>正文


Python models.AbstractUser方法代码示例

本文整理汇总了Python中django.contrib.auth.models.AbstractUser方法的典型用法代码示例。如果您正苦于以下问题:Python models.AbstractUser方法的具体用法?Python models.AbstractUser怎么用?Python models.AbstractUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.auth.models的用法示例。


在下文中一共展示了models.AbstractUser方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: can_vote

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def can_vote(self, user: AbstractUser, request: Optional[HttpRequest] = None, is_edit: bool=False) -> bool:
        """
        Determine if the user is allowed to vote

        :param is_edit: if the vote is an edit
        :param user:
        :param request: the request object or None. if None no messages are printed
        :return:
        """
        has_voted = self.has_voted(user)
        if self.one_vote_per_user and has_voted and not is_edit:
            if request:
                messages.error(request, _("It is only one vote allowed. You have already voted."))
            return False
        elif self.require_login and not user.is_authenticated:
            if request:
                messages.error(request, _("Login required to vote."))
            return False
        elif self.require_invitation and (not user.is_authenticated or not self.invitation_set.filter(user=user).exists()):
            if request:
                messages.error(request, _("You are not allowed to vote in this poll. You have to be invited"))
            return False
        return True 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:25,代码来源:models.py

示例2: has_controls

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def has_controls(cls, user: AbstractUser) -> bool:
        """Determines whether the given user is allowed to control playback."""
        return (
            user.username == "mod" or user.username == "pad" or user.username == "admin"
        ) 
开发者ID:raveberry,项目名称:raveberry,代码行数:7,代码来源:user_manager.py

示例3: has_pad

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def has_pad(cls, user: AbstractUser) -> bool:
        """Determines whether the given user is allowed to access the pad."""
        return user.username == "pad" or user.username == "admin" 
开发者ID:raveberry,项目名称:raveberry,代码行数:5,代码来源:user_manager.py

示例4: is_admin

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def is_admin(cls, user: AbstractUser) -> bool:
        """Determines whether the given user is the admin."""
        return user.username == "admin"

    # This dictionary needs to be static so the middleware can access it. 
开发者ID:raveberry,项目名称:raveberry,代码行数:7,代码来源:user_manager.py

示例5: check_api_permissions

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def check_api_permissions(self, request, *args, **kwargs):
        if not isinstance(request.user, auth_models.AbstractUser):
            raise CustomError(ErrCode.ERR_AUTH_NOLOGIN)
        if not request.user.is_active or not request.user.is_staff:
            raise CustomError(ErrCode.ERR_AUTH_PERMISSION)
        if self.need_superuser:
            if not request.user.is_superuser:
                raise CustomError(ErrCode.ERR_AUTH_PERMISSION) 
开发者ID:007gzs,项目名称:dingtalk-django-example,代码行数:10,代码来源:view.py

示例6: link_user

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def link_user(user):
    if isinstance(user, Profile):
        user, profile = user.user, user
    elif isinstance(user, AbstractUser):
        profile = user.profile
    elif type(user).__name__ == 'ContestRankingProfile':
        user, profile = user.user, user
    else:
        raise ValueError('Expected profile or user, got %s' % (type(user),))
    return {'user': user, 'profile': profile} 
开发者ID:DMOJ,项目名称:online-judge,代码行数:12,代码来源:reference.py

示例7: gravatar

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def gravatar(email, size=80, default=None):
    if isinstance(email, Profile):
        if default is None:
            default = email.mute
        email = email.user.email
    elif isinstance(email, AbstractUser):
        email = email.email

    gravatar_url = 'https://www.gravatar.com/avatar/' + hashlib.md5(utf8bytes(email.strip().lower())).hexdigest() + '?'
    args = {'d': 'identicon', 's': str(size)}
    if default:
        args['f'] = 'y'
    gravatar_url += urlencode(args)
    return gravatar_url 
开发者ID:DMOJ,项目名称:online-judge,代码行数:16,代码来源:gravatar.py

示例8: test_inherit_ship

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def test_inherit_ship(self):
        from django.contrib.auth.models import AbstractUser
        self.assertTrue(isinstance(self.user, AbstractUser)) 
开发者ID:Arianxx,项目名称:BookForum,代码行数:5,代码来源:tests.py

示例9: poll_can_edit

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def poll_can_edit(poll: Poll, user: AbstractUser) -> bool:
    return poll.can_edit(user) 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:4,代码来源:poll_permissions.py

示例10: poll_is_owner

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def poll_is_owner(poll: Poll, user: AbstractUser) -> bool:
    return poll.is_owner(user) 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:4,代码来源:poll_permissions.py

示例11: has_voted

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def has_voted(self, user: AbstractUser) -> bool:
        return user.is_authenticated and Vote.objects.filter(user=user, poll=self).count() > 0 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:4,代码来源:models.py

示例12: get_own_vote

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def get_own_vote(self, user: AbstractUser):
        return Vote.objects.filter(user=user, poll=self)[0] 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:4,代码来源:models.py

示例13: can_watch

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def can_watch(self, user: AbstractUser) -> bool:
        if self.can_vote(user) and self.show_results not in ('never', 'summary after vote', 'complete after vote'):
            # If the user can vote and the results are not restricted
            return True
        if self.has_voted(user) and self.show_results not in ('never', ):
            # If the user has voted and can view the results
            return True
        return False 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:10,代码来源:models.py

示例14: is_owner

# 需要导入模块: from django.contrib.auth import models [as 别名]
# 或者: from django.contrib.auth.models import AbstractUser [as 别名]
def is_owner(self, user: AbstractUser):
        return self.user == user or (self.group and user in self.group.user_set.all()) 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:4,代码来源:models.py


注:本文中的django.contrib.auth.models.AbstractUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。