26 import os |
26 import os |
27 |
27 |
28 from google.appengine.api import users |
28 from google.appengine.api import users |
29 |
29 |
30 from django.template import loader |
30 from django.template import loader |
|
31 from django.utils.encoding import force_unicode |
31 from django.utils.translation import ugettext_lazy |
32 from django.utils.translation import ugettext_lazy |
32 |
33 |
33 from soc.logic import mail_dispatcher |
34 from soc.logic import mail_dispatcher |
34 from soc.views.helper import redirects |
35 from soc.views.helper import redirects |
35 |
36 |
|
37 import soc.views.models as model_view |
36 import soc.logic.models as model_logic |
38 import soc.logic.models as model_logic |
37 |
39 |
|
40 |
|
41 DEF_NEW_NOTIFICATION_MSG = ugettext_lazy( |
|
42 "You have received a new Notification") |
38 |
43 |
39 DEF_INVITATION_MSG_FMT = ugettext_lazy( |
44 DEF_INVITATION_MSG_FMT = ugettext_lazy( |
40 "Invitation to become a %(role)s for %(group)s") |
45 "Invitation to become a %(role)s for %(group)s") |
41 |
46 |
42 DEF_WELCOME_MSG_FMT = ugettext_lazy("Welcome to Melange %(name)s") |
47 DEF_WELCOME_MSG_FMT = ugettext_lazy("Welcome to Melange %(name)s") |
57 # get the user the request is for |
62 # get the user the request is for |
58 properties = {'link_id': entity.link_id } |
63 properties = {'link_id': entity.link_id } |
59 request_user_entity = user_logic.getForFields(properties, unique=True) |
64 request_user_entity = user_logic.getForFields(properties, unique=True) |
60 |
65 |
61 # create the invitation_url |
66 # create the invitation_url |
62 invitation_url = "%(host)s%(index)s" % { |
67 invitation_url = "http://%(host)s%(index)s" % { |
63 'host' : os.environ['HTTP_HOST'], |
68 'host' : os.environ['HTTP_HOST'], |
64 'index': redirects.inviteAcceptedRedirect(entity, None)} |
69 'index': redirects.inviteAcceptedRedirect(entity, None)} |
65 |
70 |
66 # get the group entity |
71 # get the group entity |
67 group_entity = entity.scope |
72 group_entity = entity.scope |
94 # create and put a new notification in the datastore |
99 # create and put a new notification in the datastore |
95 notification_logic = model_logic.notification.logic |
100 notification_logic = model_logic.notification.logic |
96 notification_logic.updateOrCreateFromFields(fields, |
101 notification_logic.updateOrCreateFromFields(fields, |
97 notification_logic.getKeyFieldsFromDict(fields)) |
102 notification_logic.getKeyFieldsFromDict(fields)) |
98 |
103 |
|
104 def sendNewNotificationMessage(notification_entity): |
|
105 """Sends an email to a user about a new notification |
|
106 |
|
107 Args: |
|
108 notification_entity: Notification about which the message should be sent |
|
109 """ |
|
110 |
|
111 # get user logic |
|
112 user_logic = model_logic.user |
|
113 |
|
114 # get the current user |
|
115 current_user_entity = user_logic.logic.getForCurrentAccount() |
|
116 |
|
117 # create the url to show this notification |
|
118 notification_url = "http://%(host)s%(index)s" % { |
|
119 'host' : os.environ['HTTP_HOST'], |
|
120 'index': redirects.getPublicRedirect(notification_entity, |
|
121 model_view.notification.view.getParams())} |
|
122 |
|
123 |
|
124 # TODO(Lennard): Change the sender to the no-reply address |
|
125 |
|
126 # create the message contents |
|
127 messageProperties = { |
|
128 'to_name': notification_entity.scope.name, |
|
129 'sender_name': current_user_entity.name, |
|
130 'to': notification_entity.scope.account.email(), |
|
131 'sender': current_user_entity.account.email(), |
|
132 'subject': force_unicode(DEF_NEW_NOTIFICATION_MSG), |
|
133 'notification' : notification_entity, |
|
134 'notification_url' : notification_url |
|
135 } |
|
136 |
|
137 # send out the message using the default new notification template |
|
138 mail_dispatcher.sendMailFromTemplate('soc/mail/new_notification.html', |
|
139 messageProperties) |
99 |
140 |
100 def sendWelcomeMessage(user_entity): |
141 def sendWelcomeMessage(user_entity): |
101 """Sends out a welcome message to a user. |
142 """Sends out a welcome message to a user. |
102 |
143 |
103 Args: |
144 Args: |
106 |
147 |
107 # get user logic |
148 # get user logic |
108 user_logic = model_logic.user |
149 user_logic = model_logic.user |
109 |
150 |
110 # get the current user |
151 # get the current user |
111 properties = {'account': users.get_current_user()} |
152 current_user_entity = user_logic.logic.getForCurrentAccount() |
112 current_user_entity = user_logic.logic.getForFields(properties, unique=True) |
|
113 |
153 |
114 # TODO(Lennard): change the message sender to some sort of no-reply adress |
154 # TODO(Lennard): change the message sender to some sort of no-reply adress |
115 # that is probably a setting in sitesettings. (adress must be a developer). |
155 # that is probably a setting in sitesettings. (adress must be a developer). |
116 # This is due to a GAE limitation that allows only devs or the current user |
156 # This is due to a GAE limitation that allows only devs or the current user |
117 # to send an email. Currently this results in a user receiving the same |
157 # to send an email. Currently this results in a user receiving the same |