Python django.contrib.auth.models.AbstractUser() Examples
The following are 15
code examples of django.contrib.auth.models.AbstractUser().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.auth.models
, or try the search function
.
Example #1
Source File: models.py From Bitpoll with GNU General Public License v3.0 | 6 votes |
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
Example #2
Source File: user_manager.py From raveberry with GNU Lesser General Public License v3.0 | 5 votes |
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" )
Example #3
Source File: user_manager.py From raveberry with GNU Lesser General Public License v3.0 | 5 votes |
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"
Example #4
Source File: user_manager.py From raveberry with GNU Lesser General Public License v3.0 | 5 votes |
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.
Example #5
Source File: view.py From dingtalk-django-example with GNU General Public License v3.0 | 5 votes |
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)
Example #6
Source File: utils.py From meeting with GNU General Public License v3.0 | 5 votes |
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)
Example #7
Source File: reference.py From online-judge with GNU Affero General Public License v3.0 | 5 votes |
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}
Example #8
Source File: gravatar.py From online-judge with GNU Affero General Public License v3.0 | 5 votes |
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
Example #9
Source File: tests.py From BookForum with MIT License | 5 votes |
def test_inherit_ship(self): from django.contrib.auth.models import AbstractUser self.assertTrue(isinstance(self.user, AbstractUser))
Example #10
Source File: poll_permissions.py From Bitpoll with GNU General Public License v3.0 | 5 votes |
def poll_can_edit(poll: Poll, user: AbstractUser) -> bool: return poll.can_edit(user)
Example #11
Source File: poll_permissions.py From Bitpoll with GNU General Public License v3.0 | 5 votes |
def poll_is_owner(poll: Poll, user: AbstractUser) -> bool: return poll.is_owner(user)
Example #12
Source File: models.py From Bitpoll with GNU General Public License v3.0 | 5 votes |
def has_voted(self, user: AbstractUser) -> bool: return user.is_authenticated and Vote.objects.filter(user=user, poll=self).count() > 0
Example #13
Source File: models.py From Bitpoll with GNU General Public License v3.0 | 5 votes |
def get_own_vote(self, user: AbstractUser): return Vote.objects.filter(user=user, poll=self)[0]
Example #14
Source File: models.py From Bitpoll with GNU General Public License v3.0 | 5 votes |
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
Example #15
Source File: models.py From Bitpoll with GNU General Public License v3.0 | 5 votes |
def is_owner(self, user: AbstractUser): return self.user == user or (self.group and user in self.group.user_set.all())