author | Madhusudan.C.S <madhusudancs@gmail.com> |
Fri, 28 Aug 2009 12:57:12 +0200 | |
changeset 2825 | e57a661a174d |
permissions | -rw-r--r-- |
2825
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2 |
# |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
4 |
# |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
8 |
# |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
10 |
# |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
16 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
17 |
"""Appengine Tasks related to GHOPTask. |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
18 |
""" |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
19 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
21 |
'"Madhusudan.C.S" <madhusudancs@gmail.com>' |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
22 |
] |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
23 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
24 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
25 |
import os |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
26 |
import time |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
27 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
28 |
from django.template import loader |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
29 |
from django.utils.encoding import force_unicode |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
30 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
31 |
from soc.logic import accounts |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
32 |
from soc.logic import dicts |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
33 |
from soc.logic import mail_dispatcher |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
34 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
35 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
36 |
def sendTaskUpdateMail(subscriber, subject, message_properties=None): |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
37 |
"""Sends an email to a user about an update to a Task. |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
38 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
39 |
Args: |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
40 |
subscriber: The user entity to whom the message must be sent |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
41 |
subject: Subject of the mail |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
42 |
message_properties: The mail message properties |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
43 |
template: Optional django template that is used to build the message body |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
44 |
""" |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
45 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
46 |
from soc.logic.models.site import logic as site_logic |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
47 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
48 |
site_entity = site_logic.getSingleton() |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
49 |
site_name = site_entity.site_name |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
50 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
51 |
# get the default mail sender |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
52 |
default_sender = mail_dispatcher.getDefaultMailSender() |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
53 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
54 |
if not default_sender: |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
55 |
# no valid sender found, abort |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
56 |
return |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
57 |
else: |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
58 |
(sender_name, sender) = default_sender |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
59 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
60 |
to = accounts.denormalizeAccount(subscriber.account).email() |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
61 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
62 |
# create the message contents |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
63 |
new_message_properties = { |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
64 |
'to_name': subscriber.name, |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
65 |
'sender_name': sender_name, |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
66 |
'to': to, |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
67 |
'sender': sender, |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
68 |
'site_name': site_name, |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
69 |
'subject': force_unicode(subject), |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
70 |
} |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
71 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
72 |
messageProperties = dicts.merge(message_properties, new_message_properties) |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
73 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
74 |
template = 'modules/ghop/task/update_notification' |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
75 |
|
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
76 |
# send out the message using the default new notification template |
e57a661a174d
Added method to send out mail about a Task update.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
77 |
mail_dispatcher.sendMailFromTemplate(template, messageProperties) |