1. Luke Plant
  2. django-piston

Commits

Joe Stump  committed 5ad118e

- Fail silently if email templates are not present.
- Don't send email to admins if there are no settings.ADMINS.

  • Participants
  • Parent commits 9c00773
  • Branches default

Comments (0)

Files changed (1)

File piston/utils.py

View file
 from django.core.mail import send_mail, mail_admins
 from django.conf import settings
 from django.utils.translation import ugettext as _
-from django.template import loader
+from django.template import loader, TemplateDoesNotExist
 from django.contrib.sites.models import Site
 from decorator import decorator
 
 
     template = "piston/mails/consumer_%s.txt" % consumer.status    
     
-    body = loader.render_to_string(template, 
-        { 'consumer' : consumer, 'user' : consumer.user })
+    try:
+        body = loader.render_to_string(template, 
+            { 'consumer' : consumer, 'user' : consumer.user })
+    except TemplateDoesNotExist:
+        """ 
+        They haven't set up the templates, which means they might not want
+        these emails sent.
+        """
+        return 
 
     try:
         sender = settings.PISTON_FROM_EMAIL
 
     send_mail(_(subject), body, sender, [consumer.user.email], fail_silently=True)
 
-    if consumer.status == 'pending':
+    if consumer.status == 'pending' and len(settings.ADMINS):
         mail_admins(_(subject), body, fail_silently=True)
 
     if settings.DEBUG: