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


Python models.UserEmail类代码示例

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


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

示例1: test_show_alt_emails

 def test_show_alt_emails(self):
     user = self.create_user('[email protected]')
     self.login_as(user)
     email = UserEmail(user=user, email='[email protected]')
     email.save()
     resp = self.client.get(self.path)
     self.assertIn('[email protected]', resp.content)
     assert '[email protected]' in ([thing.email for thing in user.emails.all()])
开发者ID:duanshuaimin,项目名称:sentry,代码行数:8,代码来源:test_emails.py

示例2: test_username_updates

 def test_username_updates(self):
     user = self.create_user('[email protected]')
     self.login_as(user)
     email = UserEmail(user=user, email='[email protected]')
     email.save()
     self.client.post(self.path, data={'primary': '', 'new_primary_email': '[email protected]'}, follow=True)
     user = User.objects.get(id=user.id)
     assert user.username != '[email protected]'
     assert user.username == '[email protected]'
开发者ID:duanshuaimin,项目名称:sentry,代码行数:9,代码来源:test_emails.py

示例3: test_remove_alt_email

 def test_remove_alt_email(self):
     user = self.create_user('[email protected]')
     self.login_as(user)
     email = UserEmail(user=user, email='[email protected]')
     email.save()
     resp = self.client.get(self.path)
     self.assertIn('[email protected]', resp.content)
     resp = self.client.post(self.path, data={'remove': '', 'email': '[email protected]'}, follow=True)
     self.assertNotIn('[email protected]', resp.content)
     assert '[email protected]' not in (email.email for email in user.emails.all())
开发者ID:duanshuaimin,项目名称:sentry,代码行数:10,代码来源:test_emails.py

示例4: create_useremail

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

        kwargs.setdefault('is_verified', True)

        useremail = UserEmail(user=user, email=email, **kwargs)
        useremail.save()

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

示例5: account_settings

def account_settings(request):
    user = request.user

    form = AccountSettingsForm(
        user, request, request.POST or None,
        initial={
            'email': UserEmail.get_primary_email(user).email,
            'username': user.username,
            'name': user.name,
        },
    )

    if form.is_valid():
        old_email = user.email

        form.save()

        # remove previously valid email address
        # TODO(dcramer): we should maintain validation here when we support
        # multiple email addresses
        if request.user.email != old_email:
            UserEmail.objects.filter(user=user, email=old_email).delete()
            try:
                with transaction.atomic():
                    user_email = UserEmail.objects.create(
                        user=user,
                        email=user.email,
                    )
            except IntegrityError:
                pass
            else:
                user_email.set_hash()
                user_email.save()
                user.send_confirm_email_singular(user_email)
                msg = _('A confirmation email has been sent to %s.') % user_email.email
                messages.add_message(
                    request,
                    messages.SUCCESS,
                    msg)

        messages.add_message(
            request, messages.SUCCESS, _('Your settings were saved.'))
        return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'form': form,
        'page': 'settings',
        'has_2fa': Authenticator.objects.user_has_2fa(request.user),
        'AUTH_PROVIDERS': auth.get_auth_providers(),
        'email': UserEmail.get_primary_email(user),
        'has_newsletters': newsletter.is_enabled,
    })
    return render_to_response('sentry/account/settings.html', context, request)
开发者ID:faulkner,项目名称:sentry,代码行数:54,代码来源:accounts.py

示例6: put

    def put(self, request, user):
        """
        Update Account Subscriptions
        ````````````````````````````

        Update account subscriptions to newsletter

        :param int listId: id of newsletter list
        :param boolean subscribed: should be subscribed to newsletter
        :auth: required
        """
        validator = NewsletterValidator(data=request.DATA)
        if not validator.is_valid():
            return self.respond(validator.errors, status=400)

        result = validator.object
        email = UserEmail.get_primary_email(user)

        kwargs = {
            'list_id': result['listId'],
            'subscribed': result['subscribed'],
            'verified': email.is_verified,
        }
        if not result['subscribed']:
            kwargs['unsubscribed_date'] = timezone.now()
        else:
            kwargs['subscribed_date'] = timezone.now()

        newsletter.create_or_update_subscription(user, **kwargs)
        return self.respond(status=204)
开发者ID:Kayle009,项目名称:sentry,代码行数:30,代码来源:user_subscriptions.py

