From ed8858d23b52af59cbf2a46bbc678cef8ca3e368 Mon Sep 17 00:00:00 2001 From: Tanner Prestegard <tanner.prestegard@ligo.org> Date: Tue, 27 Dec 2016 10:03:32 -0600 Subject: [PATCH] some additional tweaks for contact test button --- userprofile/views.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/userprofile/views.py b/userprofile/views.py index 24ab56fb4..2ae22244b 100644 --- a/userprofile/views.py +++ b/userprofile/views.py @@ -167,30 +167,35 @@ def testContact(request, id): if request.user != c.user: return HttpResponseForbidden("NO!") else: - flash_msg = "Testing contact %s." % c.desc + flash_msg = 'Testing contact "{0}".'.format(c.desc) hostname = socket.gethostname() if c.email: # Send test e-mail try: - subject = "Test of contact %s from %s" % (c.desc, hostname) - message = ("This is test of contact %s on server %s," - " e-mailed to %s") % (c.desc, hostname, c.email) + subject = 'Test of contact "{0}" from {1}' \ + .format(c.desc, hostname) + message = ('This is test e-mail from https://{0}.ligo.org to' + ' verify your information for contact "{1}".') \ + .format(hostname, c.desc) email = EmailMessage(subject, message, settings.SERVER_EMAIL, [c.email], []) email.send() except: - flash_msg += " Error sending test e-mail to %s." % c.email + flash_msg += " Error sending test e-mail to {0}." \ + .format(c.email) if c.phone: # Send test phone alert try: + # Get "from" phone number. from_ = get_twilio_from() + # Construct URL of TwiML bin twiml_url = settings.TWIML_BASE_URL + settings.TWILIO_TEST_KEY - twiml_url += '?server={0}&type={1}'.format( - hostname,hostname.split('-')[1]) + twiml_url += "?server={0}".format(hostname) + # Make call twilio_client.calls.create(c.phone, from_, twiml_url, method='GET') - except Exception as e: - flash_msg += " Error calling %s." % e + except: + flash_msg += " Error calling {0}.".format(c.phone) request.session['flash_msg'] = flash_msg return index(request) -- GitLab