annotate gpp/core/functions.py @ 37:91fd31dc78fb

Removed the database logging stuff. Will replace with Python logging.
author Brian Neal <bgneal@gmail.com>
date Thu, 11 Jun 2009 01:00:31 +0000
parents b3b11edf91d8
children c14cfd6be87a
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@37 19 #logging.info('EMAIL:\nFrom: %s\nTo: %s\nSubject: %s\nMessage:\n%s' %
bgneal@37 20 # (from_email, str(recipient_list), subject, message))
gremmie@1 21
gremmie@1 22
gremmie@1 23 def email_admins(subject, message):
gremmie@1 24 """Emails the site admins. Goes through the site send_mail function."""
gremmie@1 25 site = Site.objects.get_current()
gremmie@1 26 subject = '[%s] %s' % (site.name, subject)
gremmie@1 27 send_mail(subject,
gremmie@1 28 message,
gremmie@1 29 '%s@%s' % (settings.GPP_NO_REPLY_EMAIL, site.domain),
gremmie@1 30 [mail_tuple[1] for mail_tuple in settings.ADMINS])
gremmie@1 31
gremmie@1 32
gremmie@1 33 def email_managers(subject, message):
gremmie@1 34 """Emails the site managers. Goes through the site send_mail function."""
gremmie@1 35 site = Site.objects.get_current()
gremmie@1 36 subject = '[%s] %s' % (site.name, subject)
gremmie@1 37 send_mail(subject,
gremmie@1 38 msg,
gremmie@1 39 '%s@%s' % (settings.GPP_NO_REPLY_EMAIL, site.domain),
gremmie@1 40 [mail_tuple[1] for mail_tuple in settings.MANAGERS])
gremmie@1 41
gremmie@1 42
gremmie@1 43 def get_full_name(user):
gremmie@1 44 """Returns the user's full name if available, otherwise falls back
gremmie@1 45 to the username."""
gremmie@1 46 full_name = user.get_full_name()
gremmie@1 47 if full_name:
gremmie@1 48 return full_name
gremmie@1 49 return user.username
bgneal@9 50