summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-06-08 20:43:20 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-06-08 20:43:20 -0400
commit2f76b6460e0da66a2ef4251301059c84b3f5a753 (patch)
treedfb05ee36851786b499223f0d56c244f5525e69c
parente215c1d15b049b04f7a2497c07d3c9a3f380638d (diff)
downloadaskbot-2f76b6460e0da66a2ef4251301059c84b3f5a753.tar.gz
askbot-2f76b6460e0da66a2ef4251301059c84b3f5a753.tar.bz2
askbot-2f76b6460e0da66a2ef4251301059c84b3f5a753.zip
envelope turns on correctly when there are new content or mention responses
-rw-r--r--forum/models/answer.py4
-rw-r--r--forum/models/base.py32
-rw-r--r--forum/models/content.py9
-rw-r--r--forum/models/question.py4
-rw-r--r--forum/tests.py116
5 files changed, 131 insertions, 34 deletions
diff --git a/forum/models/answer.py b/forum/models/answer.py
index e8ff2e50..fd336ffa 100644
--- a/forum/models/answer.py
+++ b/forum/models/answer.py
@@ -26,7 +26,7 @@ class AnswerManager(models.Manager):
answer.last_edited_at = added_at
answer.wikified_at = added_at
- answer.parse_and_save()
+ answer.parse_and_save(author = author)
answer.add_revision(
revised_by = author,
@@ -117,7 +117,7 @@ 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()
+ self.parse_and_save(author = edited_by)
self.add_revision(
revised_by=edited_by,
diff --git a/forum/models/base.py b/forum/models/base.py
index 29d4fff3..c6c196fc 100644
--- a/forum/models/base.py
+++ b/forum/models/base.py
@@ -46,8 +46,6 @@ def parse_post_text(post):
if '@' in text:
from forum.models.user import Activity
- mentioned_by = post.get_last_author()
-
op = post.get_origin_post()
anticipated_authors = op.get_author_list(
include_comments = True,
@@ -97,15 +95,18 @@ def parse_post_text(post):
}
return data
-def parse_and_save_post(post, **kwargs):
+#todo: when models are merged, it would be great to remove author parameter
+def parse_and_save_post(post, author = None, **kwargs):
"""generic method to use with posts to be used prior to saving
post edit or addition
"""
+ assert(author is not None)
+
data = post.parse()
post.html = data['html']
- newly_mentioned_users = data['newly_mentioned_users']
+ newly_mentioned_users = set(data['newly_mentioned_users']) - set([author])
removed_mentions = data['removed_mentions']
#a hack allowing to save denormalized .summary field for questions
@@ -121,27 +122,22 @@ def parse_and_save_post(post, **kwargs):
#this save must precede saving the mention activity
#because generic relation needs primary key of the related object
super(post.__class__, post).save(**kwargs)
- last_author = post.get_last_author()
-
-
- last_author = post.get_last_author()
#create new mentions
for u in newly_mentioned_users:
from forum.models.user import Activity
- if u != last_author:
- Activity.objects.create_new_mention(
- mentioned_whom = u,
- mentioned_in = post,
- mentioned_by = last_author
- )
+ Activity.objects.create_new_mention(
+ mentioned_whom = u,
+ mentioned_in = post,
+ mentioned_by = author
+ )
#todo: this is handled in signal because models for posts
#are too spread out
from forum.models import signals
signals.post_updated.send(
post = post,
- updated_by = last_author,
+ updated_by = author,
newly_mentioned_users = newly_mentioned_users,
timestamp = post.get_time_of_last_edit(),
created = created,
@@ -160,12 +156,6 @@ class UserContent(models.Model):
abstract = True
app_label = 'forum'
- def get_last_author(self):
- """
- get author who last edited the content
- since here we don't have revisions, it will be the creator
- """
- return self.user
class MetaContent(models.Model):
"""
diff --git a/forum/models/content.py b/forum/models/content.py
index ec7f26b8..fd73c419 100644
--- a/forum/models/content.py
+++ b/forum/models/content.py
@@ -65,7 +65,7 @@ class Content(models.Model):
user=user,
added_at=added_at
)
- comment.parse_and_save()
+ comment.parse_and_save(author = user)
self.comment_count = self.comment_count + 1
self.save()
return comment
@@ -185,13 +185,6 @@ class Content(models.Model):
def get_latest_revision_number(self):
return self.get_latest_revision().revision
- def get_last_author(self):
- #todo: fix this issue
- if self.last_edited_by:
- return self.last_edited_by
- else:
- return self.author
-
def get_time_of_last_edit(self):
if self.last_edited_at:
return self.last_edited_at
diff --git a/forum/models/question.py b/forum/models/question.py
index 8e137e2e..f24aecc7 100644
--- a/forum/models/question.py
+++ b/forum/models/question.py
@@ -54,7 +54,7 @@ class QuestionManager(models.Manager):
question.last_edited_at = added_at
question.wikified_at = added_at
- question.parse_and_save()
+ question.parse_and_save(author = author)
question.add_revision(
author=author,
@@ -422,7 +422,7 @@ class Question(content.Content, DeletableContent):
if self.wiki == False and wiki == True:
self.wiki = True
- self.parse_and_save()
+ self.parse_and_save(author = edited_by)
# Update the Question tag associations
if latest_revision.tagnames != tags:
diff --git a/forum/tests.py b/forum/tests.py
index d93e7d4e..28544b73 100644
--- a/forum/tests.py
+++ b/forum/tests.py
@@ -135,7 +135,7 @@ class UpdateNotificationTests(TestCase):
timestamp = datetime.datetime.now()
self.question.add_comment(
user = self.u11,
- comment = 'self-comment 1',
+ comment = 'self-comment',
added_at = timestamp
)
notifications = get_re_notif_after(timestamp)
@@ -203,6 +203,120 @@ class UpdateNotificationTests(TestCase):
]
)
+ def test_self_mention_not_posting_in_comment_to_question1(self):
+ self.reset_response_counts()
+ time.sleep(1)
+ timestamp = datetime.datetime.now()
+ self.question.add_comment(
+ user = self.u11,
+ comment = 'self-comment @user11',
+ added_at = timestamp
+ )
+ notifications = get_re_notif_after(timestamp)
+ self.assertEqual(len(notifications), 1)
+ self.assertEqual(
+ set(notifications[0].receiving_users.all()),
+ set([self.u12, self.u13]),
+ )
+ self.reload_users()
+ self.assertEqual(
+ [
+ self.u11.response_count,
+ self.u12.response_count,
+ self.u13.response_count,
+ self.u14.response_count,
+ self.u21.response_count,
+ self.u22.response_count,
+ self.u23.response_count,
+ self.u24.response_count,
+ self.u31.response_count,
+ self.u32.response_count,
+ self.u33.response_count,
+ self.u34.response_count,
+ ],
+ [
+ 0, 1, 1, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ ]
+ )
+
+ def test_self_mention_not_posting_in_comment_to_question2(self):
+ self.reset_response_counts()
+ time.sleep(1)
+ timestamp = datetime.datetime.now()
+ self.question.add_comment(
+ user = self.u11,
+ comment = 'self-comment @user11 blah',
+ added_at = timestamp
+ )
+ notifications = get_re_notif_after(timestamp)
+ self.assertEqual(len(notifications), 1)
+ self.assertEqual(
+ set(notifications[0].receiving_users.all()),
+ set([self.u12, self.u13]),
+ )
+ self.reload_users()
+ self.assertEqual(
+ [
+ self.u11.response_count,
+ self.u12.response_count,
+ self.u13.response_count,
+ self.u14.response_count,
+ self.u21.response_count,
+ self.u22.response_count,
+ self.u23.response_count,
+ self.u24.response_count,
+ self.u31.response_count,
+ self.u32.response_count,
+ self.u33.response_count,
+ self.u34.response_count,
+ ],
+ [
+ 0, 1, 1, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ ]
+ )
+
+ def test_self_mention_not_posting_in_comment_to_answer(self):
+ self.reset_response_counts()
+ time.sleep(1)
+ timestamp = datetime.datetime.now()
+ self.answer1.add_comment(
+ user = self.u21,
+ comment = 'self-comment 1 @user21',
+ added_at = timestamp
+ )
+ notifications = get_re_notif_after(timestamp)
+ self.assertEqual(len(notifications), 1)
+ self.assertEqual(
+ set(notifications[0].receiving_users.all()),
+ set([self.u22, self.u23]),
+ )
+ self.reload_users()
+ self.assertEqual(
+ [
+ self.u11.response_count,
+ self.u12.response_count,
+ self.u13.response_count,
+ self.u14.response_count,
+ self.u21.response_count,
+ self.u22.response_count,
+ self.u23.response_count,
+ self.u24.response_count,
+ self.u31.response_count,
+ self.u32.response_count,
+ self.u33.response_count,
+ self.u34.response_count,
+ ],
+ [
+ 0, 0, 0, 0,
+ 0, 1, 1, 0,
+ 0, 0, 0, 0,
+ ]
+ )
+
def test_comments_to_post_authors(self):
self.question.apply_edit(
edited_by = self.u14,