示例7: serialize

 def serialize(self, obj, attrs, user):
     primary_email = UserEmail.get_primary_email(user)
     return {
         'email': obj.email,
         'isPrimary': obj.email == primary_email.email,
         'isVerified': obj.is_verified,
     }
开发者ID:Kayle009,项目名称:sentry,代码行数:7,代码来源:useremail.py

示例8: delete

    def delete(self, request, user):
        """
        Removes an email from account
        `````````````````````````````

        Removes an email from account, can not remove primary email

        :param string email: email to remove
        :auth required:
        """
        validator = EmailValidator(data=request.DATA)
        if not validator.is_valid():
            return self.respond(validator.errors, status=400)

        email = validator.object['email']
        primary_email = UserEmail.get_primary_email(user)
        del_email = UserEmail.objects.filter(user=user, email__iexact=email).first()

        # Don't allow deleting primary email?
        if primary_email == del_email:
            return self.respond({'detail': 'Cannot remove primary email'},
                                status=400)

        del_email.delete()

        logger.info(
            'user.email.remove',
            extra={
                'user_id': user.id,
                'ip_address': request.META['REMOTE_ADDR'],
                'email': email,
            }
        )

        return self.respond(status=204)
开发者ID:binlee1990,项目名称:sentry,代码行数:35,代码来源:user_emails.py

示例9: post

    def post(self, request, user):
        """
        Configure Newsletter Subscription
        `````````````````````````````````

        Update the default newsletter subscription.

        :param boolean subscribed: should be subscribed to newsletter
        :auth: required
        """
        validator = DefaultNewsletterValidator(data=request.DATA)
        if not validator.is_valid():
            return self.respond(validator.errors, status=400)

        result = validator.object
        email = UserEmail.get_primary_email(user)

        kwargs = {
            'subscribed': result['subscribed'],
            'verified': email.is_verified,
            'list_ids': newsletter.get_default_list_ids(),
        }
        if not result['subscribed']:
            kwargs['unsubscribed_date'] = timezone.now()
        else:
            kwargs['subscribed_date'] = timezone.now()

        newsletter.create_or_update_subscriptions(user, **kwargs)

        user.update(
            flags=F('flags').bitand(~User.flags.newsletter_consent_prompt),
        )

        return self.respond(status=204)
开发者ID:Kayle009,项目名称:sentry,代码行数:34,代码来源:user_subscriptions.py

示例10: test_assigns_author

    def test_assigns_author(self):
        group = self.create_group()
        user = self.create_user(name='Foo Bar', email='[email protected]', is_active=True)
        email = UserEmail.get_primary_email(user=user)
        email.is_verified = True
        email.save()
        repo = Repository.objects.create(
            name='example',
            organization_id=self.group.organization.id,
        )
        OrganizationMember.objects.create(organization=group.project.organization, user=user)
        commit = Commit.objects.create(
            key=sha1(uuid4().hex).hexdigest(),
            organization_id=group.organization.id,
            repository_id=repo.id,
            message='Foo Biz\n\nFixes {}'.format(group.qualified_short_id),
            author=CommitAuthor.objects.create(
                organization_id=group.organization.id,
                name=user.name,
                email=user.email,
            )
        )

        assert GroupCommitResolution.objects.filter(
            group_id=group.id,
            commit_id=commit.id,
        ).exists()

        assert GroupAssignee.objects.filter(
            group=group,
            user=user
        ).exists()
开发者ID:duanshuaimin,项目名称:sentry,代码行数:32,代码来源:test_releases.py

示例11: manage_subscriptions

def manage_subscriptions(request):
    user = request.user
    email = UserEmail.get_primary_email(user)

    if request.method == 'GET':
        context = csrf(request)
        context.update(
            {
                'page': 'subscriptions',
                'email': email,
                'AUTH_PROVIDERS': auth.get_auth_providers(),
                'has_newsletters': newsletter.is_enabled,
                'subscriptions': newsletter.get_subscriptions(user),
            }
        )
        return render_to_response('sentry/account/subscriptions.html', context, request)

    subscribed = request.POST.get('subscribed') == '1'
    try:
        list_id = int(request.POST.get('listId', ''))
    except ValueError:
        return HttpResponse('bad request', status=400)

    kwargs = {
        'list_id': list_id,
        'subscribed': subscribed,
        'verified': email.is_verified,
    }
    if not subscribed:
        kwargs['unsubscribed_date'] = timezone.now()
    else:
        kwargs['subscribed_date'] = timezone.now()

    newsletter.create_or_update_subscription(user, **kwargs)
    return HttpResponse()
