scripts/mails.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Tue, 01 Feb 2011 02:14:28 +0530
changeset 538 478c7fc9a223
parent 517 bbc20d6428ad
permissions -rw-r--r--
Create a package for taskapp views and break the views into task and textbook. Now all the view functions common to any two entities along with all tasks related views sit in task module. Even if the view is not directly related to the task entity, it sits in the task module since task is the base for every other entity in the application.

"""Helper script to send emails to the users.
"""


__authors__ = [
  '"Madhusudan.C.S" <madhusudancs@gmail.com>',
  ]


from django.template import loader
from django.contrib.auth.models import User


def textbook_workshop_remainder(subject_template=None, body_template=None):
    """Sends a mail to each delegate about the template content specified.
    """

    users = User.objects.all()

    subject = loader.render_to_string(subject_template).strip(' \n\t')

    for user in users:
        profile = user.get_profile()
        if profile:
            full_name = profile.full_name
        else:
            full_name = ''

        message = loader.render_to_string(
          body_template, dictionary={'name': full_name})

        user.email_user(subject=subject, message=message,
                        from_email='Madhusudan C.S. <madhusudancs@fossee.in>')