app/soc/logic/models/request.py
changeset 619 7b61da3d4306
parent 618 b2319f2633bc
child 620 e74e0b74625f
equal deleted inserted replaced
618:b2319f2633bc 619:7b61da3d4306
    22   '"Lennard de Rijk" <ljvderijk@gmail.com>'
    22   '"Lennard de Rijk" <ljvderijk@gmail.com>'
    23   ]
    23   ]
    24 
    24 
    25 from google.appengine.api import users
    25 from google.appengine.api import users
    26 
    26 
       
    27 from django.utils.translation import ugettext_lazy
       
    28 
    27 from soc.logic import mail_dispatcher
    29 from soc.logic import mail_dispatcher
    28 from soc.logic.models import base
    30 from soc.logic.models import base
    29 from soc.logic.models import user as user_logic
    31 from soc.logic.models import user as user_logic
    30 
    32 
    31 import os
    33 import os
    34 
    36 
    35 
    37 
    36 class Logic(base.Logic):
    38 class Logic(base.Logic):
    37   """Logic methods for the Request model.
    39   """Logic methods for the Request model.
    38   """
    40   """
       
    41 
       
    42   DEF_INVITATION_FMT = ugettext_lazy(
       
    43       "Invitation to become a %(role)s for %(group)s")
    39 
    44 
    40   def __init__(self, model=soc.models.request.Request,
    45   def __init__(self, model=soc.models.request.Request,
    41                base_model=None):
    46                base_model=None):
    42     """Defines the name, key_name and model for this entity.
    47     """Defines the name, key_name and model for this entity.
    43     """
    48     """
    75       pass
    80       pass
    76 
    81 
    77     
    82     
    78   def sendInviteMessage(self, entity):
    83   def sendInviteMessage(self, entity):
    79     """Sends out an invite notification to the user the request is for.
    84     """Sends out an invite notification to the user the request is for.
    80     
    85 
    81     Args:
    86     Args:
    82       entity : A request containing the information needed to create the message
    87       entity : A request containing the information needed to create the message
    83     
       
    84     """
    88     """
       
    89 
    85     # get the current user
    90     # get the current user
    86     properties = {'account': users.get_current_user()}
    91     properties = {'account': users.get_current_user()}
    87     current_user_entity = user_logic.logic.getForFields(properties, unique=True)
    92     current_user_entity = user_logic.logic.getForFields(properties, unique=True)
    88     
    93 
    89     # get the user the request is for
    94     # get the user the request is for
    90     properties = {'link_id': entity.link_id }
    95     properties = {'link_id': entity.link_id }
    91     request_user_entity = user_logic.logic.getForFields(properties, unique=True)
    96     request_user_entity = user_logic.logic.getForFields(properties, unique=True)
    92     
    97 
    93     # create the invitation_url
    98     # create the invitation_url
    94     invitation_url = "%(host)s%(index)s" % {
    99     invitation_url = "%(host)s%(index)s" % {
    95                           'host' : os.environ['HTTP_HOST'], 
   100                           'host' : os.environ['HTTP_HOST'], 
    96                           'index': self.inviteAcceptedRedirect(entity, None)
   101                           'index': self.inviteAcceptedRedirect(entity, None)
    97                           }
   102                           }
    98     
   103 
    99     # get the group entity
   104     # get the group entity
   100     group_entity = entity.scope
   105     group_entity = entity.scope
   101     
   106 
   102     messageProperties = {
   107     messageProperties = {
   103                       'to_name': request_user_entity.name,
   108         'to_name': request_user_entity.name,
   104                       'sender_name': current_user_entity.name,
   109         'sender_name': current_user_entity.name,
   105                       'role': entity.role,
   110         'role': entity.role,
   106                       'group': group_entity.name,
   111         'group': group_entity.name,
   107                       'invitation_url': invitation_url,
   112         'invitation_url': invitation_url,
   108                       'to': request_user_entity.account.email(),
   113         'to': request_user_entity.account.email(),
   109                       'sender': current_user_entity.account.email(),
   114         'sender': current_user_entity.account.email(),
   110                       'subject': "Invitation to become a %(role)s for %(group)s"
   115         'subject': self.DEF_INVITATION_FMT % {
   111                          %{'role': entity.role, 'group': group_entity.name},
   116             'role': entity.role,
   112                       }
   117             'group': group_entity.name
   113     
   118             },
       
   119         }
       
   120 
   114     # send out the message using the default invitation template    
   121     # send out the message using the default invitation template    
   115     mail_dispatcher.sendMailFromTemplate('soc/mail/invitation.html', 
   122     mail_dispatcher.sendMailFromTemplate('soc/mail/invitation.html', 
   116                                          messageProperties)
   123                                          messageProperties)
   117     
   124 
   118   def inviteAcceptedRedirect(self, entity, _):
   125   def inviteAcceptedRedirect(self, entity, _):
   119     """Returns the redirect for accepting an invite
   126     """Returns the redirect for accepting an invite
   120     """
   127     """
   121 
   128 
   122     return '/%s/create/%s/%s' % (
   129     return '/%s/create/%s/%s' % (