annotate gpp/core/functions.py @ 72:7f199c85a07c

#19 Use new google maps API key for the entire surfguitar101.com domain.
author Brian Neal <bgneal@gmail.com>
date Wed, 01 Jul 2009 18:38:25 +0000
parents c14cfd6be87a
children b7ac381996e8
rev   line source
gremmie@1 1 """This file houses various core utility functions for GPP"""
gremmie@1 2
gremmie@1 3 import django.core.mail
gremmie@1 4 from django.contrib.sites.models import Site
gremmie@1 5 from django.conf import settings
gremmie@1 6
gremmie@1 7
gremmie@1 8 def send_mail(subject, message, from_email, recipient_list,
gremmie@1 9 fail_silently = False, auth_user = None, auth_password = None):
gremmie@1 10 """The main gpp send email function.
gremmie@1 11 Use this function to send email from the site. It will obey debug settings and
gremmie@1 12 log all emails.
gremmie@1 13 """
gremmie@1 14
gremmie@1 15 if settings.GPP_SEND_EMAIL:
gremmie@1 16 django.core.mail.send_mail(subject, message, from_email, recipient_list,
gremmie@1 17 fail_silently, auth_user, auth_password)
gremmie@1 18
bgneal@38 19 import logging
bgneal@38 20 logging.debug('EMAIL:\nFrom: %s\nTo: %s\nSubject: %s\nMessage:\n%s' %
bgneal@38 21 (from_email, str(recipient_list), subject, message))
gremmie@1 22
gremmie@1 23
gremmie@1 24 def email_admins(subject, message):
gremmie@1 25 """Emails the site admins. Goes through the site send_mail function."""
gremmie@1 26 site = Site.objects.get_current()
gremmie@1 27 subject = '[%s] %s' % (site.name, subject)
gremmie@1 28 send_mail(subject,
gremmie@1 29 message,
gremmie@1 30 '%s@%s' % (settings.GPP_NO_REPLY_EMAIL, site.domain),
gremmie@1 31 [mail_tuple[1] for mail_tuple in settings.ADMINS])
gremmie@1 32
gremmie@1 33
gremmie@1 34 def email_managers(subject, message):
gremmie@1 35 """Emails the site managers. Goes through the site send_mail function."""
gremmie@1 36 site = Site.objects.get_current()
gremmie@1 37 subject = '[%s] %s' % (site.name, subject)
gremmie@1 38 send_mail(subject,
gremmie@1 39 msg,
gremmie@1 40 '%s@%s' % (settings.GPP_NO_REPLY_EMAIL, site.domain),
gremmie@1 41 [mail_tuple[1] for mail_tuple in settings.MANAGERS])
gremmie@1 42
gremmie@1 43
gremmie@1 44 def get_full_name(user):
gremmie@1 45 """Returns the user's full name if available, otherwise falls back
gremmie@1 46 to the username."""
gremmie@1 47 full_name = user.get_full_name()
gremmie@1 48 if full_name:
gremmie@1 49 return full_name
gremmie@1 50 return user.username
bgneal@9 51