34 from soc.logic import accounts |
34 from soc.logic import accounts |
35 from soc.logic import dicts |
35 from soc.logic import dicts |
36 from soc.logic import mail_dispatcher |
36 from soc.logic import mail_dispatcher |
37 from soc.views.helper import redirects |
37 from soc.views.helper import redirects |
38 |
38 |
39 import soc.views.models as model_view |
|
40 import soc.logic.models as model_logic |
|
41 |
|
42 |
39 |
43 DEF_NEW_NOTIFICATION_MSG = ugettext( |
40 DEF_NEW_NOTIFICATION_MSG = ugettext( |
44 "You have received a new Notification.") |
41 "You have received a new Notification.") |
45 |
42 |
46 DEF_INVITATION_MSG_FMT = ugettext( |
43 DEF_INVITATION_MSG_FMT = ugettext( |
68 |
65 |
69 Args: |
66 Args: |
70 entity : A request containing the information needed to create the message |
67 entity : A request containing the information needed to create the message |
71 """ |
68 """ |
72 |
69 |
|
70 from soc.logic.models.user import logic as user_logic |
|
71 |
73 # get the user the request is for |
72 # get the user the request is for |
74 properties = {'link_id': entity.link_id } |
73 properties = {'link_id': entity.link_id } |
75 to_user = model_logic.user.logic.getForFields(properties, unique=True) |
74 to_user = user_logic.getForFields(properties, unique=True) |
76 |
75 |
77 invitation_url = "http://%(host)s%(index)s" % { |
76 invitation_url = "http://%(host)s%(index)s" % { |
78 'host' : os.environ['HTTP_HOST'], |
77 'host' : os.environ['HTTP_HOST'], |
79 'index': redirects.getInviteProcessRedirect(entity, None), |
78 'index': redirects.getInviteProcessRedirect(entity, None), |
80 } |
79 } |
90 'group' : entity.scope.name |
89 'group' : entity.scope.name |
91 } |
90 } |
92 |
91 |
93 template = DEF_GROUP_INVITE_NOTIFICATION_TEMPLATE |
92 template = DEF_GROUP_INVITE_NOTIFICATION_TEMPLATE |
94 |
93 |
95 from_user = model_logic.user.logic.getForCurrentAccount() |
94 from_user = user_logic.getForCurrentAccount() |
96 |
95 |
97 sendNotification(to_user, from_user, message_properties, subject, template) |
96 sendNotification(to_user, from_user, message_properties, subject, template) |
98 |
97 |
99 |
98 |
100 def sendNewGroupNotification(entity, params): |
99 def sendNewGroupNotification(entity, params): |
165 message_properties : message properties |
164 message_properties : message properties |
166 subject : subject of notification email |
165 subject : subject of notification email |
167 template : template used for generating notification |
166 template : template used for generating notification |
168 """ |
167 """ |
169 |
168 |
|
169 from soc.logic.models.notification import logic as notification_logic |
|
170 from soc.logic.models.site import logic as site_logic |
|
171 |
170 if from_user: |
172 if from_user: |
171 sender_name = from_user.name |
173 sender_name = from_user.name |
172 else: |
174 else: |
173 site_entity = model_logic.site.logic.getSingleton() |
175 site_entity = site_logic.getSingleton() |
174 sender_name = 'The %s Team' % (site_entity.site_name) |
176 sender_name = 'The %s Team' % (site_entity.site_name) |
175 |
177 |
176 new_message_properties = { |
178 new_message_properties = { |
177 'sender_name': sender_name, |
179 'sender_name': sender_name, |
178 'to_name': to_user.name, |
180 'to_name': to_user.name, |
189 'scope': to_user, |
191 'scope': to_user, |
190 'link_id': 't%i' % (int(time.time()*100)), |
192 'link_id': 't%i' % (int(time.time()*100)), |
191 'scope_path': to_user.link_id |
193 'scope_path': to_user.link_id |
192 } |
194 } |
193 |
195 |
194 # pylint: disable-msg=W0612 |
196 key_name = notification_logic.getKeyNameFromFields(fields) |
195 import soc.logic.models.notification |
|
196 key_name = model_logic.notification.logic.getKeyNameFromFields(fields) |
|
197 |
197 |
198 # create and put a new notification in the datastore |
198 # create and put a new notification in the datastore |
199 model_logic.notification.logic.updateOrCreateFromKeyName(fields, key_name) |
199 notification_logic.updateOrCreateFromKeyName(fields, key_name) |
200 |
200 |
201 |
201 |
202 def sendNewNotificationMessage(notification_entity): |
202 def sendNewNotificationMessage(notification_entity): |
203 """Sends an email to a user about a new notification. |
203 """Sends an email to a user about a new notification. |
204 |
204 |
205 Args: |
205 Args: |
206 notification_entity: Notification about which the message should be sent |
206 notification_entity: Notification about which the message should be sent |
207 """ |
207 """ |
208 # pylint: disable-msg=W0612 |
208 |
209 import soc.views.models.notification |
209 from soc.logic.models.site import logic as site_logic |
|
210 from soc.views.models.notification import view as notification_view |
210 |
211 |
211 # create the url to show this notification |
212 # create the url to show this notification |
212 notification_url = "http://%(host)s%(index)s" % { |
213 notification_url = "http://%(host)s%(index)s" % { |
213 'host' : os.environ['HTTP_HOST'], |
214 'host' : os.environ['HTTP_HOST'], |
214 'index': redirects.getPublicRedirect(notification_entity, |
215 'index': redirects.getPublicRedirect(notification_entity, |
215 model_view.notification.view.getParams())} |
216 notification_view.getParams())} |
216 |
217 |
217 sender = mail_dispatcher.getDefaultMailSender() |
218 sender = mail_dispatcher.getDefaultMailSender() |
218 site_entity = model_logic.site.logic.getSingleton() |
219 site_entity = site_logic.getSingleton() |
219 site_name = site_entity.site_name |
220 site_name = site_entity.site_name |
220 |
221 |
221 # get the default mail sender |
222 # get the default mail sender |
222 default_sender = mail_dispatcher.getDefaultMailSender() |
223 default_sender = mail_dispatcher.getDefaultMailSender() |
223 |
224 |
251 |
252 |
252 Args: |
253 Args: |
253 user_entity: User entity which the message should be send to |
254 user_entity: User entity which the message should be send to |
254 """ |
255 """ |
255 |
256 |
|
257 from soc.logic.models.site import logic as site_logic |
|
258 |
256 # get site name |
259 # get site name |
257 site_entity = model_logic.site.logic.getSingleton() |
260 site_entity = site_logic.getSingleton() |
258 site_name = site_entity.site_name |
261 site_name = site_entity.site_name |
259 |
262 |
260 # get the default mail sender |
263 # get the default mail sender |
261 default_sender = mail_dispatcher.getDefaultMailSender() |
264 default_sender = mail_dispatcher.getDefaultMailSender() |
262 |
265 |