# HG changeset patch # User Lennard de Rijk # Date 1228083339 0 # Node ID 2f5322ad1f5ba1fe4f8d3ab302046a8f5f64a380 # Parent ad58da0b78e88c19279e8d007a036f2a3ad5758b Moved sendInviteMessage to a new module in logic/helper/notifications.py. Renamed sendInviteMessage to sendInviteNotification. Removed the now obsolete imports in logic/models/request.py. This has been done to keep the models/logic modules clean. diff -r ad58da0b78e8 -r 2f5322ad1f5b app/soc/logic/helper/__init__.py diff -r ad58da0b78e8 -r 2f5322ad1f5b app/soc/logic/helper/notifications.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/logic/helper/notifications.py Sun Nov 30 22:15:39 2008 +0000 @@ -0,0 +1,79 @@ +#!/usr/bin/python2.5 +# +# Copyright 2008 the Melange authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Helper functions for sending out notifications +""" + +__authors__ = [ + '"Lennard de Rijk" ', + ] + +from google.appengine.api import users + +from django.utils.translation import ugettext_lazy + +from soc.logic import mail_dispatcher +from soc.logic.models import user as user_logic + +from soc.views.helper import redirects + +import os + + +DEF_INVITATION_FMT = ugettext_lazy( + "Invitation to become a %(role)s for %(group)s") + + +def sendInviteNotification(entity): + """Sends out an invite notification to the user the request is for. + + Args: + entity : A request containing the information needed to create the message + """ + + # get the current user + properties = {'account': users.get_current_user()} + current_user_entity = user_logic.logic.getForFields(properties, unique=True) + + # get the user the request is for + properties = {'link_id': entity.link_id } + request_user_entity = user_logic.logic.getForFields(properties, unique=True) + + # create the invitation_url + invitation_url = "%(host)s%(index)s" % { + 'host' : os.environ['HTTP_HOST'], + 'index': redirects.inviteAcceptedRedirect(entity, None)} + + # get the group entity + group_entity = entity.scope + + messageProperties = { + 'to_name': request_user_entity.name, + 'sender_name': current_user_entity.name, + 'role': entity.role, + 'group': group_entity.name, + 'invitation_url': invitation_url, + 'to': request_user_entity.account.email(), + 'sender': current_user_entity.account.email(), + 'subject': DEF_INVITATION_FMT % { + 'role': entity.role, + 'group': group_entity.name + }, + } + + # send out the message using the default invitation template + mail_dispatcher.sendMailFromTemplate('soc/mail/invitation.html', + messageProperties) diff -r ad58da0b78e8 -r 2f5322ad1f5b app/soc/logic/models/request.py --- a/app/soc/logic/models/request.py Sun Nov 30 21:49:14 2008 +0000 +++ b/app/soc/logic/models/request.py Sun Nov 30 22:15:39 2008 +0000 @@ -22,28 +22,16 @@ '"Lennard de Rijk" ' ] -from google.appengine.api import users +import soc.models.request -from django.utils.translation import ugettext_lazy - -from soc.logic import mail_dispatcher +from soc.logic.helper import notifications from soc.logic.models import base -from soc.logic.models import user as user_logic - -from soc.views.helper import redirects - -import os - -import soc.models.request class Logic(base.Logic): """Logic methods for the Request model. """ - DEF_INVITATION_FMT = ugettext_lazy( - "Invitation to become a %(role)s for %(group)s") - def __init__(self, model=soc.models.request.Request, base_model=None): """Defines the name, key_name and model for this entity. @@ -75,53 +63,11 @@ if entity.group_accepted: # this is an invite - self.sendInviteMessage(entity) + notifications.sendInviteNotification(entity) elif entity.user_accepted: # this is a request # TODO(Lennard) Create a new request message pass - - def sendInviteMessage(self, entity): - """Sends out an invite notification to the user the request is for. - - Args: - entity : A request containing the information needed to create the message - """ - - # get the current user - properties = {'account': users.get_current_user()} - current_user_entity = user_logic.logic.getForFields(properties, unique=True) - - # get the user the request is for - properties = {'link_id': entity.link_id } - request_user_entity = user_logic.logic.getForFields(properties, unique=True) - - # create the invitation_url - invitation_url = "%(host)s%(index)s" % { - 'host' : os.environ['HTTP_HOST'], - 'index': redirects.inviteAcceptedRedirect(entity, None)} - - # get the group entity - group_entity = entity.scope - - messageProperties = { - 'to_name': request_user_entity.name, - 'sender_name': current_user_entity.name, - 'role': entity.role, - 'group': group_entity.name, - 'invitation_url': invitation_url, - 'to': request_user_entity.account.email(), - 'sender': current_user_entity.account.email(), - 'subject': self.DEF_INVITATION_FMT % { - 'role': entity.role, - 'group': group_entity.name - }, - } - - # send out the message using the default invitation template - mail_dispatcher.sendMailFromTemplate('soc/mail/invitation.html', - messageProperties) - logic = Logic()