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


Python template_mail.MagicMailBuilder类代码示例

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


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

示例1: dump_project

def dump_project(self, user, project):
    mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail)
    path = "exports/{}/{}-{}.json".format(project.pk, project.slug, self.request.id)

    try:
        content = ExportRenderer().render(project_to_dict(project), renderer_context={"indent": 4})
        content = content.decode('utf-8')
        content = ContentFile(content)

        default_storage.save(path, content)
        url = default_storage.url(path)
    except Exception:
        ctx = {
            "user": user,
            "error_subject": _("Error generating project dump"),
            "error_message": _("Error generating project dump"),
            "project": project
        }
        email = mbuilder.export_error(user, ctx)
        email.send()
        logger.error('Error generating dump %s (by %s)', project.slug, user, exc_info=sys.exc_info())
        return

    deletion_date = timezone.now() + datetime.timedelta(seconds=settings.EXPORTS_TTL)
    ctx = {
        "url": url,
        "project": project,
        "user": user,
        "deletion_date": deletion_date
    }
    email = mbuilder.dump_project(user, ctx)
    email.send()
开发者ID:niibruce,项目名称:taiga-back,代码行数:32,代码来源:tasks.py

示例2: dump_project

def dump_project(self, user, project):
    mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail)
    path = "exports/{}/{}-{}.json".format(project.pk, project.slug, self.request.id)
    storage_path = default_storage.path(path)

    try:
        url = default_storage.url(path)
        with default_storage.open(storage_path, mode="w") as outfile:
            render_project(project, outfile)

    except Exception:
        ctx = {
            "user": user,
            "error_subject": _("Error generating project dump"),
            "error_message": _("Error generating project dump"),
            "project": project
        }
        email = mbuilder.export_error(user, ctx)
        email.send()
        logger.error('Error generating dump %s (by %s)', project.slug, user, exc_info=sys.exc_info())
        return

    deletion_date = timezone.now() + datetime.timedelta(seconds=settings.EXPORTS_TTL)
    ctx = {
        "url": url,
        "project": project,
        "user": user,
        "deletion_date": deletion_date
    }
    email = mbuilder.dump_project(user, ctx)
    email.send()
开发者ID:WALR,项目名称:taiga-back,代码行数:31,代码来源:tasks.py

示例3: send_feedback

def send_feedback(feedback_entry, extra):
    support_email = settings.FEEDBACK_EMAIL

    if support_email:
        mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail)
        email = mbuilder.feedback_notification(support_email, {"feedback_entry": feedback_entry,
                                                               "extra": extra})
        email.send()
开发者ID:epintor,项目名称:taiga-back,代码行数:8,代码来源:services.py

示例4: send_public_register_email

def send_public_register_email(user) -> bool:
    """
    Given a user, send public register welcome email
    message to specified user.
    """

    context = {"user": user}
    mbuilder = MagicMailBuilder()
    email = mbuilder.public_register_user(user.email, context)
    return bool(email.send())
开发者ID:yamila-moreno,项目名称:taiga-back,代码行数:10,代码来源:services.py

示例5: send_register_email

def send_register_email(user) -> bool:
    """
    Given a user, send register welcome email
    message to specified user.
    """
    cancel_token = get_token_for_user(user, "cancel_account")
    context = {"user": user, "cancel_token": cancel_token}
    mbuilder = MagicMailBuilder()
    email = mbuilder.registered_user(user.email, context)
    return bool(email.send())
开发者ID:BWStearns,项目名称:taiga-back,代码行数:10,代码来源:services.py

示例6: post_save

    def post_save(self, object, created=False):
        super().post_save(object, created=created)

        if not created:
            return

        # Send email only if a new membership is created
        mbuilder = MagicMailBuilder()
        email = mbuilder.membership_invitation(object.email, {"membership": object})
        email.send()
开发者ID:niwinz,项目名称:taiga-back,代码行数:10,代码来源:api.py

示例7: send_private_register_email

def send_private_register_email(user, **kwargs) -> bool:
    """
    Given a user, send private register welcome
    email message to specified user.
    """
    context = {"user": user}
    context.update(kwargs)

    mbuilder = MagicMailBuilder()
    email = mbuilder.private_register_user(user.email, context)
    return bool(email.send())
开发者ID:yamila-moreno,项目名称:taiga-back,代码行数:11,代码来源:services.py

示例8: test_simple_send_email_with_magic_builder_1

    def test_simple_send_email_with_magic_builder_1(self):
        mails = MagicMailBuilder()

        email = mails.test_email2('[email protected]', {'name': 'foo'})
        email.send()

        model = Message.objects.get()
        self.assertEqual(email.from_email, model.from_email)
        self.assertEqual(email.to, model.to_email.split(','))
        self.assertEqual(email.subject, model.subject)
        self.assertEqual(email.body, model.body_text)
开发者ID:bameda,项目名称:djmail,代码行数:11,代码来源:tests.py

