email.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from django.conf import settings
  2. from glitchtip.email import DetailEmail
  3. from .models import Organization, OrganizationUser
  4. class ThrottleNoticeEmail(DetailEmail):
  5. html_template_name = "organizations/throttle-notice-drip.html"
  6. text_template_name = "organizations/throttle-notice-drip.txt"
  7. subject_template_name = "organizations/throttle-notice-drip-subject.txt"
  8. model = Organization
  9. def get_object(self, *args, **kwargs):
  10. return super().get_object(queryset=Organization.objects.with_event_counts())
  11. def get_email(self):
  12. return self.object.email
  13. def get_context_data(self, **kwargs):
  14. from djstripe.models import Product
  15. context = super().get_context_data(**kwargs)
  16. base_url = settings.GLITCHTIP_URL.geturl()
  17. faq_link = (
  18. settings.MARKETING_URL
  19. + "/documentation/frequently-asked-questions"
  20. + "#how-can-i-reduce-the-number-of-events-my-organization-is-using-each-month"
  21. )
  22. organization = self.object
  23. subscription_link = f"{base_url}/{organization.slug}/settings/subscription"
  24. product = Product.objects.filter(
  25. plan__subscriptions__customer__subscriber=organization,
  26. plan__subscriptions__status="active",
  27. ).first()
  28. context.update(
  29. {
  30. "organization": organization,
  31. "product": product,
  32. "event_limit": product.metadata.get("events") if product else None,
  33. "subscription_link": subscription_link,
  34. "faq_link": faq_link,
  35. }
  36. )
  37. return context
  38. class InvitationEmail(DetailEmail):
  39. html_template_name = "organizations/invite-user-drip.html"
  40. text_template_name = "organizations/invite-user-drip.txt"
  41. subject_template_name = "organizations/invite-user-drip-subject.txt"
  42. model = OrganizationUser
  43. def get_email(self):
  44. return self.object.email
  45. def get_context_data(self, **kwargs):
  46. context = super().get_context_data(**kwargs)
  47. org_user = context["object"]
  48. context["token"] = self.kwargs["token"]
  49. context["user"] = org_user
  50. context["organization"] = org_user.organization
  51. return context