annotate gpp/core/functions.py @ 183:149c3567fec1

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