annotate gpp/core/functions.py @ 176:b7ac381996e8

Implement ticket #59; update RSS feeds for Django 1.2.
author Brian Neal <bgneal@gmail.com>
date Thu, 11 Mar 2010 02:34:07 +0000
parents c14cfd6be87a
children aef00df91165
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
gremmie@1 16 if settings.GPP_SEND_EMAIL:
gremmie@1 17 django.core.mail.send_mail(subject, message, from_email, recipient_list,
gremmie@1 18 fail_silently, auth_user, auth_password)
gremmie@1 19
bgneal@38 20 import logging
bgneal@38 21 logging.debug('EMAIL:\nFrom: %s\nTo: %s\nSubject: %s\nMessage:\n%s' %
bgneal@38 22 (from_email, str(recipient_list), subject, message))
gremmie@1 23
gremmie@1 24
gremmie@1 25 def email_admins(subject, message):
gremmie@1 26 """Emails the site admins. Goes through the site send_mail function."""
gremmie@1 27 site = Site.objects.get_current()
gremmie@1 28 subject = '[%s] %s' % (site.name, subject)
gremmie@1 29 send_mail(subject,
gremmie@1 30 message,
gremmie@1 31 '%s@%s' % (settings.GPP_NO_REPLY_EMAIL, site.domain),
gremmie@1 32 [mail_tuple[1] for mail_tuple in settings.ADMINS])
gremmie@1 33
gremmie@1 34
gremmie@1 35 def email_managers(subject, message):
gremmie@1 36 """Emails the site managers. Goes through the site send_mail function."""
gremmie@1 37 site = Site.objects.get_current()
gremmie@1 38 subject = '[%s] %s' % (site.name, subject)
gremmie@1 39 send_mail(subject,
gremmie@1 40 msg,
gremmie@1 41 '%s@%s' % (settings.GPP_NO_REPLY_EMAIL, site.domain),
gremmie@1 42 [mail_tuple[1] for mail_tuple in settings.MANAGERS])
gremmie@1 43
gremmie@1 44
gremmie@1 45 def get_full_name(user):
gremmie@1 46 """Returns the user's full name if available, otherwise falls back
gremmie@1 47 to the username."""
gremmie@1 48 full_name = user.get_full_name()
gremmie@1 49 if full_name:
gremmie@1 50 return full_name
gremmie@1 51 return user.username
bgneal@9 52
bgneal@176 53
bgneal@176 54 BASE_YEAR = 2010
bgneal@176 55
bgneal@176 56 def copyright_str():
bgneal@176 57 curr_year = datetime.datetime.now().year
bgneal@176 58 if curr_year == BASE_YEAR:
bgneal@176 59 year_range = str(BASE_YEAR)
bgneal@176 60 else:
bgneal@176 61 year_range = "%d - %d" % (BASE_YEAR, curr_year)
bgneal@176 62
bgneal@176 63 return 'Copyright (C) %s, SurfGuitar101.com' % year_range