scripts/mails.py
changeset 509 288d1dfb81c0
child 511 50a5bdd313ac
equal deleted inserted replaced
508:438afe31fffd 509:288d1dfb81c0
       
     1 """Helper script to send emails to the users.
       
     2 """
       
     3 
       
     4 
       
     5 __authors__ = [
       
     6   '"Madhusudan.C.S" <madhusudancs@gmail.com>',
       
     7   ]
       
     8 
       
     9 
       
    10 from django.template import loader
       
    11 from django.contrib.auth.models import User
       
    12 from django.utils.translation import ugettext
       
    13 
       
    14 
       
    15 def textbook_workshop_remainder(subject_template=None, body_template=None):
       
    16     """Sends a mail to each delegate about the template content specified.
       
    17     """
       
    18 
       
    19     users = User.objects.all()
       
    20 
       
    21     subject = loader.render_to_string(subject_template)
       
    22 
       
    23     for user in users:
       
    24         profile = user.getprofile()
       
    25         if profile:
       
    26             full_name = profile.name
       
    27         else:
       
    28             full_name = ''
       
    29 
       
    30         message = loader.render_to_string(
       
    31           body_template, dictionary={'name': full_name})
       
    32 
       
    33         user.email_user(subject=subject, message=message,
       
    34                         from_email='madhusudancs@fossee.in')
       
    35