• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.UnsubscribeCode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_correct_url_update_notification

    def test_correct_url_update_notification(self):
        # Make sure the user is subscribed
        perm_setting = email.NOTIFICATIONS[0]
        un = UserNotification.objects.create(notification_id=perm_setting.id,
                                             user=self.user_profile,
                                             enabled=True)

        # Create a URL
        token, hash = UnsubscribeCode.create(self.user.email)
        url = reverse('users.unsubscribe', args=[token, hash,
                                                 perm_setting.short])

        # Load the URL
        r = self.client.get(url)
        doc = pq(r.content)

        # Check that it was successful
        assert doc('#unsubscribe-success').length
        assert doc('#standalone').length
        eq_(doc('#standalone ul li').length, 1)

        # Make sure the user is unsubscribed
        un = UserNotification.objects.filter(notification_id=perm_setting.id,
                                             user=self.user)
        eq_(un.count(), 1)
        eq_(un.all()[0].enabled, False)
开发者ID:dimonov,项目名称:zamboni,代码行数:26,代码来源:test_views.py


示例2: test_wrong_url

    def test_wrong_url(self):
        perm_setting = email.NOTIFICATIONS[0]
        token, hash = UnsubscribeCode.create(self.user.email)
        hash = hash[::-1]  # Reverse the hash, so it's wrong

        url = reverse("users.unsubscribe", args=[token, hash, perm_setting.short])
        r = self.client.get(url)
        doc = pq(r.content)

        eq_(doc("#unsubscribe-fail").length, 1)
开发者ID:thefourtheye,项目名称:olympia,代码行数:10,代码来源:test_views.py


示例3: send_email

        if async:
            return send_email.delay(*args, **kwargs)
        else:
            return send_email(*args, **kwargs)

    if white_list:
        if perm_setting:
            html_template = loader.get_template('amo/emails/unsubscribe.html')
            text_template = loader.get_template('amo/emails/unsubscribe.ltxt')
            if not manage_url:
                manage_url = urlparams(absolutify(
                    reverse('users.edit', add_prefix=False)),
                    'acct-notify')
            for recipient in white_list:
                # Add unsubscribe link to footer.
                token, hash = UnsubscribeCode.create(recipient)
                unsubscribe_url = absolutify(
                    reverse('users.unsubscribe',
                            args=[token, hash, perm_setting.short],
                            add_prefix=False))

                context_options = {
                    'message': message,
                    'manage_url': manage_url,
                    'unsubscribe_url': unsubscribe_url,
                    'perm_setting': perm_setting.label,
                    'SITE_URL': settings.SITE_URL,
                    'mandatory': perm_setting.mandatory,
                }
                # Render this template in the default locale until
                # bug 635840 is fixed.
开发者ID:Nolski,项目名称:olympia,代码行数:31,代码来源:utils.py


示例4: send_mail

def send_mail(subject, message, from_email=None, recipient_list=None,
              fail_silently=False, use_blacklist=True, perm_setting=None,
              manage_url=None, headers=None, cc=None, real_email=False,
              html_message=None):
    """
    A wrapper around django.core.mail.EmailMessage.

    Adds blacklist checking and error logging.
    """
    from amo.helpers import absolutify
    import users.notifications as notifications
    if not recipient_list:
        return True

    if isinstance(recipient_list, basestring):
        raise ValueError('recipient_list should be a list, not a string.')

    connection = get_email_backend(real_email)

    # Check against user notification settings
    if perm_setting:
        if isinstance(perm_setting, str):
            perm_setting = notifications.NOTIFICATIONS_BY_SHORT[perm_setting]
        perms = dict(UserNotification.objects
                                     .filter(user__email__in=recipient_list,
                                             notification_id=perm_setting.id)
                                     .values_list('user__email', 'enabled'))

        d = perm_setting.default_checked
        recipient_list = [e for e in recipient_list
                          if e and perms.setdefault(e, d)]

    # Prune blacklisted emails.
    if use_blacklist:
        white_list = []
        for email in recipient_list:
            if email and email.lower() in settings.EMAIL_BLACKLIST:
                log.debug('Blacklisted email removed from list: %s' % email)
            else:
                white_list.append(email)
    else:
        white_list = recipient_list

    if not from_email:
        from_email = settings.DEFAULT_FROM_EMAIL
    cc = cc and [cc] or None
    if not headers:
        headers = {}

    def send(recipient, message, html_message=None):
        backend = EmailMultiAlternatives if html_message else EmailMessage

        result = backend(subject, message,
            from_email, recipient, cc=cc, connection=connection,
            headers=headers)

        if html_message:
            result.attach_alternative(html_message, 'text/html')

        try:
            result.send(fail_silently=False)
            return result
        except Exception as e:
            log.error('send_mail failed with error: %s' % e)
            if not fail_silently:
                raise
            return False

    if white_list:
        if perm_setting:
            html_template = loader.get_template('amo/emails/unsubscribe.html')
            text_template = loader.get_template('amo/emails/unsubscribe.ltxt')
            if not manage_url:
                manage_url = urlparams(absolutify(
                    reverse('users.edit', add_prefix=False)),
                    'acct-notify')
            for recipient in white_list:
                # Add unsubscribe link to footer.
                token, hash = UnsubscribeCode.create(recipient)
                unsubscribe_url = absolutify(reverse('users.unsubscribe',
                    args=[token, hash, perm_setting.short],
                    add_prefix=False))

                context = {
                    'message': message,
                    'manage_url': manage_url,
                    'unsubscribe_url': unsubscribe_url,
                    'perm_setting': perm_setting.label,
                    'SITE_URL': settings.SITE_URL,
                    'mandatory': perm_setting.mandatory
                }
                # Render this template in the default locale until
                # bug 635840 is fixed.
                with no_translation():
                    message_with_unsubscribe = text_template.render(
                        Context(context, autoescape=False))

                if html_message:
                    context['message'] = html_message
                    with no_translation():
