app/soc/logic/helper/notifications.py
changeset 1887 8b71f4e58f39
parent 1648 11c74138c56d
child 1890 a8a5da24212c
equal deleted inserted replaced
1886:660bdc99239c 1887:8b71f4e58f39
    84       'group' : entity.scope.name
    84       'group' : entity.scope.name
    85       }
    85       }
    86 
    86 
    87   template = DEF_GROUP_INVITE_NOTIFICATION_TEMPLATE
    87   template = DEF_GROUP_INVITE_NOTIFICATION_TEMPLATE
    88 
    88 
    89   sendNotification(to_user, message_properties, subject, template)
    89   from_user = model_logic.user.logic.getForCurrentAccount()
       
    90 
       
    91   sendNotification(to_user, from_user, message_properties, subject, template)
    90 
    92 
    91 
    93 
    92 def sendNewGroupNotification(entity, params):
    94 def sendNewGroupNotification(entity, params):
    93   """Sends out an invite notification to the applicant of the group.
    95   """Sends out an invite notification to the applicant of the group.
    94 
    96 
   116       'group_name': entity.name,
   118       'group_name': entity.name,
   117       }
   119       }
   118 
   120 
   119   template = DEF_NEW_GROUP_TEMPLATE
   121   template = DEF_NEW_GROUP_TEMPLATE
   120 
   122 
   121   sendNotification(to_user, message_properties, subject, template)
   123   sendNotification(to_user, None, message_properties, subject, template)
   122 
   124 
   123 
   125 
   124 def sendNotification(to_user, message_properties, subject, template):
   126 def sendNotification(to_user, from_user, message_properties, subject, template):
   125   """Sends out an notification to the specified user.
   127   """Sends out a notification to the specified user.
   126 
   128 
   127   Args:
   129   Args:
   128     to_user : user to which the notification will be send
   130     to_user : user to which the notification will be send
   129     message_properties : email message properties
   131     from_user: user from who sends the notifications (None iff sent by site)
       
   132     message_properties : message properties
   130     subject : subject of notification email
   133     subject : subject of notification email
   131     template : template used for generating notification
   134     template : template used for generating notification
   132   """
   135   """
   133 
   136 
   134   from_user = model_logic.user.logic.getForCurrentAccount()
   137   if from_user:
       
   138     sender_name = from_user.name
       
   139   else:
       
   140     site_entity = model_logic.site.logic.getSingleton()
       
   141     sender_name = 'The %s Team' %(site_entity.site_name)
   135 
   142 
   136   new_message_properties = {
   143   new_message_properties = {
   137       'sender_name': from_user.name,
   144       'sender_name': sender_name,
   138       'to_name': to_user.name,
   145       'to_name': to_user.name,
   139       }
   146       }
   140 
   147 
   141   message_properties = dicts.merge(message_properties, new_message_properties)
   148   message_properties = dicts.merge(message_properties, new_message_properties)
   142 
   149