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


Python UserEmail.get_primary_email方法代码示例

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


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

示例1: account_settings

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
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,代码行数:56,代码来源:accounts.py

示例2: delete

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
    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,代码行数:37,代码来源:user_emails.py

示例3: post

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
    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,代码行数:36,代码来源:user_subscriptions.py

示例4: put

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
    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,代码行数:32,代码来源:user_subscriptions.py

示例5: manage_subscriptions

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
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,代码行数:37,代码来源:accounts.py

示例6: test_assigns_author

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
    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,代码行数:34,代码来源:test_releases.py

示例7: serialize

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
 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,代码行数:9,代码来源:useremail.py

示例8: test_send_single_email

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
 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,代码行数:11,代码来源:tests.py

示例9: test_get_user_from_email

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
    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,代码行数:43,代码来源:test_release.py

示例10: test_matching_author_with_assignment

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
    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,代码行数:52,代码来源:test_releases.py

示例11: __init__

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
    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,代码行数:17,代码来源:dummy.py

示例12: test_assigns_author

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
    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=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,
            )
        )

        assert GroupLink.objects.filter(
            group_id=group.id,
            linked_type=GroupLink.LinkedType.commit,
            linked_id=commit.id).exists()

        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',
        }
开发者ID:alexandrul,项目名称:sentry,代码行数:44,代码来源:test_releases.py

示例13: show_emails

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
def show_emails(request):
    user = request.user
    emails = user.emails.all()
    email_form = EmailForm(user, request.POST or None)
    primary_email = UserEmail.get_primary_email(user)
    alt_emails = emails.exclude(email=primary_email.email)

    if 'remove' in request.POST:
        email = request.POST.get('email')
        del_email = UserEmail.objects.filter(user=user, email=email)
        del_email.delete()
        logger.info(
            'user.email.remove',
            extra={
                'user_id': user.id,
                'ip_address': request.META['REMOTE_ADDR'],
                'email': email,
            }
        )
        user.clear_lost_passwords()
        return HttpResponseRedirect(request.path)

    if 'primary' in request.POST:
        new_primary = request.POST['new_primary_email'].lower().strip()

        if User.objects.filter(Q(email__iexact=new_primary) | Q(username__iexact=new_primary)
                               ).exclude(id=user.id).exists():
            messages.add_message(
                request, messages.ERROR, _("That email is already in use for another user")
            )

        elif new_primary != user.email:
            new_primary_email = UserEmail.objects.get(user=user, email__iexact=new_primary)
            if not new_primary_email.is_verified:
                messages.add_message(
                    request, messages.ERROR, _(
                        "Cannot make an unverified address your primary email")
                )
                return HttpResponseRedirect(request.path)
            # update notification settings for those set to primary email with new primary email
            alert_email = UserOption.objects.get_value(user=user, key='alert_email')

            if alert_email == user.email:
                UserOption.objects.set_value(user=user, key='alert_email', value=new_primary)
            options = UserOption.objects.filter(user=user, key='mail:email')
            for option in options:
                if option.value != user.email:
                    continue
                option.value = new_primary
                option.save()

            has_new_username = user.email == user.username

            user.email = new_primary

            msg = _('Your settings were saved')
            messages.add_message(request, messages.SUCCESS, msg)

            if has_new_username and not User.objects.filter(username__iexact=new_primary).exists():
                user.username = user.email
            user.save()
        user.clear_lost_passwords()
        return HttpResponseRedirect(request.path)

    if email_form.is_valid():

        alternative_email = email_form.cleaned_data['alt_email'].lower().strip()

        # check if this alternative email already exists for user
        if alternative_email and not UserEmail.objects.filter(
            user=user, email__iexact=alternative_email
        ).exists():
            # create alternative email for user
            try:
                with transaction.atomic():
                    new_email = UserEmail.objects.create(user=user, email=alternative_email)
            except IntegrityError:
                pass
            else:
                new_email.set_hash()
                new_email.save()
                user.send_confirm_email_singular(new_email)

                logger.info(
                    'user.email.add',
                    extra={
                        'user_id': user.id,
                        'ip_address': request.META['REMOTE_ADDR'],
                        'email': new_email.email,
                    }
                )
                msg = _('A confirmation email has been sent to %s.') % new_email.email
                messages.add_message(request, messages.SUCCESS, msg)

        user.clear_lost_passwords()

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

    context = csrf(request)
