Skip to content

Commit

Permalink
Show an error message if proposal approval notification fails to send
Browse files Browse the repository at this point in the history
  • Loading branch information
eheinrich committed Jun 12, 2019
1 parent 0fa36a2 commit 5056f75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion observation_portal/sciapplications/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,15 @@ def port(self, request, queryset):
request, 'Application {} has no approved Time Allocations'.format(app.title), level='ERROR'
)
return
app.send_approved_notification()
self.message_user(request, 'Proposal {} successfully created.'.format(app.proposal))

notification_sent = app.send_approved_notification()
if not notification_sent:
self.message_user(
request,
'Email notifying PI of approval of proposal {} failed to send'.format(app.proposal),
level='ERROR'
)
return

admin.site.register(ScienceApplication, ScienceApplicationAdmin)
11 changes: 9 additions & 2 deletions observation_portal/sciapplications/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import io
import smtplib

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
Expand All @@ -7,7 +10,6 @@
from django.contrib.staticfiles import finders
from weasyprint import HTML, CSS
from PyPDF2 import PdfFileMerger
import io

from observation_portal.accounts.tasks import send_mail
from observation_portal.proposals.models import (
Expand Down Expand Up @@ -214,7 +216,12 @@ def send_approved_notification(self):
# the proposal might not be set yet if the pi has not a registered an account. In that case, use the email
# as set on the science application.
pi_email = self.proposal.pi.email if self.proposal.pi else self.pi
send_mail.send(subject, message, 'portal@lco.global', [pi_email])
email_sent = True
try:
send_mail.send(subject, message, 'portal@lco.global', [pi_email])
except smtplib.SMTPException:
email_sent = False
return email_sent


class TimeRequest(models.Model):
Expand Down

0 comments on commit 5056f75

Please sign in to comment.