开发者ID:hosmelq,项目名称:sentry,代码行数:35,代码来源:accounts.py

示例12: test_send_single_email

 def test_send_single_email(self, send_confirm_email):
     user = self.create_user('[email protected]')
     email = UserEmail.objects.create(user=user, email='[email protected]')
     email.save()
     self.login_as(user)
     self.client.post(reverse('sentry-account-confirm-email-send'),
                     data={'primary-email': '', 'email': '[email protected]'},
                     follow=True)
     send_confirm_email.assert_called_once_with(UserEmail.get_primary_email(user))
开发者ID:faulkner,项目名称:sentry,代码行数:9,代码来源:tests.py

示例13: test_get_user_from_email

    def test_get_user_from_email(self):
        user = User.objects.create(email='[email protected]')
        UserEmail.get_primary_email(user=user)
        project = self.create_project()
        self.create_member(user=user, organization=project.organization)
        release = Release.objects.create(
            organization_id=project.organization_id,
            version=uuid4().hex,
            new_groups=1,
        )
        release.add_project(project)
        commit_author = CommitAuthor.objects.create(
            name='stebe',
            email='[email protected]',
            organization_id=project.organization_id,
        )
        commit = Commit.objects.create(
            organization_id=project.organization_id,
            repository_id=1,
            key='abc',
            author=commit_author,
            message='waddap',
        )
        ReleaseCommit.objects.create(
            organization_id=project.organization_id,
            project_id=project.id,
            release=release,
            commit=commit,
            order=1,
        )
        release.update(
            authors=[six.text_type(commit_author.id)],
            commit_count=1,
            last_commit_id=commit.id,
        )

        result = serialize(release, user)
        result_author = result['authors'][0]
        assert int(result_author['id']) == user.id
        assert result_author['email'] == user.email
        assert result_author['username'] == user.username
开发者ID:Kayle009,项目名称:sentry,代码行数:41,代码来源:test_release.py

示例14: test_matching_author_with_assignment

    def test_matching_author_with_assignment(self):
        group = self.create_group()
        user = self.create_user(
            name='Foo Bar', email='[email protected]', is_active=True)
        email = UserEmail.get_primary_email(user=user)
        email.is_verified = True
        email.save()
        repo = Repository.objects.create(
            name='example',
            organization_id=self.group.organization.id,
        )
        OrganizationMember.objects.create(
            organization=group.project.organization, user=user)
        UserOption.objects.set_value(
            user=user,
            key='self_assign_issue',
            value='1'
        )

        commit = Commit.objects.create(
            key=sha1(uuid4().hex).hexdigest(),
            organization_id=group.organization.id,
            repository_id=repo.id,
            message=u'Foo Biz\n\nFixes {}'.format(group.qualified_short_id),
            author=CommitAuthor.objects.create(
                organization_id=group.organization.id,
                name=user.name,
                email=user.email,
            )
        )

        self.assertResolvedFromCommit(group, commit)

        assert GroupAssignee.objects.filter(group=group, user=user).exists()

        assert Activity.objects.filter(
            project=group.project,
            group=group,
            type=Activity.ASSIGNED,
            user=user,
        )[0].data == {
            'assignee': six.text_type(user.id),
            'assigneeEmail': user.email,
            'assigneeType': 'user',
        }

        assert GroupSubscription.objects.filter(
            group=group,
            user=user,
        ).exists()
开发者ID:Kayle009,项目名称:sentry,代码行数:50,代码来源:test_releases.py

示例15: __init__

    def __init__(self, user, list_id, list_name=None, list_description=None, email=None, verified=None, subscribed=False, subscribed_date=None, unsubscribed_date=None, **kwargs):
        from sentry.models import UserEmail

        self.email = user.email or email
        self.list_id = list_id
        self.list_description = list_description
        self.list_name = list_name
        # is the email address verified?
        self.verified = UserEmail.get_primary_email(user).is_verified if verified is None else verified
        # are they subscribed to ``list_id``
        self.subscribed = subscribed
        if subscribed:
            self.subscribed_date = subscribed_date or timezone.now()
        elif subscribed is False:
            self.unsubscribed_date = unsubscribed_date or timezone.now()
开发者ID:Kayle009,项目名称:sentry,代码行数:15,代码来源:dummy.py


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