summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-10-26 18:28:30 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-10-26 18:28:30 -0400
commit4a630e66cc502ece57405a7b72c4bc1b55ab71f3 (patch)
tree9376df5986fb687e5aaa7924f4988526de7265fd
parent2a3eef1264672c43ad96d75f38d47443c3f1177a (diff)
downloadaskbot-4a630e66cc502ece57405a7b72c4bc1b55ab71f3.tar.gz
askbot-4a630e66cc502ece57405a7b72c4bc1b55ab71f3.tar.bz2
askbot-4a630e66cc502ece57405a7b72c4bc1b55ab71f3.zip
made htmldiff to be sent in instant email updates on content edits
-rw-r--r--askbot/models/__init__.py20
-rw-r--r--askbot/models/answer.py4
-rw-r--r--askbot/models/question.py4
3 files changed, 24 insertions, 4 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index ef53828a..d37f68a0 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -31,6 +31,7 @@ from askbot.models.repute import Badge, Award, Repute
from askbot import auth
from askbot.utils.decorators import auto_now_timestamp
from askbot.utils.slug import slugify
+from askbot.utils.diff import textDiff as htmldiff
from askbot.startup_tests import run_startup_tests
run_startup_tests()
@@ -1512,10 +1513,27 @@ def format_instant_notification_email(
else:
raise ValueError('unexpected update_type %s' % update_type)
+ if update_type.endswith('update'):
+ assert('comment' not in update_type)
+ revisions = post.revisions.all()[:2]
+ assert(len(revisions) == 2)
+ content_preview = htmldiff(
+ revisions[1].as_html(),
+ revisions[0].as_html()
+ )
+ #todo: remove hardcoded style
+ content_preview += """<style type ="text/css">
+ del {color: #ff5f5f};
+ ins {background-color: #97ff97};
+ </style>
+ """
+ else:
+ content_preview = post.html
+
update_data = {
'update_author_name': from_user.username,
'receiving_user_name': to_user.username,
- 'content_preview': post.html,#post.get_snippet()
+ 'content_preview': content_preview,#post.get_snippet()
'update_type': update_type,
'post_url': site_url + post.get_absolute_url(),
'origin_post_title': origin_post.title,
diff --git a/askbot/models/answer.py b/askbot/models/answer.py
index 71b8c8e0..16463616 100644
--- a/askbot/models/answer.py
+++ b/askbot/models/answer.py
@@ -116,8 +116,8 @@ class Answer(content.Content, DeletableContent):
#self.html is denormalized in save()
self.text = text
#todo: bug wiki has no effect here
- self.parse_and_save(author = edited_by)
+ #must add revision before saving the answer
self.add_revision(
author = edited_by,
revised_at = edited_at,
@@ -125,6 +125,8 @@ class Answer(content.Content, DeletableContent):
comment = comment
)
+ self.parse_and_save(author = edited_by)
+
self.question.last_activity_at = edited_at
self.question.last_activity_by = edited_by
self.question.save()
diff --git a/askbot/models/question.py b/askbot/models/question.py
index 27a718ae..81116e0d 100644
--- a/askbot/models/question.py
+++ b/askbot/models/question.py
@@ -525,8 +525,6 @@ class Question(content.Content, DeletableContent):
if self.wiki == False and wiki == True:
self.wiki = True
- self.parse_and_save(author = edited_by)
-
# Update the Question tag associations
if latest_revision.tagnames != tags:
tags_updated = self.update_tags(tags, edited_by)
@@ -539,6 +537,8 @@ class Question(content.Content, DeletableContent):
comment = comment,
)
+ self.parse_and_save(author = edited_by)
+
def add_revision(self,author=None, text=None, comment=None, revised_at=None):
if None in (author, text, comment):
raise Exception('author, text and comment are required arguments')