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