我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用flask_login.UserMixin()。
def get_user(cls, user): """Get user object: 1º check if user is already User, LocalProxy, or AnnonymousUser object if so, just return it 2º if not, search for this user and return if found. 3º otherwise, return DoesNotExists exception""" if any([isinstance(user, obj) for obj in [UserMixin, AnonymousUserMixin]]): return user if isinstance(user, LocalProxy): return user._get_current_object() try: return User.objects.get(username=user) except (me.DoesNotExist, me.ValidationError): return User.objects.get(id=user)
def __eq__(self, other): ''' Checks the equality of two `UserMixin` objects using `get_id`. ''' if isinstance(other, UserMixin): return self.get_id() == other.get_id() return NotImplemented
def __ne__(self, other): ''' Checks the inequality of two `UserMixin` objects using `get_id`. ''' equal = self.__eq__(other) if equal is NotImplemented: return NotImplemented return not equal