2013-09-15 12:29:56 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Message ( models.Model ):
|
|
|
|
|
|
|
|
titel = models.CharField( max_length = 100, verbose_name = _("titel") )
|
|
|
|
text = models.TextField( blank=False, verbose_name = _("text") )
|
|
|
|
|
|
|
|
creation_time = models.DateTimeField( verbose_name=_("creation_time") )
|
|
|
|
|
|
|
|
author = models.ForeignKey( User, verbose_name=_("Author") )
|
|
|
|
|
|
|
|
|
2013-10-15 21:51:05 +02:00
|
|
|
def __unicode__( self ):
|
|
|
|
return self.author.username + " : " + self.titel
|
|
|
|
|
2013-09-15 12:29:56 +02:00
|
|
|
|
2013-11-01 12:42:57 +01:00
|
|
|
|
|
|
|
from django.db.models.signals import post_save
|
|
|
|
from django.dispatch import receiver
|
|
|
|
|
|
|
|
from django.core.mail import EmailMultiAlternatives
|
|
|
|
|
2013-11-10 20:47:05 +01:00
|
|
|
#from musicians.models import Musician
|
2013-11-01 12:42:57 +01:00
|
|
|
|
|
|
|
from django.template.loader import get_template
|
|
|
|
|
|
|
|
from django.template import Context
|
|
|
|
|
|
|
|
@receiver(post_save, sender=Message)
|
|
|
|
def my_handler(sender, instance, created, **kwargs):
|
|
|
|
if not created:
|
|
|
|
return
|
|
|
|
|
2013-11-10 20:47:05 +01:00
|
|
|
#receivers = [ m.user.email for m in Musician.objects.all() ]
|
2013-11-01 12:42:57 +01:00
|
|
|
# overwrite only to me for now
|
2013-11-10 20:47:05 +01:00
|
|
|
receivers = [ 'forum@blechreiz.com' ]
|
2013-11-01 12:42:57 +01:00
|
|
|
|
|
|
|
subject = "Blechreiz Forum: " + instance.titel
|
|
|
|
from_email = 'forum@blechreiz.com'
|
|
|
|
|
|
|
|
c = { 'messages': Message.objects.all().order_by('-creation_time')[:10] }
|
|
|
|
|
|
|
|
text_template = get_template( "simpleforum/mail.txt" )
|
2013-11-10 20:47:05 +01:00
|
|
|
#html_template = get_template( "simpleforum/mail.html" )
|
2013-11-01 12:42:57 +01:00
|
|
|
|
|
|
|
text_content = text_template.render( Context(c) )
|
|
|
|
#html_content = html_template.render( Context(c) )
|
|
|
|
|
|
|
|
msg = EmailMultiAlternatives( subject, text_content, from_email, receivers )
|
|
|
|
#msg.attach_alternative( html_content, "text/html" )
|
|
|
|
msg.send()
|
|
|
|
|