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


Python MagicMailBuilder.change_email方法代码示例

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


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

示例1: partial_update

# 需要导入模块: from djmail.template_mail import MagicMailBuilder [as 别名]
# 或者: from djmail.template_mail.MagicMailBuilder import change_email [as 别名]
    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,代码行数:40,代码来源:api.py

示例2: handle

# 需要导入模块: from djmail.template_mail import MagicMailBuilder [as 别名]
# 或者: from djmail.template_mail.MagicMailBuilder import change_email [as 别名]
    def handle(self, *args, **options):
        if len(args) != 1:
            print("Usage: ./manage.py test_emails <email-address>")
            return

        test_email = args[0]

        mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail)

        # Register email
        context = {"user": User.objects.all().order_by("?").first(), "cancel_token": "cancel-token"}
        email = mbuilder.registered_user(test_email, context)
        email.send()

        # Membership invitation
        context = {"membership": Membership.objects.order_by("?").filter(user__isnull=True).first()}
        email = mbuilder.membership_invitation(test_email, context)
        email.send()

        # Membership notification
        context = {"membership": Membership.objects.order_by("?").filter(user__isnull=False).first()}
        email = mbuilder.membership_notification(test_email, context)
        email.send()

        # Feedback
        context = {
            "feedback_entry": {
                "full_name": "Test full name",
                "email": "[email protected]",
                "comment": "Test comment",
            },
            "extra": {
                "key1": "value1",
                "key2": "value2",
            },
        }
        email = mbuilder.feedback_notification(test_email, context)
        email.send()

        # Password recovery
        context = {"user": User.objects.all().order_by("?").first()}
        email = mbuilder.password_recovery(test_email, context)
        email.send()

        # Change email
        context = {"user": User.objects.all().order_by("?").first()}
        email = mbuilder.change_email(test_email, context)
        email.send()

        # Notification emails
        notification_emails = [
            "issues/issue-change",
            "issues/issue-create",
            "issues/issue-delete",
            "milestones/milestone-change",
            "milestones/milestone-create",
            "milestones/milestone-delete",
            "projects/project-change",
            "projects/project-create",
            "projects/project-delete",
            "tasks/task-change",
            "tasks/task-create",
            "tasks/task-delete",
            "userstories/userstory-change",
            "userstories/userstory-create",
            "userstories/userstory-delete",
            "wiki/wikipage-change",
            "wiki/wikipage-create",
            "wiki/wikipage-delete",
        ]

        context = {
           "snapshot": HistoryEntry.objects.filter(is_snapshot=True).order_by("?")[0].snapshot,
           "project": Project.objects.all().order_by("?").first(),
           "changer": User.objects.all().order_by("?").first(),
           "history_entries": HistoryEntry.objects.all().order_by("?")[0:5],
           "user": User.objects.all().order_by("?").first(),
        }

        for notification_email in notification_emails:
            cls = type("InlineCSSTemplateMail", (InlineCSSTemplateMail,), {"name": notification_email})
            email = cls()
            email.send(test_email, context)
开发者ID:epintor,项目名称:taiga-back,代码行数:85,代码来源:test_emails.py

示例3: handle

# 需要导入模块: from djmail.template_mail import MagicMailBuilder [as 别名]
# 或者: from djmail.template_mail.MagicMailBuilder import change_email [as 别名]
    def handle(self, *args, **options):
        if len(args) != 1:
            print("Usage: ./manage.py test_emails <email-address>")
            return

        test_email = args[0]

        mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail)

        # Register email
        context = {"user": User.objects.all().order_by("?").first(), "cancel_token": "cancel-token"}
        email = mbuilder.registered_user(test_email, context)
        email.send()

        # Membership invitation
        membership = Membership.objects.order_by("?").filter(user__isnull=True).first()
        membership.invited_by = User.objects.all().order_by("?").first()
        membership.invitation_extra_text = "Text example, Text example,\nText example,\n\nText example"

        context = {"membership": membership}
        email = mbuilder.membership_invitation(test_email, context)
        email.send()

        # Membership notification
        context = {"membership": Membership.objects.order_by("?").filter(user__isnull=False).first()}
        email = mbuilder.membership_notification(test_email, context)
        email.send()

        # Feedback
        context = {
            "feedback_entry": {
                "full_name": "Test full name",
                "email": "[email protected]",
                "comment": "Test comment",
            },
            "extra": {
                "key1": "value1",
                "key2": "value2",
            },
        }
        email = mbuilder.feedback_notification(test_email, context)
        email.send()

        # Password recovery
        context = {"user": User.objects.all().order_by("?").first()}
        email = mbuilder.password_recovery(test_email, context)
        email.send()

        # Change email
        context = {"user": User.objects.all().order_by("?").first()}
        email = mbuilder.change_email(test_email, context)
        email.send()

        # Export/Import emails
        context = {
            "user": User.objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
            "error_subject": "Error generating project dump",
            "error_message": "Error generating project dump",
        }
        email = mbuilder.export_error(test_email, context)
        email.send()
        context = {
            "user": User.objects.all().order_by("?").first(),
            "error_subject": "Error importing project dump",
            "error_message": "Error importing project dump",
        }
        email = mbuilder.import_error(test_email, context)
        email.send()

        deletion_date = timezone.now() + datetime.timedelta(seconds=60*60*24)
        context = {
            "url": "http://dummyurl.com",
            "user": User.objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
            "deletion_date": deletion_date,
        }
        email = mbuilder.dump_project(test_email, context)
        email.send()

        context = {
            "user": User.objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
        }
        email = mbuilder.load_dump(test_email, context)
        email.send()

        # Notification emails
        notification_emails = [
            ("issues.Issue", "issues/issue-change"),
            ("issues.Issue", "issues/issue-create"),
            ("issues.Issue", "issues/issue-delete"),
            ("tasks.Task", "tasks/task-change"),
            ("tasks.Task", "tasks/task-create"),
            ("tasks.Task", "tasks/task-delete"),
            ("userstories.UserStory", "userstories/userstory-change"),
            ("userstories.UserStory", "userstories/userstory-create"),
            ("userstories.UserStory", "userstories/userstory-delete"),
            ("milestones.Milestone", "milestones/milestone-change"),
            ("milestones.Milestone", "milestones/milestone-create"),
#.........这里部分代码省略.........
开发者ID:FlorianBezagu,项目名称:taiga-back,代码行数:103,代码来源:test_emails.py


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