annotate gpp/core/functions.py @ 14:7b6540b185d9

Added get_absolute_url() for my comments. Had to add a get_absolute_url() function for downloads in the process.
author Brian Neal <bgneal@gmail.com>
date Sat, 18 Apr 2009 19:14:17 +0000
parents b3b11edf91d8
children 91fd31dc78fb
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 from core import logging
gremmie@1 8
gremmie@1 9
gremmie@1 10 def send_mail(subject, message, from_email, recipient_list,
gremmie@1 11 fail_silently = False, auth_user = None, auth_password = None):
gremmie@1 12 """The main gpp send email function.
gremmie@1 13 Use this function to send email from the site. It will obey debug settings and
gremmie@1 14 log all emails.
gremmie@1 15 """
gremmie@1 16
gremmie@1 17 if settings.GPP_SEND_EMAIL:
gremmie@1 18 django.core.mail.send_mail(subject, message, from_email, recipient_list,
gremmie@1 19 fail_silently, auth_user, auth_password)
gremmie@1 20
gremmie@1 21 logging.info('EMAIL:\nFrom: %s\nTo: %s\nSubject: %s\nMessage:\n%s' %
gremmie@1 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@9 53 # vim: ts=4 sw=4