21 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
21 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
22 ] |
22 ] |
23 |
23 |
24 |
24 |
25 import os |
25 import os |
|
26 import soc.logic.models as model_logic |
26 |
27 |
27 from google.appengine.api import users |
28 from google.appengine.api import users |
28 |
29 |
29 from django.utils.translation import ugettext_lazy |
30 from django.utils.translation import ugettext_lazy |
30 |
31 |
31 from soc.logic import mail_dispatcher |
32 from soc.logic import mail_dispatcher |
32 from soc.logic.models import user as user_logic |
|
33 from soc.views.helper import redirects |
33 from soc.views.helper import redirects |
34 |
34 |
35 |
35 |
36 DEF_INVITATION_FMT = ugettext_lazy( |
36 DEF_INVITATION_FMT = ugettext_lazy( |
37 "Invitation to become a %(role)s for %(group)s") |
37 "Invitation to become a %(role)s for %(group)s") |
|
38 |
|
39 DEF_WELCOME_FMT = ugettext_lazy("Welcome to Melange %(name)s") |
38 |
40 |
39 def sendInviteNotification(entity): |
41 def sendInviteNotification(entity): |
40 """Sends out an invite notification to the user the request is for. |
42 """Sends out an invite notification to the user the request is for. |
41 |
43 |
42 Args: |
44 Args: |
43 entity : A request containing the information needed to create the message |
45 entity : A request containing the information needed to create the message |
44 """ |
46 """ |
|
47 |
|
48 # get user logic |
|
49 user_logic = model_logic.user |
45 |
50 |
46 # get the current user |
51 # get the current user |
47 properties = {'account': users.get_current_user()} |
52 properties = {'account': users.get_current_user()} |
48 current_user_entity = user_logic.logic.getForFields(properties, unique=True) |
53 current_user_entity = user_logic.logic.getForFields(properties, unique=True) |
49 |
54 |
74 } |
79 } |
75 |
80 |
76 # send out the message using the default invitation template |
81 # send out the message using the default invitation template |
77 mail_dispatcher.sendMailFromTemplate('soc/mail/invitation.html', |
82 mail_dispatcher.sendMailFromTemplate('soc/mail/invitation.html', |
78 messageProperties) |
83 messageProperties) |
|
84 |
|
85 def sendWelcomeMessage(user_entity): |
|
86 """Sends out a welcome message to a user. |
|
87 |
|
88 Args: |
|
89 user_entity: User entity which the message should be send to |
|
90 """ |
|
91 |
|
92 # get user logic |
|
93 user_logic = model_logic.user |
|
94 |
|
95 # get the current user |
|
96 properties = {'account': users.get_current_user()} |
|
97 current_user_entity = user_logic.logic.getForFields(properties, unique=True) |
|
98 |
|
99 # create the message contents |
|
100 # TODO(Lennard) change the message sender to some sort of no-reply adress that is |
|
101 # probably a setting in sitesettings. (adress must be a developer). This is due |
|
102 # to a GAE limitation that allows only devs or the current user to send an email. |
|
103 # Currently this results in a user receiving the same email twice. |
|
104 messageProperties = { |
|
105 'to_name': user_entity.name, |
|
106 'sender_name': current_user_entity.name, |
|
107 'to': user_entity.account.email(), |
|
108 'sender': current_user_entity.account.email(), |
|
109 'subject': DEF_WELCOME_FMT % { |
|
110 'name': user_entity.name |
|
111 } |
|
112 } |
|
113 |
|
114 # send out the message using the default welcome template |
|
115 mail_dispatcher.sendMailFromTemplate('soc/mail/welcome.html', |
|
116 messageProperties) |