email.py 1.1 KB

123456789101112131415161718192021222324252627
  1. from django.conf import settings
  2. from djstripe.models import Subscription
  3. from glitchtip.email import DetailEmail
  4. class WarnQuotaEmail(DetailEmail):
  5. html_template_name = "djstripe_ext/near-quota-drip.html"
  6. text_template_name = "djstripe_ext/near-quota-drip.txt"
  7. subject_template_name = "djstripe_ext/near-quota-drip-subject.txt"
  8. model = Subscription
  9. event_count = None
  10. def get_email(self):
  11. return self.object.customer.subscriber.email
  12. def get_context_data(self, **kwargs):
  13. context = super().get_context_data(**kwargs)
  14. base_url = settings.GLITCHTIP_URL.geturl()
  15. subscription = context["object"]
  16. organization = subscription.customer.subscriber
  17. plan_event_count = subscription.plan.product.metadata.get("events")
  18. subscription_link = f"{base_url}/{organization.slug}/settings/subscription"
  19. context["organization"] = organization.name
  20. context["plan_event_count"] = plan_event_count
  21. context["event_count"] = self.event_count
  22. context["subscription_link"] = subscription_link
  23. return context