email.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from django.conf import settings
  2. from django.contrib.auth import get_user_model
  3. from glitchtip.email import GlitchTipEmail
  4. User = get_user_model()
  5. class AlertEmail(GlitchTipEmail):
  6. html_template_name = "alerts/issue.html"
  7. text_template_name = "alerts/issue.txt"
  8. subject_template_name = "alerts/issue-subject.txt"
  9. notification = None
  10. def get_context_data(self, **kwargs):
  11. context = super().get_context_data(**kwargs)
  12. notification = self.notification
  13. first_issue = notification.issues.all().first()
  14. base_url = settings.GLITCHTIP_URL.geturl()
  15. org_slug = first_issue.project.organization.slug
  16. issue_link = f"{base_url}/{org_slug}/issues/{first_issue.id}"
  17. settings_link = (
  18. f"{base_url}/{org_slug}/settings/projects/{first_issue.project.slug}"
  19. )
  20. context["issue_title"] = first_issue.title
  21. context["project_name"] = first_issue.project
  22. context["first_issue"] = first_issue
  23. context["issue_link"] = issue_link
  24. context["issues"] = notification.issues.all()
  25. context["issue_count"] = notification.issues.count()
  26. context["project_notification_settings_link"] = settings_link
  27. context["org_slug"] = org_slug
  28. context[
  29. "project_link"
  30. ] = f"{base_url}/{org_slug}/issues?project={first_issue.project.id}"
  31. return context
  32. def send_email_notification(notification):
  33. email = AlertEmail()
  34. email.notification = notification
  35. users = User.objects.alert_notification_recipients(notification)
  36. if not users.exists():
  37. return
  38. email.send_users_email(users)