app/soc/logic/helper/notifications.py
author Lennard de Rijk <ljvderijk@gmail.com>
Wed, 17 Dec 2008 22:15:21 +0000
changeset 757 b11cee4ab535
parent 756 a0c0b48563cb
child 759 ed7a7596033e
permissions -rw-r--r--
Added email message when receiving a notification.py At the moment this only triggers when the new notification is your first unread message. Also fixed an url bug in the invite notification. Patch by: Lennard de Rijk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
638
22ec01fdf8f4 Add missing dot and correctly sort imports in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 635
diff changeset
    17
"""Helper functions for sending out notifications.
635
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
638
22ec01fdf8f4 Add missing dot and correctly sort imports in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 635
diff changeset
    24
756
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    25
import time
638
22ec01fdf8f4 Add missing dot and correctly sort imports in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 635
diff changeset
    26
import os
22ec01fdf8f4 Add missing dot and correctly sort imports in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 635
diff changeset
    27
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
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
    29
756
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    30
from django.template import loader
757
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
    31
from django.utils.encoding import force_unicode
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
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
    33
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
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
    35
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
    36
757
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
    37
import soc.views.models as model_view
664
fb4c825b24ab Some style fixes in soc.logic.helper.notifications module. Little changes in welcome.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 641
diff changeset
    38
import soc.logic.models as model_logic
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
664
fb4c825b24ab Some style fixes in soc.logic.helper.notifications module. Little changes in welcome.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 641
diff changeset
    40
757
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
    41
DEF_NEW_NOTIFICATION_MSG = ugettext_lazy(
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
    42
  "You have received a new Notification")
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
    43
664
fb4c825b24ab Some style fixes in soc.logic.helper.notifications module. Little changes in welcome.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 641
diff changeset
    44
DEF_INVITATION_MSG_FMT = ugettext_lazy(
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
    "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
    46
664
fb4c825b24ab Some style fixes in soc.logic.helper.notifications module. Little changes in welcome.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 641
diff changeset
    47
DEF_WELCOME_MSG_FMT = ugettext_lazy("Welcome to Melange %(name)s")
640
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
    48
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
def sendInviteNotification(entity):
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
  """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
    51
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
  Args:
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
    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
    54
  """
640
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
    55
  
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
    56
  # get user logic
756
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    57
  user_logic = model_logic.user.logic
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
  # get the current user
756
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    60
  current_user_entity = user_logic.getForCurrentAccount()
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
  
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
  # 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
    63
  properties = {'link_id': entity.link_id }
756
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    64
  request_user_entity = user_logic.getForFields(properties, unique=True)
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
  # create the invitation_url
757
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
    67
  invitation_url = "http://%(host)s%(index)s" % {
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
      '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
    69
      '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
    70
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
  # 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
    72
  group_entity = entity.scope
756
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    73
  
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    74
  # create the properties for the message
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    75
  messageProperties = {
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
      '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
    77
      '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
    78
      'role': entity.role,
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    79
      '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
    80
      'invitation_url': invitation_url,
756
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    81
      }
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    82
  
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    83
  # render the message
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    84
  message = loader.render_to_string('soc/notification/messages/invitation.html', dictionary=messageProperties)
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    85
  
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    86
  # create the fields for the notification
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    87
  fields = { 
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    88
      'from_user' : current_user_entity,
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    89
      'subject' : DEF_INVITATION_MSG_FMT % {
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    90
          'role' : entity.role,
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    91
          'group' : group_entity.name 
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
          },
756
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    93
      'message' : message,
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    94
      'scope' : request_user_entity,
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    95
      'link_id' :'%i' % (time.time()),
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    96
      'scope_path' : request_user_entity.link_id
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    97
  }
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    98
  
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    99
  # create and put a new notification in the datastore
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
   100
  notification_logic = model_logic.notification.logic
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
   101
  notification_logic.updateOrCreateFromFields(fields, 
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
   102
      notification_logic.getKeyFieldsFromDict(fields))
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
   103
  
757
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   104
def sendNewNotificationMessage(notification_entity):
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   105
  """Sends an email to a user about a new notification
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   106
  
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   107
    Args:
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   108
      notification_entity: Notification about which the message should be sent    
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   109
  """
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   110
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   111
  # get user logic
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   112
  user_logic = model_logic.user  
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   113
  
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   114
  # get the current user
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   115
  current_user_entity = user_logic.logic.getForCurrentAccount()
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   116
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   117
  # create the url to show this notification
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   118
  notification_url = "http://%(host)s%(index)s" % {
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   119
      'host' : os.environ['HTTP_HOST'], 
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   120
      'index': redirects.getPublicRedirect(notification_entity,
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   121
          model_view.notification.view.getParams())}
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   122
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   123
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   124
  # TODO(Lennard): Change the sender to the no-reply address
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   125
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   126
  # create the message contents
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   127
  messageProperties = {
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   128
      'to_name': notification_entity.scope.name,
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   129
      'sender_name': current_user_entity.name,
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   130
      'to': notification_entity.scope.account.email(),
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   131
      'sender': current_user_entity.account.email(),
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   132
      'subject': force_unicode(DEF_NEW_NOTIFICATION_MSG),
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   133
      'notification' : notification_entity,
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   134
      'notification_url' : notification_url
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   135
      }
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   136
  
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   137
  # send out the message using the default new notification template    
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   138
  mail_dispatcher.sendMailFromTemplate('soc/mail/new_notification.html', 
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   139
                                       messageProperties)
640
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   140
  
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   141
def sendWelcomeMessage(user_entity):
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   142
  """Sends out a welcome message to a user.
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   143
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   144
    Args:
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   145
      user_entity: User entity which the message should be send to
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   146
  """
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   147
  
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   148
  # get user logic
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   149
  user_logic = model_logic.user  
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   150
  
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   151
  # get the current user
757
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   152
  current_user_entity = user_logic.logic.getForCurrentAccount()
640
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   153
750
6e8d67d04507 Fix too long lines in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 664
diff changeset
   154
  # TODO(Lennard): change the message sender to some sort of no-reply adress 
6e8d67d04507 Fix too long lines in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 664
diff changeset
   155
  # that is probably a setting in sitesettings. (adress must be a developer). 
6e8d67d04507 Fix too long lines in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 664
diff changeset
   156
  # This is due to a GAE limitation that allows only devs or the current user 
6e8d67d04507 Fix too long lines in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 664
diff changeset
   157
  # to send an email. Currently this results in a user receiving the same 
6e8d67d04507 Fix too long lines in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 664
diff changeset
   158
  # email twice.
664
fb4c825b24ab Some style fixes in soc.logic.helper.notifications module. Little changes in welcome.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 641
diff changeset
   159
  
fb4c825b24ab Some style fixes in soc.logic.helper.notifications module. Little changes in welcome.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 641
diff changeset
   160
  # create the message contents
640
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   161
  messageProperties = {
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   162
      'to_name': user_entity.name,
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   163
      'sender_name': current_user_entity.name,
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   164
      'to': user_entity.account.email(),
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   165
      'sender': current_user_entity.account.email(),
664
fb4c825b24ab Some style fixes in soc.logic.helper.notifications module. Little changes in welcome.html template.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 641
diff changeset
   166
      'subject': DEF_WELCOME_MSG_FMT % {
640
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   167
          'name': user_entity.name
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   168
          }
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   169
      } 
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   170
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   171
  # send out the message using the default welcome template    
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   172
  mail_dispatcher.sendMailFromTemplate('soc/mail/welcome.html', 
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   173
                                       messageProperties)