<s> from os import environ as env <EOL> from django . conf import settings <EOL> from django . core . mail import send_mail <EOL> from django . core . urlresolvers import reverse <EOL> from django . template import Context , Template <EOL> from django . db import models <EOL> from django . db . models import get_models <EOL> from twilio . rest import TwilioRestClient <EOL> from twilio import twiml <EOL> import requests <EOL> import logging <EOL> import re <EOL> from polymorphic import PolymorphicModel <EOL> logger = logging . getLogger ( __name__ ) <EOL> class AlertPlugin ( PolymorphicModel ) : <EOL> title = models . CharField ( max_length = <NUM_LIT:30> , unique = True , editable = False ) <EOL> enabled = models . BooleanField ( default = True ) <EOL> author = None <EOL> def __unicode__ ( self ) : <EOL> return u'<STR_LIT:%s>' % ( self . title ) <EOL> def send_alert ( self , service , users , duty_officers ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> class AlertPluginUserData ( PolymorphicModel ) : <EOL> title = models . CharField ( max_length = <NUM_LIT:30> , editable = False ) <EOL> user = models . ForeignKey ( '<STR_LIT>' , editable = False ) <EOL> class Meta : <EOL> unique_together = ( '<STR_LIT:title>' , '<STR_LIT:user>' , ) <EOL> def __unicode__ ( self ) : <EOL> return u'<STR_LIT:%s>' % ( self . title ) <EOL> def send_alert ( service , duty_officers = None ) : <EOL> users = service . users_to_notify . filter ( is_active = True ) <EOL> for alert in service . alerts . all ( ) : <EOL> try : <EOL> alert . send_alert ( service , users , duty_officers ) <EOL> except Exception as e : <EOL> logging . exception ( '<STR_LIT>' % ( alert . name , e ) ) <EOL> def send_alert_update ( service , duty_officers = None ) : <EOL> users = service . users_to_notify . filter ( is_active = True ) <EOL> for alert in service . alerts . all ( ) : <EOL> if hasattr ( alert , '<STR_LIT>' ) : <EOL> try : <EOL> alert . send_alert_update ( service , users , duty_officers ) <EOL> except Exception as e : <EOL> logger . exception ( '<STR_LIT>' % ( alert . name , e ) ) <EOL> else : <EOL> logger . warning ( '<STR_LIT>' % alert . name ) <EOL> def update_alert_plugins ( ) : <EOL> for plugin_subclass in AlertPlugin . __subclasses__ ( ) : <EOL> plugin = plugin_subclass . objects . get_or_create ( title = plugin_subclass . name ) <EOL> return AlertPlugin . objects . all ( ) </s>
