author | Madhusudan.C.S <madhusudancs@gmail.com> |
Tue, 01 Feb 2011 04:33:35 +0530 | |
changeset 542 | 23bf9b4611cb |
parent 517 | bbc20d6428ad |
permissions | -rw-r--r-- |
509
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
1 |
"""Helper script to send emails to the users. |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
2 |
""" |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
3 |
|
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
4 |
|
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
5 |
__authors__ = [ |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
6 |
'"Madhusudan.C.S" <madhusudancs@gmail.com>', |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
7 |
] |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
8 |
|
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
9 |
|
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
10 |
from django.template import loader |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
11 |
from django.contrib.auth.models import User |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
12 |
|
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
13 |
|
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
14 |
def textbook_workshop_remainder(subject_template=None, body_template=None): |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
15 |
"""Sends a mail to each delegate about the template content specified. |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
16 |
""" |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
17 |
|
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
18 |
users = User.objects.all() |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
19 |
|
511
50a5bdd313ac
Fixed the getting profile and name model property.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
509
diff
changeset
|
20 |
subject = loader.render_to_string(subject_template).strip(' \n\t') |
509
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
21 |
|
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
22 |
for user in users: |
511
50a5bdd313ac
Fixed the getting profile and name model property.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
509
diff
changeset
|
23 |
profile = user.get_profile() |
509
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
24 |
if profile: |
511
50a5bdd313ac
Fixed the getting profile and name model property.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
509
diff
changeset
|
25 |
full_name = profile.full_name |
509
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
26 |
else: |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
27 |
full_name = '' |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
28 |
|
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
29 |
message = loader.render_to_string( |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
30 |
body_template, dictionary={'name': full_name}) |
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
31 |
|
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
32 |
user.email_user(subject=subject, message=message, |
517
bbc20d6428ad
Added my name for the email sender address.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
511
diff
changeset
|
33 |
from_email='Madhusudan C.S. <madhusudancs@fossee.in>') |
509
288d1dfb81c0
Add a script for sending email to users.
Madhusudan.C.S <madhusudancs@fossee.in>
parents:
diff
changeset
|
34 |