本文整理汇总了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
示例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"
)
示例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"
示例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.
示例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)
示例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}
示例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
示例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))
示例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)
示例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)
示例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
示例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]
示例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
示例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())