當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。