#.........这里部分代码省略.........
开发者ID:hosmelq,项目名称:sentry,代码行数:103,代码来源:accounts.py

示例14: show_emails

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
def show_emails(request):
    user = request.user
    primary_email = UserEmail.get_primary_email(user)
    alt_emails = user.emails.all().exclude(email=primary_email.email)

    email_form = EmailForm(user, request.POST or None,
        initial={
            'primary_email': primary_email.email,
        },
    )

    if 'remove' in request.POST:
        email = request.POST.get('email')
        del_email = UserEmail.objects.filter(user=user, email=email)
        del_email.delete()
        return HttpResponseRedirect(request.path)

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

        email_form.save()

        if user.email != old_email:
            useroptions = UserOption.objects.filter(user=user, value=old_email)
            for option in useroptions:
                option.value = user.email
                option.save()
            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_emails()
        alternative_email = email_form.cleaned_data['alt_email']
        # check if this alternative email already exists for user
        if alternative_email and not UserEmail.objects.filter(user=user, email=alternative_email):
            # create alternative email for user
            try:
                with transaction.atomic():
                    new_email = UserEmail.objects.create(
                        user=user,
                        email=alternative_email
                    )
            except IntegrityError:
                pass
            else:
                new_email.set_hash()
                new_email.save()
            # send confirmation emails to any non verified emails
            user.send_confirm_emails()

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

    context = csrf(request)
    context.update({
        'email_form': email_form,
        'primary_email': primary_email,
        'alt_emails': alt_emails,
        'page': 'emails',
        'AUTH_PROVIDERS': auth.get_auth_providers(),
    })
    return render_to_response('sentry/account/emails.html', context, request)
开发者ID:ollie314,项目名称:sentry,代码行数:73,代码来源:accounts.py

示例15: show_emails

# 需要导入模块: from sentry.models import UserEmail [as 别名]
# 或者: from sentry.models.UserEmail import get_primary_email [as 别名]
def show_emails(request):
    user = request.user
    primary_email = UserEmail.get_primary_email(user)
    alt_emails = user.emails.all().exclude(email=primary_email.email)

    email_form = EmailForm(user, request.POST or None,
        initial={
            'primary_email': primary_email.email,
        },
    )

    if 'remove' in request.POST:
        email = request.POST.get('email')
        del_email = UserEmail.objects.filter(user=user, email=email)
        del_email.delete()
        logger.info('user.email.remove', extra={
            'user_id': user.id,
            'ip_address': request.META['REMOTE_ADDR'],
            'email': email,
        })

        return HttpResponseRedirect(request.path)

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

        email_form.save()

        if user.email != old_email:
            useroptions = UserOption.objects.filter(user=user, value=old_email)
            for option in useroptions:
                option.value = user.email
                option.save()
            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)
                # Update newsletter subscription and mark as unverified
                newsletter.update_subscription(
                    user=user,
                    verified=False,
                )
                logger.info('user.email.add', extra={
                    'user_id': user.id,
                    'ip_address': request.META['REMOTE_ADDR'],
                    'email': user_email.email,
                })
                msg = _('A confirmation email has been sent to %s.') % user_email.email
                messages.add_message(
                    request,
                    messages.SUCCESS,
                    msg)
        alternative_email = email_form.cleaned_data['alt_email']
        # check if this alternative email already exists for user
        if alternative_email and not UserEmail.objects.filter(user=user, email=alternative_email):
            # create alternative email for user
            try:
                with transaction.atomic():
                    new_email = UserEmail.objects.create(
                        user=user,
                        email=alternative_email
                    )
            except IntegrityError:
                pass
            else:
                new_email.set_hash()
                new_email.save()
            # send confirmation emails to any non verified emails
            user.send_confirm_email_singular(new_email)
            logger.info('user.email.add', extra={
                'user_id': user.id,
                'ip_address': request.META['REMOTE_ADDR'],
                'email': new_email.email,
            })
            msg = _('A confirmation email has been sent to %s.') % new_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({
        'email_form': email_form,
        'primary_email': primary_email,
        'alt_emails': alt_emails,
        'page': 'emails',
        'AUTH_PROVIDERS': auth.get_auth_providers(),
#.........这里部分代码省略.........
开发者ID:faulkner,项目名称:sentry,代码行数:103,代码来源:accounts.py


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