From efc6101f165b48f588d47b73fd5cfb355f5816a6 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Fri, 23 Mar 2012 00:11:22 -0400 Subject: added second format for the instant notification --- askbot/models/__init__.py | 21 +++++---------------- askbot/models/post.py | 45 +++++++++++++++++++++++++++++++++++++++++++-- askbot/models/question.py | 15 +++++++++++++++ 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 089c83a5..c5e8c46f 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -2375,22 +2375,11 @@ def format_instant_notification_email( content_preview = post.format_for_email() #add indented summaries for the parent posts - quote_level = 0 - current_post = post - while True: - parent_post = current_post.get_parent_post() - if parent_post is None: - break - quote_level += 1 - content_preview += _( - 'In reply to %(user)s %(post)s of %(date)s
' - ) % { - 'user': parent_post.author.username, - 'post': _(parent_post.post_type), - 'date': parent_post.added_at.strftime('%I:%M %p, %d %b %Y') - } - content_preview += parent_post.format_for_email(quote_level = quote_level) - current_post = parent_post + content_preview += post.format_for_email_as_parent_thread_summary() + + content_preview += '======= Full thread summary =======' + + content_preview += post.thread.format_for_email() update_data = { 'update_author_name': from_user.username, diff --git a/askbot/models/post.py b/askbot/models/post.py index 2f6254a4..cd8301b8 100644 --- a/askbot/models/post.py +++ b/askbot/models/post.py @@ -13,6 +13,7 @@ from django.core import urlresolvers from django.db import models from django.utils import html as html_utils from django.utils.translation import ugettext as _ +from django.utils.translation import ungettext from django.utils.http import urlquote as django_urlquote from django.core import exceptions as django_exceptions from django.core.exceptions import ValidationError @@ -564,7 +565,7 @@ class Post(models.Model): from askbot.templatetags.extra_filters_jinja import absolutize_urls_func output = '' if self.post_type == 'question': - output =+ '%s
' % self.thread.title + output += '%s
' % self.thread.title output += absolutize_urls_func(self.html) if self.post_type == 'question':#add tags to the question @@ -574,7 +575,47 @@ class Post(models.Model): quote_level = quote_level - 1 output = '
%s
' % (quote_style, output) return output - + + def format_for_email_as_parent_thread_summary(self): + """format for email as summary of parent posts + all the way to the original question""" + quote_level = 0 + current_post = self + output = '' + while True: + parent_post = current_post.get_parent_post() + if parent_post is None: + break + quote_level += 1 + output += _( + 'In reply to %(user)s %(post)s of %(date)s
' + ) % { + 'user': parent_post.author.username, + 'post': _(parent_post.post_type), + 'date': parent_post.added_at.strftime('%I:%M %p, %d %b %Y') + } + output += parent_post.format_for_email(quote_level = quote_level) + current_post = parent_post + return output + + def format_for_email_as_subthread(self): + """outputs question or answer and all it's comments + returns empty string for all other post types + """ + if self.post_type in ('question', 'answer'): + output = self.format_for_email() + comments = self.get_cached_comments() + if comments: + comments_heading = ungettext( + '%(count)d comment:', + '%(count)d comments:', + len(comments) + ) % {'count': len(comments)} + output += '

%s

' % comments_heading + for comment in comments: + output += comment.format_for_email(quote_level = 1) + else: + return '' def set_cached_comments(self, comments): """caches comments in the lifetime of the object diff --git a/askbot/models/question.py b/askbot/models/question.py index 8c61385c..2f5884ae 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -9,6 +9,7 @@ from django.core import cache # import cache, not from cache import cache, to b from django.core.urlresolvers import reverse from django.utils.hashcompat import md5_constructor from django.utils.translation import ugettext as _ +from django.utils.translation import ungettext import askbot import askbot.conf @@ -416,6 +417,20 @@ class Thread(models.Model): else: return self.title + def format_for_email(self): + """experimental function: output entire thread for email""" + question, answers, junk = self.get_cached_post_data() + output = question.format_for_email_as_subthread() + if answers: + answer_heading = ungettext( + '%(count)d answer:', + '%(count)d answers:', + len(answers) + ) + output += '

%s

' % answer_heading + for answer in answers: + output += answer.format_for_email_as_subthread() + def tagname_meta_generator(self): return u','.join([unicode(tag) for tag in self.get_tag_names()]) -- cgit v1.2.3-1-g7c22