45 Args: |
47 Args: |
46 entity : A request containing the information needed to create the message |
48 entity : A request containing the information needed to create the message |
47 """ |
49 """ |
48 |
50 |
49 # get user logic |
51 # get user logic |
50 user_logic = model_logic.user |
52 user_logic = model_logic.user.logic |
51 |
53 |
52 # get the current user |
54 # get the current user |
53 properties = {'account': users.get_current_user()} |
55 current_user_entity = user_logic.getForCurrentAccount() |
54 current_user_entity = user_logic.logic.getForFields(properties, unique=True) |
|
55 |
56 |
56 # get the user the request is for |
57 # get the user the request is for |
57 properties = {'link_id': entity.link_id } |
58 properties = {'link_id': entity.link_id } |
58 request_user_entity = user_logic.logic.getForFields(properties, unique=True) |
59 request_user_entity = user_logic.getForFields(properties, unique=True) |
59 |
60 |
60 # create the invitation_url |
61 # create the invitation_url |
61 invitation_url = "%(host)s%(index)s" % { |
62 invitation_url = "%(host)s%(index)s" % { |
62 'host' : os.environ['HTTP_HOST'], |
63 'host' : os.environ['HTTP_HOST'], |
63 'index': redirects.inviteAcceptedRedirect(entity, None)} |
64 'index': redirects.inviteAcceptedRedirect(entity, None)} |
64 |
65 |
65 # get the group entity |
66 # get the group entity |
66 group_entity = entity.scope |
67 group_entity = entity.scope |
67 |
68 |
|
69 # create the properties for the message |
68 messageProperties = { |
70 messageProperties = { |
69 'to_name': request_user_entity.name, |
71 'to_name': request_user_entity.name, |
70 'sender_name': current_user_entity.name, |
72 'sender_name': current_user_entity.name, |
71 'role': entity.role, |
73 'role': entity.role, |
72 'group': group_entity.name, |
74 'group': group_entity.name, |
73 'invitation_url': invitation_url, |
75 'invitation_url': invitation_url, |
74 'to': request_user_entity.account.email(), |
76 } |
75 'sender': current_user_entity.account.email(), |
77 |
76 'subject': DEF_INVITATION_MSG_FMT % { |
78 # render the message |
77 'role': entity.role, |
79 message = loader.render_to_string('soc/notification/messages/invitation.html', dictionary=messageProperties) |
78 'group': group_entity.name |
80 |
|
81 # create the fields for the notification |
|
82 fields = { |
|
83 'from_user' : current_user_entity, |
|
84 'subject' : DEF_INVITATION_MSG_FMT % { |
|
85 'role' : entity.role, |
|
86 'group' : group_entity.name |
79 }, |
87 }, |
80 } |
88 'message' : message, |
81 |
89 'scope' : request_user_entity, |
82 # send out the message using the default invitation template |
90 'link_id' :'%i' % (time.time()), |
83 mail_dispatcher.sendMailFromTemplate('soc/mail/invitation.html', |
91 'scope_path' : request_user_entity.link_id |
84 messageProperties) |
92 } |
|
93 |
|
94 # create and put a new notification in the datastore |
|
95 notification_logic = model_logic.notification.logic |
|
96 notification_logic.updateOrCreateFromFields(fields, |
|
97 notification_logic.getKeyFieldsFromDict(fields)) |
|
98 |
85 |
99 |
86 def sendWelcomeMessage(user_entity): |
100 def sendWelcomeMessage(user_entity): |
87 """Sends out a welcome message to a user. |
101 """Sends out a welcome message to a user. |
88 |
102 |
89 Args: |
103 Args: |