Adding some early Notifications stubs

* A basic NotificationTemplate model class with early notification type
  definitions
* Initial implementations of the Email, Slack, and Twilio Notification
  backends using the Django email backend system
* Some dependencies thereof
This commit is contained in:
Matthew Jones
2016-02-01 16:54:34 -05:00
parent 6d71fe49f2
commit 7385efef35
7 changed files with 139 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
# Copyright (c) 2016 Ansible, Inc.
# All Rights Reserved.
import logging
from django.db import models
from awx.main.models.base import * # noqa
from awx.main.notifications.email_backend import CustomEmailBackend
from awx.main.notifications.slack_backend import SlackBackend
from awx.main.notifications.twilio_backend import TwilioBackend
# Django-JSONField
from jsonfield import JSONField
logger = logging.getLogger('awx.main.models.notifications')
class NotificationTemplate(CommonModel):
NOTIFICATION_TYPES = [('email', _('Email'), CustomEmailBackend),
('slack', _('Slack'), SlackBackend),
('twilio', _('Twilio'), TwilioBackend)]
NOTIFICATION_TYPE_CHOICES = [(x[0], x[1]) for x in NOTIFICATION_TYPES]
CLASS_FOR_NOTIFICATION_TYPE = dict([(x[0], x[2]) for x in NOTIFICATION_TYPES])
class Meta:
app_label = 'main'
notification_type = models.CharField(
max_length = 32,
choices=NOTIFICATION_TYPE_CHOICES,
)
notification_configuration = JSONField(blank=False)
@property
def notification_class(self):
return CLASS_FOR_NOTIFICATION_TYPE[self.notification_type]