40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
from django.core.mail import EmailMultiAlternatives
|
|
from django.conf import settings
|
|
from django.core.urlresolvers import reverse
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
def notify_subscribers(post):
|
|
from apps.forum.models import Post
|
|
|
|
topic = post.topic
|
|
if post != topic.head:
|
|
for user in topic.subscribers.all():
|
|
if user != post.user:
|
|
subject = u'RE: %s' % topic.name
|
|
from_email = settings.DEFAULT_FROM_EMAIL
|
|
to_email = user.email
|
|
text_content = text_version(post)
|
|
#html_content = html_version(post)
|
|
msg = EmailMultiAlternatives(subject, text_content, from_email, [to_email])
|
|
#msg.attach_alternative(html_content, "text/html")
|
|
msg.send(fail_silently=True)
|
|
|
|
|
|
TEXT_TEMPLATE = _(u"""New reply from %(username)s to topic that you have subscribed on.
|
|
---
|
|
%(message)s
|
|
---
|
|
See topic: %(post_url)s
|
|
Unsubscribe %(unsubscribe_url)s""")
|
|
|
|
def text_version(post):
|
|
data = TEXT_TEMPLATE % {
|
|
'username': post.user.username,
|
|
'message': post.body_text,
|
|
'post_url': absolute_url(post.get_absolute_url()),
|
|
'unsubscribe_url': absolute_url(reverse('forum_delete_subscription', args=[post.topic.id])),
|
|
}
|
|
return data
|
|
|
|
def absolute_url(uri):
|
|
return 'http://%s%s' % (settings.FORUM_HOST, uri)
|