diff options
author | Dan McGee <dpmcgee@gmail.com> | 2010-08-13 08:45:29 -0500 |
---|---|---|
committer | Dan McGee <dpmcgee@gmail.com> | 2010-08-13 08:45:29 -0500 |
commit | 41fa83f94a04db7273a3c7884eb32a43bdf7d5eb (patch) | |
tree | dc18bcff960db732755ffa514dc8a82c6ad1518d | |
parent | 2d081bd8d43849cd62524501dfeef8f7edfc9bc1 (diff) | |
download | website-41fa83f94a04db7273a3c7884eb32a43bdf7d5eb.tar.gz website-41fa83f94a04db7273a3c7884eb32a43bdf7d5eb.zip |
Move comment email notification to templates
Signed-off-by: Dan McGee <dpmcgee@gmail.com>
-rw-r--r-- | mycomments/signals.py | 27 | ||||
-rw-r--r-- | templates/mycomments/email_body.txt | 10 | ||||
-rw-r--r-- | templates/mycomments/email_subject.txt | 1 |
3 files changed, 17 insertions, 21 deletions
diff --git a/mycomments/signals.py b/mycomments/signals.py index 6fe7fac..8357054 100644 --- a/mycomments/signals.py +++ b/mycomments/signals.py @@ -1,25 +1,10 @@ from django.contrib.sites.models import Site -from django.template import Context, Template +from django.template.loader import render_to_string from blog.models import Post from mycomments.models import MyComment, BannedIP, BannedUserName from mycomments.utils import akismet_check -SUBJECT_TEMPLATE = Template( -'New comment for post \ -"{{ post.title|safe }}" by \ -"{{ comment.user_name|safe }}"') - -BODY_TEMPLATE = Template( -'User: {{comment.user_name|safe }} ({{ usercount }} comments from this user)\n\ -Email: {{comment.user_email|safe }}\n\ -URL: {{ comment.user_url|safe }}\n\ -IP Address: {{ comment.ip_address }} ({{ ipcount }} comments from this IP)\n\ -Public?: {{ comment.is_public }}\n\n\ -{{ comment.comment|safe }}\n\n\ -Comment link: {{ commenturl }}\n\ -Admin interface: {{ adminsite }}') - def send_comment_by_mail(sender, **kwargs): import socket, errno comment = kwargs['comment'] @@ -32,20 +17,20 @@ def send_comment_by_mail(sender, **kwargs): adminsite = 'https://%s/admin/' % Site.objects.get_current().domain usercount = MyComment.objects.filter(user_name=comment.user_name).count() ipcount = MyComment.objects.filter(ip_address=comment.ip_address).count() - ctx = Context({ + content = { 'post': post, 'comment': comment, 'commenturl': commenturl, 'adminsite': adminsite, 'usercount': usercount, 'ipcount': ipcount, - }) + } # write out a subject and body - subject = SUBJECT_TEMPLATE.render(ctx).strip() - body = BODY_TEMPLATE.render(ctx) + subject = render_to_string('mycomments/email_subject.txt', content) + body = render_to_string('mycomments/email_body.txt', content) # send the email try: - post.author.email_user(subject, body) + post.author.email_user(subject.strip(), body) except socket.error, e: # TODO really should have a logger or something here if not e.errno == errno.ECONNREFUSED: diff --git a/templates/mycomments/email_body.txt b/templates/mycomments/email_body.txt new file mode 100644 index 0000000..69e254f --- /dev/null +++ b/templates/mycomments/email_body.txt @@ -0,0 +1,10 @@ +User: {{comment.user_name|safe }} ({{ usercount }} comments from this user) +Email: {{comment.user_email|safe }} +URL: {{ comment.user_url|safe }} +IP Address: {{ comment.ip_address }} ({{ ipcount }} comments from this IP) +Public?: {{ comment.is_public }} + +{{ comment.comment|safe }} + +Comment link: {{ commenturl }} +Admin interface: {{ adminsite }} diff --git a/templates/mycomments/email_subject.txt b/templates/mycomments/email_subject.txt new file mode 100644 index 0000000..e305db5 --- /dev/null +++ b/templates/mycomments/email_subject.txt @@ -0,0 +1 @@ +New comment for post "{{ post.title|safe }}" by "{{ comment.user_name|safe }}" |