示例9: test_simple_send_email_with_magic_builder_1_with_extra_kwargs

    def test_simple_send_email_with_magic_builder_1_with_extra_kwargs(self):
        mails = MagicMailBuilder()

        email = mails.test_email2(
            "[email protected]", {"name": "foo"}, from_email="[email protected]")
        email.send()

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(Message.objects.count(), 1)

        self.assertEqual(email.subject, 'Subject2: foo')
        self.assertEqual(email.body, 'body\n')
        self.assertEqual(email.alternatives, [(u'<b>Body</b>\n', 'text/html')])
开发者ID:bameda,项目名称:djmail,代码行数:13,代码来源:tests.py

示例10: send_feedback

def send_feedback(feedback_entry, extra, reply_to=[]):
    support_email = settings.FEEDBACK_EMAIL

    if support_email:
        reply_to.append(support_email)

        ctx = {
            "feedback_entry": feedback_entry,
            "extra": extra
        }

        mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail)
        email = mbuilder.feedback_notification(support_email, ctx)
        email.extra_headers["Reply-To"] = ", ".join(reply_to)
        email.send()
开发者ID:FlorianBezagu,项目名称:taiga-back,代码行数:15,代码来源:services.py

示例11: load_project_dump

def load_project_dump(user, dump):
    mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail)

    try:
        project = dict_to_project(dump, user.email)
    except Exception:
        ctx = {
            "user": user,
            "error_subject": "Error loading project dump",
            "error_message": "Error loading project dump",
        }
        email = mbuilder.import_error(user.email, ctx)
        email.send()
        return

    ctx = {"user": user, "project": project}
    email = mbuilder.load_dump(user.email, ctx)
    email.send()
开发者ID:david-strejc,项目名称:taiga-back,代码行数:18,代码来源:tasks.py

示例12: load_project_dump

def load_project_dump(user, dump):
    mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail)

    try:
        project = dict_to_project(dump, user.email)
    except Exception:
        ctx = {
            "user": user,
            "error_subject": _("Error loading project dump"),
            "error_message": _("Error loading project dump"),
        }
        email = mbuilder.import_error(user, ctx)
        email.send()
        logger.error('Error loading dump %s (by %s)', project.slug, user, exc_info=sys.exc_info())
        return

    ctx = {"user": user, "project": project}
    email = mbuilder.load_dump(user, ctx)
    email.send()
开发者ID:WALR,项目名称:taiga-back,代码行数:19,代码来源:tasks.py

示例13: password_recovery

    def password_recovery(self, request, pk=None):
        username_or_email = request.DATA.get('username', None)

        if not username_or_email:
            raise exc.WrongArguments(_("Invalid username or email"))

        try:
            queryset = User.objects.all()
            user = queryset.get(Q(username=username_or_email) |
                                    Q(email=username_or_email))
        except User.DoesNotExist:
            raise exc.WrongArguments(_("Invalid username or email"))

        user.token = str(uuid.uuid1())
        user.save(update_fields=["token"])

        mbuilder = MagicMailBuilder()
        email = mbuilder.password_recovery(user.email, {"user": user})
        email.send()

        return Response({"detail": _("Mail sended successful!")})
开发者ID:niwinz,项目名称:taiga-back,代码行数:21,代码来源:api.py

示例14: test_simple_send_email_with_magic_builder_1_with_low_priority

    def test_simple_send_email_with_magic_builder_1_with_low_priority(self):
        mails = MagicMailBuilder()

        email = mails.test_email2(
            '[email protected]', {'name': 'foo'}, priority=10)
        email.send()

        self.assertEqual(len(mail.outbox), 0)
        self.assertEqual(Message.objects.count(), 1)

        m1 = Message.objects.get()
        self.assertEqual(m1.status, Message.STATUS_PENDING)
        self.assertEqual(m1.priority, 10)

        core._send_pending_messages()

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(Message.objects.count(), 1)

        m2 = Message.objects.get()
        self.assertEqual(m2.status, Message.STATUS_SENT)
        self.assertEqual(m2.priority, 10)
开发者ID:bameda,项目名称:djmail,代码行数:22,代码来源:tests.py

示例15: partial_update

    def partial_update(self, request, *args, **kwargs):
        """
        We must detect if the user is trying to change his email so we can
        save that value and generate a token that allows him to validate it in
        the new email account
        """
        user = self.get_object()
        self.check_permissions(request, "update", user)

        ret = super(UsersViewSet, self).partial_update(request, *args, **kwargs)

        new_email = request.DATA.get('email', None)
        if new_email is not None:
            valid_new_email = True
            duplicated_email = models.User.objects.filter(email = new_email).exists()

            try:
                validate_email(new_email)
            except ValidationError:
                valid_new_email = False

            valid_new_email = valid_new_email and new_email != request.user.email

            if duplicated_email:
                raise exc.WrongArguments(_("Duplicated email"))
            elif not valid_new_email:
                raise exc.WrongArguments(_("Not valid email"))

            #We need to generate a token for the email
            request.user.email_token = str(uuid.uuid1())
            request.user.new_email = new_email
            request.user.save(update_fields=["email_token", "new_email"])
            mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail)
            email = mbuilder.change_email(request.user.new_email, {"user": request.user,
                                                                   "lang": request.user.lang})
            email.send()

        return ret
开发者ID:Sheshtawy,项目名称:taiga-back,代码行数:38,代码来源:api.py


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