#.........这里部分代码省略.........
开发者ID:bearstech,项目名称:zamboni,代码行数:101,代码来源:utils.py


示例5: send_mail

def send_mail(subject, message, from_email=None, recipient_list=None,
              fail_silently=False, use_blacklist=True, perm_setting=None,
              connection=None):
    """
    A wrapper around django.core.mail.send_mail.

    Adds blacklist checking and error logging.
    """
    if not recipient_list:
        return True

    if not from_email:
        from_email = settings.DEFAULT_FROM_EMAIL

    # Check against user notification settings
    if perm_setting:
        if isinstance(perm_setting, str):
            perm_setting = notifications.NOTIFICATIONS_BY_SHORT[perm_setting]
        perms = dict(UserNotification.objects
                                     .filter(user__email__in=recipient_list,
                                             notification_id=perm_setting.id)
                                     .values_list('user__email', 'enabled'))

        d = perm_setting.default_checked
        recipient_list = [e for e in recipient_list
                          if e and perms.setdefault(e, d)]

    # Prune blacklisted emails.
    if use_blacklist:
        white_list = []
        for email in recipient_list:
            if email and email.lower() in settings.EMAIL_BLACKLIST:
                log.debug('Blacklisted email removed from list: %s' % email)
            else:
                white_list.append(email)
    else:
        white_list = recipient_list

    try:
        if white_list:
            if perm_setting:
                template = loader.get_template('amo/emails/unsubscribe.ltxt')
                for recipient in white_list:
                    # Add unsubscribe link to footer
                    token, hash = UnsubscribeCode.create(recipient)
                    from amo.helpers import absolutify
                    url = absolutify(reverse('users.unsubscribe',
                            args=[token, hash, perm_setting.short]))
                    context = {'message': message, 'unsubscribe': url,
                               'perm_setting': perm_setting.label,
                               'SITE_URL': settings.SITE_URL}
                    send_message = template.render(Context(context,
                                                           autoescape=False))

                    result = django_send_mail(subject, send_message, from_email,
                                              [recipient], fail_silently=False,
                                              connection=connection)
            else:
                result = django_send_mail(subject, message, from_email,
                                          white_list, fail_silently=False,
                                          connection=connection)
        else:
            result = True
    except Exception as e:
        result = False
        log.error('send_mail failed with error: %s' % e)
        if not fail_silently:
            raise

    return result
开发者ID:chenba,项目名称:zamboni,代码行数:70,代码来源:utils.py


示例6: send_mail

def send_mail(
    subject,
    message,
    from_email=None,
    recipient_list=None,
    fail_silently=False,
    use_blacklist=True,
    perm_setting=None,
    headers=None,
    connection=None,
):
    """
    A wrapper around django.core.mail.EmailMessage.

    Adds blacklist checking and error logging.
    """
    import users.notifications as notifications

    if not recipient_list:
        return True

    if not from_email:
        from_email = settings.DEFAULT_FROM_EMAIL

    # Check against user notification settings
    if perm_setting:
        if isinstance(perm_setting, str):
            perm_setting = notifications.NOTIFICATIONS_BY_SHORT[perm_setting]
        perms = dict(
            UserNotification.objects.filter(
                user__email__in=recipient_list, notification_id=perm_setting.id
            ).values_list("user__email", "enabled")
        )

        d = perm_setting.default_checked
        recipient_list = [e for e in recipient_list if e and perms.setdefault(e, d)]

    # Prune blacklisted emails.
    if use_blacklist:
        white_list = []
        for email in recipient_list:
            if email and email.lower() in settings.EMAIL_BLACKLIST:
                log.debug("Blacklisted email removed from list: %s" % email)
            else:
                white_list.append(email)
    else:
        white_list = recipient_list

    try:
        if white_list:
            if perm_setting:
                template = loader.get_template("amo/emails/unsubscribe.ltxt")
                for recipient in white_list:
                    # Add unsubscribe link to footer
                    token, hash = UnsubscribeCode.create(recipient)
                    from amo.helpers import absolutify

                    unsubscribe_url = absolutify(reverse("users.unsubscribe", args=[token, hash, perm_setting.short]))
                    manage_url = urlparams(absolutify(reverse("users.edit")), "acct-notify")

                    context = {
                        "message": message,
                        "manage_url": manage_url,
                        "unsubscribe_url": unsubscribe_url,
                        "perm_setting": perm_setting.label,
                        "SITE_URL": settings.SITE_URL,
                        "mandatory": perm_setting.mandatory,
                    }
                    # Render this template in the default locale until
                    # bug 635840 is fixed.
                    with no_translation():
                        send_message = template.render(Context(context, autoescape=False))

                        result = EmailMessage(
                            subject, send_message, from_email, [recipient], connection=connection, headers=headers or {}
                        ).send(fail_silently=False)
            else:
                result = EmailMessage(
                    subject, message, from_email, white_list, connection=connection, headers=headers or {}
                ).send(fail_silently=False)
        else:
            result = True
    except Exception as e:
        result = False
        log.error("send_mail failed with error: %s" % e)
        if not fail_silently:
            raise

    return result
开发者ID:vaidik,项目名称:zamboni,代码行数:89,代码来源:utils.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python views._login函数代码示例发布时间:2022-05-27
下一篇:
Python utils.handle_register函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap