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


Python models.User类代码示例

本文整理汇总了Python中sentry.models.User的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: owner

    def owner(self):
        user = User(username="owner", email="[email protected]")
        user.set_password('owner')
        user.save()

        Team.objects.create(owner=user, name='foo', slug='foo')

        return user
开发者ID:CaseCommonsDevOps,项目名称:sentry,代码行数:8,代码来源:tests.py

示例2: create_user

    def create_user(self, email, **kwargs):
        kwargs.setdefault('username', email)
        kwargs.setdefault('is_staff', True)
        kwargs.setdefault('is_superuser', True)

        user = User(email=email, **kwargs)
        user.set_password('admin')
        user.save()

        return user
开发者ID:catufunwa,项目名称:sentry,代码行数:10,代码来源:fixtures.py

示例3: createuser

def createuser(email, password, superuser, no_password, no_input):
    "Create a new user."
    if not no_input:
        if not email:
            email = _get_email()

        if not (password or no_password):
            password = _get_password()

        if superuser is None:
            superuser = _get_superuser()

    if superuser is None:
        superuser = False

    if not email:
        raise click.ClickException('Invalid or missing email address.')

    # TODO(mattrobenolt): Accept password over stdin?
    if not no_password and not password:
        raise click.ClickException('No password set and --no-password not passed.')

    from sentry import roles
    from sentry.models import User
    from django.conf import settings

    user = User(
        email=email,
        username=email,
        is_superuser=superuser,
        is_staff=superuser,
        is_active=True,
    )

    if password:
        user.set_password(password)

    user.save()

    click.echo('User created: %s' % (email,))

    # TODO(dcramer): kill this when we improve flows
    if settings.SENTRY_SINGLE_ORGANIZATION:
        from sentry.models import Organization, OrganizationMember
        org = Organization.get_default()
        if superuser:
            role = roles.get_top_dog().id
        else:
            role = org.default_role
        OrganizationMember.objects.create(
            organization=org,
            user=user,
            role=role,
        )
        click.echo('Added to organization: %s' % (org.slug,))
开发者ID:delkyd,项目名称:sentry,代码行数:55,代码来源:createuser.py

示例4: member

    def member(self):
        user = User(username="member", email="[email protected]")
        user.set_password('member')
        user.save()

        TeamMember.objects.create(
            user=user,
            team=self.team,
            type=MEMBER_USER,
        )
        return user
开发者ID:CaseCommonsDevOps,项目名称:sentry,代码行数:11,代码来源:tests.py

示例5: member

    def member(self):
        user = User(username="member", email="[email protected]")
        user.set_password('member')
        user.save()

        om = self.create_member(
            organization=self.team.organization,
            user=user,
            type=MEMBER_USER,
            teams=[self.team],
        )
        return user
开发者ID:carriercomm,项目名称:sentry-1,代码行数:12,代码来源:tests.py

示例6: member

    def member(self):
        user = User(username="member", email="[email protected]")
        user.set_password('member')
        user.save()

        om = OrganizationMember.objects.create(
            organization=self.team.organization,
            user=user,
            type=MEMBER_USER,
        )
        om.teams.add(self.team)
        return user
开发者ID:BlueMoebius,项目名称:sentry,代码行数:12,代码来源:tests.py

示例7: create_user

    def create_user(self, email=None, **kwargs):
        if not email:
            email = uuid4().hex + "@example.com"

        kwargs.setdefault("username", email)
        kwargs.setdefault("is_staff", True)
        kwargs.setdefault("is_superuser", False)

        user = User(email=email, **kwargs)
        user.set_password("admin")
        user.save()

        return user
开发者ID:noah-lee,项目名称:sentry,代码行数:13,代码来源:fixtures.py

示例8: handle

    def handle(self, **options):
        email = options['email']
        is_superuser = options['is_superuser']
        password = options['password']

        if not options['noinput']:
            try:
                if not email:
                    email = self.get_email()

                if not (password or options['nopassword']):
                    password = self.get_password()

                if is_superuser is None:
                    is_superuser = self.get_superuser()
            except KeyboardInterrupt:
                self.stderr.write("\nOperation cancelled.")
                sys.exit(1)

        if not email:
            raise CommandError('Invalid or missing email address')

        if not options['nopassword'] and not password:
            raise CommandError('No password set and --no-password not passed')

        user = User(
            email=email,
            username=email,
            is_superuser=is_superuser,
            is_staff=is_superuser,
            is_active=True,
        )

        if password:
            user.set_password(password)

        user.save()

        self.stdout.write('User created: %s' % (email,))

        # TODO(dcramer): kill this when we improve flows
        if settings.SENTRY_SINGLE_ORGANIZATION:
            org = Organization.objects.all()[0]
            OrganizationMember.objects.create(
                organization=org,
                user=user,
                type=OrganizationMemberType.OWNER,
                has_global_access=user.is_superuser,
            )
            self.stdout.write('Added to organization: %s' % (org.slug,))
