本文整理汇总了Python中djmail.template_mail.MagicMailBuilder.dump_project方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMailBuilder.dump_project方法的具体用法?Python MagicMailBuilder.dump_project怎么用?Python MagicMailBuilder.dump_project使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类djmail.template_mail.MagicMailBuilder
的用法示例。
在下文中一共展示了MagicMailBuilder.dump_project方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dump_project
# 需要导入模块: from djmail.template_mail import MagicMailBuilder [as 别名]
# 或者: from djmail.template_mail.MagicMailBuilder import dump_project [as 别名]
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()
示例2: dump_project
# 需要导入模块: from djmail.template_mail import MagicMailBuilder [as 别名]
# 或者: from djmail.template_mail.MagicMailBuilder import dump_project [as 别名]
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()
示例3: handle
# 需要导入模块: from djmail.template_mail import MagicMailBuilder [as 别名]
# 或者: from djmail.template_mail.MagicMailBuilder import dump_project [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"),
#.........这里部分代码省略.........