app/soc/logic/helper/notifications.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Thu, 08 Jan 2009 20:27:21 +0000
changeset 784 23eaf3aa19b1
parent 759 ed7a7596033e
child 792 3cc6bea5c632
permissions -rw-r--r--
Fix missing dots at the end of sentences in docstring and fix wrong import sorting in soc.logic.helper.notifications module. Patch by: Pawel Solyga Review by: to-be-reviewed
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
784
23eaf3aa19b1 Fix missing dots at the end of sentences in docstring and fix wrong import sorting in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 759
diff changeset
    25
import os
756
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    26
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
    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(
784
23eaf3aa19b1 Fix missing dots at the end of sentences in docstring and fix wrong import sorting in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 759
diff changeset
    42
  "You have received a new Notification.")
757
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(
784
23eaf3aa19b1 Fix missing dots at the end of sentences in docstring and fix wrong import sorting in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 759
diff changeset
    45
    "Invitation to become a %(role)s for %(group)s.")
635
2f5322ad1f5b Moved sendInviteMessage to a new module in logic/helper/notifications.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
784
23eaf3aa19b1 Fix missing dots at the end of sentences in docstring and fix wrong import sorting in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 759
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
759
ed7a7596033e Fixed a too long line in logic/helper/notifications.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 757
diff changeset
    84
  message = loader.render_to_string(
ed7a7596033e Fixed a too long line in logic/helper/notifications.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 757
diff changeset
    85
      'soc/notification/messages/invitation.html', 
ed7a7596033e Fixed a too long line in logic/helper/notifications.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 757
diff changeset
    86
      dictionary=messageProperties)
756
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    87
  
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    88
  # create the fields for the notification
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    89
  fields = { 
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    90
      'from_user' : current_user_entity,
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    91
      'subject' : DEF_INVITATION_MSG_FMT % {
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    92
          'role' : entity.role,
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    93
          '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
    94
          },
756
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    95
      'message' : message,
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    96
      'scope' : request_user_entity,
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    97
      'link_id' :'%i' % (time.time()),
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
    98
      '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
    99
  }
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
   100
  
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
   101
  # 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
   102
  notification_logic = model_logic.notification.logic
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
   103
  notification_logic.updateOrCreateFromFields(fields, 
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
   104
      notification_logic.getKeyFieldsFromDict(fields))
a0c0b48563cb Changed invitation email and into a notification.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 750
diff changeset
   105
  
757
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   106
def sendNewNotificationMessage(notification_entity):
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   107
  """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
   108
  
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   109
    Args:
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   110
      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
   111
  """
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   112
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   113
  # get user logic
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   114
  user_logic = model_logic.user  
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   115
  
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   116
  # get the current user
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   117
  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
   118
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   119
  # 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
   120
  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
   121
      'host' : os.environ['HTTP_HOST'], 
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   122
      'index': redirects.getPublicRedirect(notification_entity,
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   123
          model_view.notification.view.getParams())}
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   124
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
  # 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
   127
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   128
  # create the message contents
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   129
  messageProperties = {
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   130
      '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
   131
      '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
   132
      '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
   133
      '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
   134
      '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
   135
      'notification' : notification_entity,
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   136
      'notification_url' : notification_url
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   137
      }
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   138
  
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   139
  # 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
   140
  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
   141
                                       messageProperties)
640
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   142
  
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   143
def sendWelcomeMessage(user_entity):
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   144
  """Sends out a welcome message to a user.
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   145
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   146
    Args:
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   147
      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
   148
  """
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   149
  
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   150
  # get user logic
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   151
  user_logic = model_logic.user  
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   152
  
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   153
  # get the current user
757
b11cee4ab535 Added email message when receiving a notification.py
Lennard de Rijk <ljvderijk@gmail.com>
parents: 756
diff changeset
   154
  current_user_entity = user_logic.logic.getForCurrentAccount()
640
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   155
750
6e8d67d04507 Fix too long lines in soc.logic.helper.notifications module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 664
diff changeset
   156
  # 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
   157
  # 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
   158
  # 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
   159
  # 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
   160
  # 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
   161
  
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
   162
  # create the message contents
640
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   163
  messageProperties = {
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   164
      'to_name': user_entity.name,
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   165
      'sender_name': current_user_entity.name,
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   166
      'to': user_entity.account.email(),
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   167
      '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
   168
      'subject': DEF_WELCOME_MSG_FMT % {
640
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   169
          'name': user_entity.name
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
      } 
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   172
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   173
  # send out the message using the default welcome template    
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   174
  mail_dispatcher.sendMailFromTemplate('soc/mail/welcome.html', 
a62a78fe4e43 Added User welcome message.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 638
diff changeset
   175
                                       messageProperties)