author | Lennard de Rijk <ljvderijk@gmail.com> |
Sun, 30 Nov 2008 22:15:39 +0000 | |
changeset 635 | 2f5322ad1f5b |
child 638 | 22ec01fdf8f4 |
permissions | -rw-r--r-- |
635
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
2 |
# |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
4 |
# |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
8 |
# |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
10 |
# |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
16 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
17 |
"""Helper functions for sending out notifications |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
18 |
""" |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
19 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
21 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
22 |
] |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
23 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
24 |
from google.appengine.api import users |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
25 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
26 |
from django.utils.translation import ugettext_lazy |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
27 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
28 |
from soc.logic import mail_dispatcher |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
29 |
from soc.logic.models import user as user_logic |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
30 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
31 |
from soc.views.helper import redirects |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
32 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
33 |
import os |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
34 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
35 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
36 |
DEF_INVITATION_FMT = ugettext_lazy( |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
37 |
"Invitation to become a %(role)s for %(group)s") |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
38 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
39 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
40 |
def sendInviteNotification(entity): |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
41 |
"""Sends out an invite notification to the user the request is for. |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
42 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
43 |
Args: |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
44 |
entity : A request containing the information needed to create the message |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
45 |
""" |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
46 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
47 |
# get the current user |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
48 |
properties = {'account': users.get_current_user()} |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
49 |
current_user_entity = user_logic.logic.getForFields(properties, unique=True) |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
50 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
51 |
# get the user the request is for |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
52 |
properties = {'link_id': entity.link_id } |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
53 |
request_user_entity = user_logic.logic.getForFields(properties, unique=True) |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
54 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
55 |
# create the invitation_url |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
56 |
invitation_url = "%(host)s%(index)s" % { |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
57 |
'host' : os.environ['HTTP_HOST'], |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
58 |
'index': redirects.inviteAcceptedRedirect(entity, None)} |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
59 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
60 |
# get the group entity |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
61 |
group_entity = entity.scope |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
62 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
63 |
messageProperties = { |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
64 |
'to_name': request_user_entity.name, |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
65 |
'sender_name': current_user_entity.name, |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
66 |
'role': entity.role, |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
67 |
'group': group_entity.name, |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
68 |
'invitation_url': invitation_url, |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
69 |
'to': request_user_entity.account.email(), |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
70 |
'sender': current_user_entity.account.email(), |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
71 |
'subject': DEF_INVITATION_FMT % { |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
72 |
'role': entity.role, |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
73 |
'group': group_entity.name |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
74 |
}, |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
75 |
} |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
76 |
|
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
77 |
# send out the message using the default invitation template |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
78 |
mail_dispatcher.sendMailFromTemplate('soc/mail/invitation.html', |
2f5322ad1f5b
Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
79 |
messageProperties) |