This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: basketcase on Jan 28th, 2013  |  syntax: Python  |  size: 2.25 KB  |  views: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from django.core import mail
  2. from django.template.loader import get_template
  3. from django.template import Context
  4. from noc_site.notify.models import Notification, Partner
  5.  
  6.  
  7. def notify_Notification():
  8.  
  9.     #I only want to touch a specific notification
  10.     notification = Notification.objects.filter(id='2')
  11.     notification_type = notification.all()[0].notify_type
  12.     partners = Partner.objects.all()
  13.     for partner in partners:
  14.         to_list = [ptr.email for ptr in partner.to_contact.all()]
  15.         cc_list = [ptr.email for ptr in partner.cc_contact.all()]
  16.         bcc_list = [ptr.email for ptr in partner.cc_contact.all()]
  17.         #Scheduled Maintenance Notification
  18.         if notification_type == 'Scheduled':
  19.             #Times
  20.             start = notification.all()[0].start
  21.             end = notification.all()[0].end
  22.             env = notification.all()[0].env
  23.  
  24.             plaintext = get_template('maintenance-notification.txt')
  25.  
  26.             variables = Context(
  27.                         {
  28.                             'start': start,
  29.                             'end': end,
  30.                             'env': env,
  31.                         }
  32.                         )
  33.         connection = mail.get_connection()
  34.         text_content = plaintext.render(variables)
  35.         EMail = mail.EmailMessage('Subject', text_content,
  36.             'email@tld.com',
  37.             to=to_list, cc=cc_list, bcc=bcc_list,)
  38.         EMail.send()
  39.         #Outage Notification
  40.         if notification_type == 'Outage':
  41.             start = notification.all()[0].start
  42.             env = notification.all()[0].env
  43.             if(notification.all()[0].restored):
  44.                 end = notification.all()[0].end
  45.             else:
  46.                 end = 'TBD'
  47.  
  48.         plaintext = get_template('outage-notification.txt')
  49.  
  50.         variables = Context(
  51.                 {
  52.                     'start': start,
  53.                     'end': end,
  54.                     'env': env,
  55.                 }
  56.                 )
  57.         connection = mail.get_connection()
  58.         text_content = plaintext.render(variables)
  59.         EMail = mail.EmailMessage('Subject', text_content,
  60.                 'email@tld.com',
  61.                 to=to_list, cc=cc_list, bcc=bcc_list,)
  62.         EMail.send()
clone this paste RAW Paste Data