annotate gpp/core/functions.py @ 180:aef00df91165

Implement #63, add a queued email facility.
author Brian Neal <bgneal@gmail.com>
date Sun, 21 Mar 2010 20:33:33 +0000
parents b7ac381996e8
children 500e5875a306
rev   line source
gremmie@1 1 """This file houses various core utility functions for GPP"""
bgneal@176 2 import datetime
gremmie@1 3
gremmie@1 4 import django.core.mail
gremmie@1 5 from django.contrib.sites.models import Site
gremmie@1 6 from django.conf import settings
gremmie@1 7
gremmie@1 8
gremmie@1 9 def send_mail(subject, message, from_email, recipient_list,
gremmie@1 10 fail_silently = False, auth_user = None, auth_password = None):
gremmie@1 11 """The main gpp send email function.
gremmie@1 12 Use this function to send email from the site. It will obey debug settings and
gremmie@1 13 log all emails.
gremmie@1 14 """
gremmie@1 15
bgneal@180 16 if settings.MAILER_ENQUEUE_MAIL:
bgneal@180 17 mailer.enqueue_mail(subject, message, from_email, recipient_list)
bgneal@180 18 elif settings.GPP_SEND_EMAIL:
gremmie@1 19 django.core.mail.send_mail(subject, message, from_email, recipient_list,
gremmie@1 20 fail_silently, auth_user, auth_password)
gremmie@1 21
bgneal@38 22 import logging
bgneal@38 23 logging.debug('EMAIL:\nFrom: %s\nTo: %s\nSubject: %s\nMessage:\n%s' %
bgneal@38 24 (from_email, str(recipient_list), subject, message))
gremmie@1 25
gremmie@1 26
gremmie@1 27 def email_admins(subject, message):
gremmie@1 28 """Emails the site admins. Goes through the site send_mail function."""
gremmie@1 29 site = Site.objects.get_current()
gremmie@1 30 subject = '[%s] %s' % (site.name, subject)
gremmie@1 31 send_mail(subject,
gremmie@1 32 message,
gremmie@1 33 '%s@%s' % (settings.GPP_NO_REPLY_EMAIL, site.domain),
gremmie@1 34 [mail_tuple[1] for mail_tuple in settings.ADMINS])
gremmie@1 35
gremmie@1 36
gremmie@1 37 def email_managers(subject, message):
gremmie@1 38 """Emails the site managers. Goes through the site send_mail function."""
gremmie@1 39 site = Site.objects.get_current()
gremmie@1 40 subject = '[%s] %s' % (site.name, subject)
gremmie@1 41 send_mail(subject,
gremmie@1 42 msg,
gremmie@1 43 '%s@%s' % (settings.GPP_NO_REPLY_EMAIL, site.domain),
gremmie@1 44 [mail_tuple[1] for mail_tuple in settings.MANAGERS])
gremmie@1 45
gremmie@1 46
gremmie@1 47 def get_full_name(user):
gremmie@1 48 """Returns the user's full name if available, otherwise falls back
gremmie@1 49 to the username."""
gremmie@1 50 full_name = user.get_full_name()
gremmie@1 51 if full_name:
gremmie@1 52 return full_name
gremmie@1 53 return user.username
bgneal@9 54
bgneal@176 55
bgneal@176 56 BASE_YEAR = 2010
bgneal@176 57
bgneal@176 58 def copyright_str():
bgneal@176 59 curr_year = datetime.datetime.now().year
bgneal@176 60 if curr_year == BASE_YEAR:
bgneal@176 61 year_range = str(BASE_YEAR)
bgneal@176 62 else:
bgneal@176 63 year_range = "%d - %d" % (BASE_YEAR, curr_year)
bgneal@176 64
bgneal@176 65 return 'Copyright (C) %s, SurfGuitar101.com' % year_range