开发者ID:KinKir,项目名称:sentry,代码行数:50,代码来源:createuser.py

示例9: create_user

    def create_user(self, email=None, **kwargs):
        if not email:
            email = uuid4().hex + '@example.com'

        kwargs.setdefault('username', email)
        kwargs.setdefault('is_staff', True)
        kwargs.setdefault('is_active', True)
        kwargs.setdefault('is_superuser', False)

        user = User(email=email, **kwargs)
        user.set_password('admin')
        user.save()

        # UserEmail is created by a signal
        UserEmail.objects.filter(
            user=user,
            email=email,
        ).update(is_verified=True)

        return user
开发者ID:duanshuaimin,项目名称:sentry,代码行数:20,代码来源:fixtures.py

示例10: handle

    def handle(self, **options):
        email = options['email']
        is_superuser = options['is_superuser']

        if not options['noinput']:
            try:
                if not email:
                    email = self.get_email()

                if not options['nopassword']:
                    password = self.get_password()

                if is_superuser is None:
                    is_superuser = self.get_superuser()
            except KeyboardInterrupt:
                self.stderr.write("\nOperation cancelled.")
                sys.exit(1)

        else:
            password = None

        if not email:
            raise CommandError('Invalid or missing email address')

        if not options['nopassword'] and not password:
            raise CommandError('No password set and --no-password not passed')

        user = User(
            email=email,
            username=email,
            is_superuser=is_superuser,
            is_staff=is_superuser,
            is_active=True,
        )

        if password:
            user.set_password(password)

        user.save()

        self.stdout.write('User created: %s' % (email,))
开发者ID:BlueMoebius,项目名称:sentry,代码行数:41,代码来源:createuser.py

示例11: EmailAuthBackendTest

class EmailAuthBackendTest(TestCase):
    def setUp(self):
        self.user = User(username="foo", email="[email protected]")
        self.user.set_password("bar")
        self.user.save()

    @property
    def backend(self):
        return EmailAuthBackend()

    def test_can_authenticate_with_username(self):
        result = self.backend.authenticate(username='foo', password='bar')
        self.assertEquals(result, self.user)

    def test_can_authenticate_with_email(self):
        result = self.backend.authenticate(username='[email protected]', password='bar')
        self.assertEquals(result, self.user)

    def test_does_not_authenticate_with_invalid_password(self):
        result = self.backend.authenticate(username='foo', password='pizza')
        self.assertEquals(result, None)
开发者ID:Kayle009,项目名称:sentry,代码行数:21,代码来源:tests.py

示例12: nobody

 def nobody(self):
     user = User(username="nobody", email="[email protected]")
     user.set_password('nobody')
     user.save()
     return user
开发者ID:CaseCommonsDevOps,项目名称:sentry,代码行数:5,代码来源:tests.py

示例13: owner

    def owner(self):
        user = User(username="owner", email="[email protected]")
        user.set_password('owner')
        user.save()

        return user
开发者ID:carriercomm,项目名称:sentry-1,代码行数:6,代码来源:tests.py

示例14: admin

 def admin(self):
     user = User(username="admin", email="[email protected]", is_staff=True, is_superuser=True)
     user.set_password('admin')
     user.save()
     return user
开发者ID:CaseCommonsDevOps,项目名称:sentry,代码行数:5,代码来源:tests.py

示例15: createuser

def createuser(email, password, superuser, no_password, no_input):
    "Create a new user."
    if not no_input:
        if not email:
            email = _get_email()

        if not (password or no_password):
            password = _get_password()

        if superuser is None:
            superuser = _get_superuser()

    if superuser is None:
        superuser = False

    if not email:
        raise click.ClickException('Invalid or missing email address.')

    # TODO(mattrobenolt): Accept password over stdin?
    if not no_password and not password:
        raise click.ClickException('No password set and --no-password not passed.')

    from sentry import roles
    from sentry.models import User
    from django.conf import settings

    user = User(
        email=email,
        username=email,
        is_superuser=superuser,
        is_staff=superuser,
        is_active=True,
    )

    if password:
        user.set_password(password)

    user.save()

    click.echo('User created: %s' % (email, ))

    # TODO(dcramer): kill this when we improve flows
    if settings.SENTRY_SINGLE_ORGANIZATION:
        from sentry.models import (Organization, OrganizationMember, OrganizationMemberTeam, Team)

        org = Organization.get_default()
        if superuser:
            role = roles.get_top_dog().id
        else:
            role = org.default_role
        member = OrganizationMember.objects.create(
            organization=org,
            user=user,
            role=role,
        )

        # if we've only got a single team let's go ahead and give
        # access to that team as its likely the desired outcome
        teams = list(Team.objects.filter(organization=org)[0:2])
        if len(teams) == 1:
            OrganizationMemberTeam.objects.create(
                team=teams[0],
                organizationmember=member,
            )
        click.echo('Added to organization: %s' % (org.slug, ))
开发者ID:Kayle009,项目名称:sentry,代码行数:65,代码来源:createuser.py


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