1 """The application's Globals object"""
5 from pylons import config, request
6 from paste.deploy.converters import asbool
7 from mailer import Message
9 log = logging.getLogger(__name__)
11 class Globals(object):
12 """Globals acts as a container for objects available throughout the
13 life of the application
17 """One instance of Globals is created during application
18 initialization and is available during requests via the 'g'
23 def send_message(self, msg):
25 Wrap the call to mailer.send() so that we can do stuff like defer mail
26 sending, wrap in a test fixture, selectively disable mailing in certain
29 if asbool(config.get('testing')) or asbool(config.get('network_free')):
30 if 'mailer.messages' not in request.environ:
31 request.environ['mailer.messages'] = []
32 request.environ['mailer.messages'].append(msg)
33 log.info("From: %s\nTo: %s\nSubject: %s\n\n%s",
34 msg.From, msg.To, msg.Subject, msg.Body)
38 def handle_notification(self, users, subject, body):
39 "Send a notification email."
40 recipients = [u.email for u in users if u.email is not None]
41 if len(recipients) > 0:
42 msg = Message(From=config.get('mailer.from',
45 msg.Subject = "BlueChips: %s" % subject
47 self.send_message(msg)