app/soc/logic/helper/notifications.py
changeset 1546 cc54ada3cf1b
parent 1533 50fb3a9b6615
child 1548 15caebd3304d
equal deleted inserted replaced
1545:ce5d37a38091 1546:cc54ada3cf1b
   174   notification_url = "http://%(host)s%(index)s" % {
   174   notification_url = "http://%(host)s%(index)s" % {
   175       'host' : os.environ['HTTP_HOST'],
   175       'host' : os.environ['HTTP_HOST'],
   176       'index': redirects.getPublicRedirect(notification_entity,
   176       'index': redirects.getPublicRedirect(notification_entity,
   177           model_view.notification.view.getParams())}
   177           model_view.notification.view.getParams())}
   178 
   178 
   179 
   179   sender = mail_dispatcher.getDefaultMailSender()
   180   # TODO(Lennard): Change the sender to the no-reply address
   180 
       
   181   if not sender:
       
   182     # no valid sender found, abort
       
   183     return
   181 
   184 
   182   # create the message contents
   185   # create the message contents
   183   messageProperties = {
   186   messageProperties = {
   184       'to_name': notification_entity.scope.name,
   187       'to_name': notification_entity.scope.name,
   185       'sender_name': current_user_entity.name,
   188       'sender_name': current_user_entity.name,
   186       'to': notification_entity.scope.account.email(),
   189       'to': notification_entity.scope.account.email(),
   187       'sender': current_user_entity.account.email(),
   190       'sender': sender,
   188       'subject': force_unicode(DEF_NEW_NOTIFICATION_MSG),
   191       'subject': force_unicode(DEF_NEW_NOTIFICATION_MSG),
   189       'notification' : notification_entity,
   192       'notification' : notification_entity,
   190       'notification_url' : notification_url
   193       'notification_url' : notification_url
   191       }
   194       }
   192 
   195 
   200 
   203 
   201     Args:
   204     Args:
   202       user_entity: User entity which the message should be send to
   205       user_entity: User entity which the message should be send to
   203   """
   206   """
   204 
   207 
   205   # get user logic
   208   # get site name
   206   user_logic = model_logic.user
   209   site_entity = model_logic.site.logic.getSingleton()
   207   site_logic = model_logic.site
       
   208 
       
   209   # get the current user
       
   210   current_user_entity = user_logic.logic.getForCurrentAccount()
       
   211   site_entity = site_logic.logic.getSingleton()
       
   212   site_name = site_entity.site_name
   210   site_name = site_entity.site_name
   213 
   211 
   214   email = site_entity.noreply_email
   212   # get the default mail sender
   215   if not email:
   213   sender = mail_dispatcher.getDefaultMailSender()
   216     # TODO(Lennard): What if current_user_entity is None?
   214 
   217     email = current_user_entity.account.email()
   215   if not sender:
   218 
   216     # no valid sender found, should not happen but abort anyway
   219   # TODO(Lennard): change the message sender to some sort of no-reply adress
   217     return
   220   # that is probably a setting in sitesettings. (adress must be a developer).
       
   221   # This is due to a GAE limitation that allows only devs or the current user
       
   222   # to send an email. Currently this results in a user receiving the same
       
   223   # email twice.
       
   224 
   218 
   225   # create the message contents
   219   # create the message contents
   226   messageProperties = {
   220   messageProperties = {
   227       'to_name': user_entity.name,
   221       'to_name': user_entity.name,
   228       'sender_name': site_name,
   222       'sender_name': site_name,
   229       'site_name': site_name,
   223       'site_name': site_name,
   230       'to': user_entity.account.email(),
   224       'to': user_entity.account.email(),
   231       'sender': email,
   225       'sender': sender,
   232       'subject': DEF_WELCOME_MSG_FMT % {
   226       'subject': DEF_WELCOME_MSG_FMT % {
   233           'site_name': site_name,
   227           'site_name': site_name,
   234           'name': user_entity.name
   228           'name': user_entity.name
   235           }
   229           }
   236       }
   230       }