mirror of
https://github.com/ansible/awx.git
synced 2026-01-18 13:11:19 -03:30
Fixing up some unicode issues
This commit is contained in:
parent
75ef0dd395
commit
4b1493f456
@ -2,6 +2,8 @@
|
||||
# All Rights Reserved.
|
||||
|
||||
import pprint
|
||||
|
||||
from django.utils.encoding import smart_text
|
||||
from django.core.mail.backends.base import BaseEmailBackend
|
||||
|
||||
class TowerBaseEmailBackend(BaseEmailBackend):
|
||||
@ -10,9 +12,9 @@ class TowerBaseEmailBackend(BaseEmailBackend):
|
||||
if "body" in body:
|
||||
body_actual = body['body']
|
||||
else:
|
||||
body_actual = "{} #{} had status {} on Ansible Tower, view details at {}\n\n".format(body['friendly_name'],
|
||||
body['id'],
|
||||
body['status'],
|
||||
body['url'])
|
||||
body_actual = smart_text("{} #{} had status {} on Ansible Tower, view details at {}\n\n".format(body['friendly_name'],
|
||||
body['id'],
|
||||
body['status'],
|
||||
body['url']))
|
||||
body_actual += pprint.pformat(body, indent=4)
|
||||
return body_actual
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from django.utils.encoding import smart_text
|
||||
from django.core.mail.backends.smtp import EmailBackend
|
||||
|
||||
class CustomEmailBackend(EmailBackend):
|
||||
@ -19,9 +20,9 @@ class CustomEmailBackend(EmailBackend):
|
||||
sender_parameter = "sender"
|
||||
|
||||
def format_body(self, body):
|
||||
body_actual = "{} #{} had status {} on Ansible Tower, view details at {}\n\n".format(body['friendly_name'],
|
||||
body['id'],
|
||||
body['status'],
|
||||
body['url'])
|
||||
body_actual = smart_text("{} #{} had status {} on Ansible Tower, view details at {}\n\n".format(body['friendly_name'],
|
||||
body['id'],
|
||||
body['status'],
|
||||
body['url']))
|
||||
body_actual += pprint.pformat(body, indent=4)
|
||||
return body_actual
|
||||
|
||||
@ -5,6 +5,8 @@ import logging
|
||||
|
||||
import requests
|
||||
|
||||
from django.utils.encoding import smart_text
|
||||
|
||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||
|
||||
logger = logging.getLogger('awx.main.notifications.hipchat_backend')
|
||||
@ -40,8 +42,8 @@ class HipChatBackend(TowerBaseEmailBackend):
|
||||
"from": m.from_email,
|
||||
"message_format": "text"})
|
||||
if r.status_code != 204:
|
||||
logger.error("Error sending messages: {}".format(r.text))
|
||||
logger.error(smart_text("Error sending messages: {}".format(r.text)))
|
||||
if not self.fail_silently:
|
||||
raise Exception("Error sending message to hipchat: {}".format(r.text))
|
||||
raise Exception(smart_text("Error sending message to hipchat: {}".format(r.text)))
|
||||
sent_messages += 1
|
||||
return sent_messages
|
||||
|
||||
@ -7,6 +7,8 @@ import logging
|
||||
|
||||
import irc.client
|
||||
|
||||
from django.utils.encoding import smart_text
|
||||
|
||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||
|
||||
logger = logging.getLogger('awx.main.notifications.irc_backend')
|
||||
@ -48,7 +50,7 @@ class IrcBackend(TowerBaseEmailBackend):
|
||||
connect_factory=connection_factory,
|
||||
)
|
||||
except irc.client.ServerConnectionError as e:
|
||||
logger.error("Exception connecting to irc server: {}".format(e))
|
||||
logger.error(smart_text("Exception connecting to irc server: {}".format(e)))
|
||||
if not self.fail_silently:
|
||||
raise
|
||||
return True
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
import logging
|
||||
import pygerduty
|
||||
|
||||
from django.utils.encoding import smart_text
|
||||
|
||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||
|
||||
logger = logging.getLogger('awx.main.notifications.pagerduty_backend')
|
||||
@ -33,7 +35,7 @@ class PagerDutyBackend(TowerBaseEmailBackend):
|
||||
except Exception as e:
|
||||
if not self.fail_silently:
|
||||
raise
|
||||
logger.error("Exception connecting to PagerDuty: {}".format(e))
|
||||
logger.error(smart_text("Exception connecting to PagerDuty: {}".format(e)))
|
||||
for m in messages:
|
||||
try:
|
||||
pager.trigger_incident(m.recipients()[0],
|
||||
@ -41,7 +43,7 @@ class PagerDutyBackend(TowerBaseEmailBackend):
|
||||
details=m.body,
|
||||
client=m.from_email)
|
||||
except Exception as e:
|
||||
logger.error("Exception sending messages: {}".format(e))
|
||||
logger.error(smart_text("Exception sending messages: {}".format(e)))
|
||||
if not self.fail_silently:
|
||||
raise
|
||||
return sent_messages
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
import logging
|
||||
from slackclient import SlackClient
|
||||
|
||||
from django.utils.encoding import smart_text
|
||||
|
||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||
|
||||
logger = logging.getLogger('awx.main.notifications.slack_backend')
|
||||
@ -44,7 +46,7 @@ class SlackBackend(TowerBaseEmailBackend):
|
||||
self.connection.rtm_send_message(r, m.subject)
|
||||
sent_messages += 1
|
||||
except Exception as e:
|
||||
logger.error("Exception sending messages: {}".format(e))
|
||||
logger.error(smart_text("Exception sending messages: {}".format(e)))
|
||||
if not self.fail_silently:
|
||||
raise
|
||||
return sent_messages
|
||||
|
||||
@ -5,6 +5,8 @@ import logging
|
||||
|
||||
from twilio.rest import TwilioRestClient
|
||||
|
||||
from django.utils.encoding import smart_text
|
||||
|
||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||
|
||||
logger = logging.getLogger('awx.main.notifications.twilio_backend')
|
||||
@ -31,7 +33,7 @@ class TwilioBackend(TowerBaseEmailBackend):
|
||||
except Exception as e:
|
||||
if not self.fail_silently:
|
||||
raise
|
||||
logger.error("Exception connecting to Twilio: {}".format(e))
|
||||
logger.error(smart_text("Exception connecting to Twilio: {}".format(e)))
|
||||
|
||||
for m in messages:
|
||||
try:
|
||||
@ -41,7 +43,7 @@ class TwilioBackend(TowerBaseEmailBackend):
|
||||
body=m.subject)
|
||||
sent_messages += 1
|
||||
except Exception as e:
|
||||
logger.error("Exception sending messages: {}".format(e))
|
||||
logger.error(smart_text("Exception sending messages: {}".format(e)))
|
||||
if not self.fail_silently:
|
||||
raise
|
||||
return sent_messages
|
||||
|
||||
@ -2,9 +2,11 @@
|
||||
# All Rights Reserved.
|
||||
|
||||
import logging
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
from django.utils.encoding import smart_text
|
||||
|
||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||
|
||||
logger = logging.getLogger('awx.main.notifications.webhook_backend')
|
||||
@ -30,8 +32,8 @@ class WebhookBackend(TowerBaseEmailBackend):
|
||||
data=json.dumps(m.body),
|
||||
headers=self.headers)
|
||||
if r.status_code >= 400:
|
||||
logger.error("Error sending notification webhook: {}".format(r.text))
|
||||
logger.error(smart_text("Error sending notification webhook: {}".format(r.text)))
|
||||
if not self.fail_silently:
|
||||
raise Exception("Error sending notification webhook: {}".format(r.text))
|
||||
raise Exception(smart_text("Error sending notification webhook: {}".format(r.text)))
|
||||
sent_messages += 1
|
||||
return sent_messages
|
||||
|
||||
@ -39,6 +39,7 @@ from celery import Task, task
|
||||
from django.conf import settings
|
||||
from django.db import transaction, DatabaseError
|
||||
from django.utils.timezone import now
|
||||
from django.utils.encoding import smart_text
|
||||
from django.core.mail import send_mail
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
@ -83,7 +84,7 @@ def send_notifications(notification_list, job_id=None):
|
||||
except Exception as e:
|
||||
logger.error("Send Notification Failed {}".format(e))
|
||||
notification.status = "failed"
|
||||
notification.error = str(e)
|
||||
notification.error = smart_text(e)
|
||||
finally:
|
||||
notification.save()
|
||||
if job_id is not None:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user