app/soc/logic/helper/notifications.py
changeset 664 fb4c825b24ab
parent 641 c59a0ffc2c31
child 750 6e8d67d04507
equal deleted inserted replaced
663:c2dcae606699 664:fb4c825b24ab
    26 
    26 
    27 from google.appengine.api import users
    27 from google.appengine.api import users
    28 
    28 
    29 from django.utils.translation import ugettext_lazy
    29 from django.utils.translation import ugettext_lazy
    30 
    30 
    31 import soc.logic.models as model_logic
       
    32 
       
    33 from soc.logic import mail_dispatcher
    31 from soc.logic import mail_dispatcher
    34 from soc.views.helper import redirects
    32 from soc.views.helper import redirects
    35 
    33 
       
    34 import soc.logic.models as model_logic
    36 
    35 
    37 DEF_INVITATION_FMT = ugettext_lazy(
    36 
       
    37 DEF_INVITATION_MSG_FMT = ugettext_lazy(
    38     "Invitation to become a %(role)s for %(group)s")
    38     "Invitation to become a %(role)s for %(group)s")
    39 
    39 
    40 DEF_WELCOME_FMT = ugettext_lazy("Welcome to Melange %(name)s")
    40 DEF_WELCOME_MSG_FMT = ugettext_lazy("Welcome to Melange %(name)s")
    41 
    41 
    42 def sendInviteNotification(entity):
    42 def sendInviteNotification(entity):
    43   """Sends out an invite notification to the user the request is for.
    43   """Sends out an invite notification to the user the request is for.
    44 
    44 
    45   Args:
    45   Args:
    71       'role': entity.role,
    71       'role': entity.role,
    72       'group': group_entity.name,
    72       'group': group_entity.name,
    73       'invitation_url': invitation_url,
    73       'invitation_url': invitation_url,
    74       'to': request_user_entity.account.email(),
    74       'to': request_user_entity.account.email(),
    75       'sender': current_user_entity.account.email(),
    75       'sender': current_user_entity.account.email(),
    76       'subject': DEF_INVITATION_FMT % {
    76       'subject': DEF_INVITATION_MSG_FMT % {
    77           'role': entity.role,
    77           'role': entity.role,
    78           'group': group_entity.name
    78           'group': group_entity.name
    79           },
    79           },
    80       }
    80       }
    81 
    81 
    95   
    95   
    96   # get the current user
    96   # get the current user
    97   properties = {'account': users.get_current_user()}
    97   properties = {'account': users.get_current_user()}
    98   current_user_entity = user_logic.logic.getForFields(properties, unique=True)
    98   current_user_entity = user_logic.logic.getForFields(properties, unique=True)
    99 
    99 
   100   # create the message contents
   100   # TODO(Lennard): change the message sender to some sort of no-reply adress that is
   101   # TODO(Lennard) change the message sender to some sort of no-reply adress that is
       
   102   # probably a setting in sitesettings. (adress must be a developer). This is due
   101   # probably a setting in sitesettings. (adress must be a developer). This is due
   103   # to a GAE limitation that allows only devs or the current user to send an email.
   102   # to a GAE limitation that allows only devs or the current user to send an email.
   104   # Currently this results in a user receiving the same email twice.
   103   # Currently this results in a user receiving the same email twice.
       
   104   
       
   105   # create the message contents
   105   messageProperties = {
   106   messageProperties = {
   106       'to_name': user_entity.name,
   107       'to_name': user_entity.name,
   107       'sender_name': current_user_entity.name,
   108       'sender_name': current_user_entity.name,
   108       'to': user_entity.account.email(),
   109       'to': user_entity.account.email(),
   109       'sender': current_user_entity.account.email(),
   110       'sender': current_user_entity.account.email(),
   110       'subject': DEF_WELCOME_FMT % {
   111       'subject': DEF_WELCOME_MSG_FMT % {
   111           'name': user_entity.name
   112           'name': user_entity.name
   112           }
   113           }
   113       } 
   114       } 
   114 
   115 
   115   # send out the message using the default welcome template    
   116   # send out the message using the default welcome template