summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2014-09-07 12:47:01 +0700
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2014-09-07 12:47:01 +0700
commitd9829a3a55e5ca96a3a995639045de94839383f4 (patch)
tree237c2a3c96f15fe2f2c33db30bdc8cf62b99f8c8
parentbc1244e44b0a7501eec74d5f5c41bbeca5041f92 (diff)
downloadaskbot-d9829a3a55e5ca96a3a995639045de94839383f4.tar.gz
askbot-d9829a3a55e5ca96a3a995639045de94839383f4.tar.bz2
askbot-d9829a3a55e5ca96a3a995639045de94839383f4.zip
allowed editing posts under moderation
-rw-r--r--askbot/models/__init__.py19
-rw-r--r--askbot/models/post.py72
-rw-r--r--askbot/models/question.py9
-rw-r--r--askbot/views/readers.py15
-rw-r--r--askbot/views/writers.py18
5 files changed, 88 insertions, 45 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index b39a11c4..3dae64b8 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -1798,7 +1798,7 @@ def user_edit_comment(
todo: add timestamp
"""
self.assert_can_edit_comment(comment_post)
- comment_post.apply_edit(
+ revision = comment_post.apply_edit(
text=body_text,
edited_at=timestamp,
edited_by=self,
@@ -1807,6 +1807,7 @@ def user_edit_comment(
ip_addr=ip_addr,
)
comment_post.thread.invalidate_cached_data()
+ return revision
def user_edit_post(self,
post=None,
@@ -1824,7 +1825,7 @@ def user_edit_post(self,
because we cannot bypass the permissions checks set within
"""
if post.post_type == 'comment':
- self.edit_comment(
+ return self.edit_comment(
comment_post=post,
body_text=body_text,
by_email=by_email,
@@ -1832,7 +1833,7 @@ def user_edit_post(self,
ip_addr=ip_addr
)
elif post.post_type == 'answer':
- self.edit_answer(
+ return self.edit_answer(
answer=post,
body_text=body_text,
timestamp=timestamp,
@@ -1842,7 +1843,7 @@ def user_edit_post(self,
ip_addr=ip_addr
)
elif post.post_type == 'question':
- self.edit_question(
+ return self.edit_question(
question=post,
body_text=body_text,
timestamp=timestamp,
@@ -1853,7 +1854,7 @@ def user_edit_post(self,
ip_addr=ip_addr
)
elif post.post_type == 'tag_wiki':
- post.apply_edit(
+ return post.apply_edit(
edited_at=timestamp,
edited_by=self,
text=body_text,
@@ -1886,7 +1887,7 @@ def user_edit_question(
if force == False:
self.assert_can_edit_question(question)
- question.apply_edit(
+ revision = question.apply_edit(
edited_at=timestamp,
edited_by=self,
title=title,
@@ -1910,6 +1911,7 @@ def user_edit_question(
context_object = question,
timestamp = timestamp
)
+ return revision
@auto_now_timestamp
def user_edit_answer(
@@ -1928,7 +1930,7 @@ def user_edit_answer(
if force == False:
self.assert_can_edit_answer(answer)
- answer.apply_edit(
+ revision = answer.apply_edit(
edited_at=timestamp,
edited_by=self,
text=body_text,
@@ -1947,6 +1949,7 @@ def user_edit_answer(
context_object = answer,
timestamp = timestamp
)
+ return revision
@auto_now_timestamp
def user_create_post_reject_reason(
@@ -1984,7 +1987,7 @@ def user_edit_post_reject_reason(
):
reason.title = title
reason.save()
- reason.details.apply_edit(
+ return reason.details.apply_edit(
edited_by = self,
edited_at = timestamp,
text = details
diff --git a/askbot/models/post.py b/askbot/models/post.py
index 18d3ea13..cd45387f 100644
--- a/askbot/models/post.py
+++ b/askbot/models/post.py
@@ -510,7 +510,7 @@ class Post(models.Model):
'html': post_html,
'newly_mentioned_users': mentioned_authors,
'removed_mentions': removed_mentions,
- }
+ }
return data
#todo: when models are merged, it would be great to remove author parameter
@@ -1853,7 +1853,7 @@ class Post(models.Model):
latest_rev.save()
else:
#otherwise we create a new revision
- self.add_revision(
+ latest_rev = self.add_revision(
author=edited_by,
revised_at=edited_at,
text=text,
@@ -1863,19 +1863,22 @@ class Post(models.Model):
is_anonymous=edit_anonymously
)
- parse_results = self.parse_and_save(author=edited_by, is_private=is_private)
+ if latest_rev.revision > 0:
+ parse_results = self.parse_and_save(author=edited_by, is_private=is_private)
- from askbot.models import signals
- signals.post_updated.send(
- post=self,
- updated_by=edited_by,
- newly_mentioned_users=parse_results['newly_mentioned_users'],
- suppress_email=suppress_email,
- timestamp=edited_at,
- created=False,
- diff=parse_results['diff'],
- sender=self.__class__
- )
+ from askbot.models import signals
+ signals.post_updated.send(
+ post=self,
+ updated_by=edited_by,
+ newly_mentioned_users=parse_results['newly_mentioned_users'],
+ suppress_email=suppress_email,
+ timestamp=edited_at,
+ created=False,
+ diff=parse_results['diff'],
+ sender=self.__class__
+ )
+
+ return latest_rev
def _answer__apply_edit(
@@ -1899,7 +1902,7 @@ class Post(models.Model):
else:
self.make_public()
- self.__apply_edit(
+ revision = self.__apply_edit(
edited_at=edited_at,
edited_by=edited_by,
text=text,
@@ -1917,6 +1920,7 @@ class Post(models.Model):
last_activity_at=edited_at,
last_activity_by=edited_by
)
+ return revision
def _question__apply_edit(
self,
@@ -1963,7 +1967,7 @@ class Post(models.Model):
else:
self.thread.make_public(recursive=False)
- self.__apply_edit(
+ revision = self.__apply_edit(
edited_at=edited_at,
edited_by=edited_by,
text=text,
@@ -1980,6 +1984,7 @@ class Post(models.Model):
last_activity_at=edited_at,
last_activity_by=edited_by
)
+ return revision
def apply_edit(self, *args, **kwargs):
#todo: unify this, here we have unnecessary indirection
@@ -2223,7 +2228,15 @@ class PostRevisionManager(models.Manager):
'revision': 0,
'summary': kwargs['summary'] or _('Suggested edit')
})
- revision = super(PostRevisionManager, self).create(*args, **kwargs)
+
+ #see if we have earlier revision with number 0
+ try:
+ pending_revs = post.revisions.filter(revision=0)
+ assert(len(pending_revs) == 1)
+ pending_revs.update(**kwargs)
+ revision = pending_revs[0]
+ except AssertionError:
+ revision = super(PostRevisionManager, self).create(*args, **kwargs)
else:
kwargs['revision'] = post.get_latest_revision_number() + 1
revision = super(PostRevisionManager, self).create(*args, **kwargs)
@@ -2345,14 +2358,23 @@ class PostRevision(models.Model):
#Activity instance is the actual queue item
from askbot.models import Activity
- activity = Activity(
- user = self.author,
- content_object = self,
- activity_type = activity_type,
- question = self.get_origin_post()
- )
- activity.save()
- activity.add_recipients(self.post.get_moderators())
+ content_type = ContentType.objects.get_for_model(self)
+ #try
+ try:
+ activity = Activity.objects.get(
+ activity_type=activity_type,
+ object_id=self.id,
+ content_type=content_type
+ )
+ except Activity.DoesNotExist:
+ activity = Activity(
+ user = self.author,
+ content_object = self,
+ activity_type = activity_type,
+ question = self.get_origin_post()
+ )
+ activity.save()
+ activity.add_recipients(self.post.get_moderators())
def should_notify_author_about_publishing(self, was_approved = False):
"""True if author should get email about making own post"""
diff --git a/askbot/models/question.py b/askbot/models/question.py
index a068224d..039c37f2 100644
--- a/askbot/models/question.py
+++ b/askbot/models/question.py
@@ -1097,6 +1097,7 @@ class Thread(models.Model):
post__id__in=post_ids,
revision=0
)
+
#get ids of posts that we need to patch with suggested data
if len(suggested_revs):
#find posts that we need to patch
@@ -1113,7 +1114,7 @@ class Thread(models.Model):
found.update(find_posts(comments, need_ids))
return found
- suggested_post_ids = set([rev.post_id for rev in suggested_revs])
+ suggested_post_ids = [rev.post_id for rev in suggested_revs]
question = post_data[0]
answers = post_data[1]
@@ -1132,7 +1133,10 @@ class Thread(models.Model):
rev = rev_map[post_id]
#patching work
post.text = rev.text
- post.html = post.parse_post_text()['html']
+ parse_data = post.parse_post_text()
+ post.html = parse_data['html']
+ post.summary = post.get_snippet()
+
post_to_author[post_id] = rev.author_id
post.set_runtime_needs_moderation()
@@ -1159,6 +1163,7 @@ class Thread(models.Model):
rev = rev_map[post.id]
post.text = rev.text
post.html = post.parse_post_text()['html']
+ post.summary = post.get_snippet()
post_to_author[post.id] = rev.author_id
if post.is_comment():
parents = find_posts(all_posts, set([post.parent_id]))
diff --git a/askbot/views/readers.py b/askbot/views/readers.py
index 2e3c8249..4327e13a 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -508,15 +508,10 @@ def question(request, id):#refactor - long subroutine. display question body, an
#load answers and post id's->athor_id mapping
#posts are pre-stuffed with the correctly ordered comments
- updated_question_post, answers, post_to_author, published_answer_ids = thread.get_post_data_for_question_view(
+ question_post, answers, post_to_author, published_answer_ids = thread.get_post_data_for_question_view(
sort_method=answer_sort_method,
user=request.user
)
- question_post.set_cached_comments(
- updated_question_post.get_cached_comments()
- )
-
- #Post.objects.precache_comments(for_posts=[question_post] + answers, visitor=request.user)
user_votes = {}
user_post_id_list = list()
@@ -711,7 +706,13 @@ def get_comment(request):
id = int(request.GET['id'])
comment = models.Post.objects.get(post_type='comment', id=id)
request.user.assert_can_edit_comment(comment)
- return {'text': comment.text}
+
+ try:
+ rev = comment.revisions.get(revision=0)
+ except models.PostRevision.DoesNotExist:
+ rev = comment.get_latest_revision()
+
+ return {'text': rev.text}
@csrf.csrf_exempt
diff --git a/askbot/views/writers.py b/askbot/views/writers.py
index 42477d07..dbfe6882 100644
--- a/askbot/views/writers.py
+++ b/askbot/views/writers.py
@@ -399,7 +399,11 @@ def edit_question(request, id):
if askbot_settings.READ_ONLY_MODE_ENABLED:
return HttpResponseRedirect(question.get_absolute_url())
- revision = question.get_latest_revision()
+ try:
+ revision = question.revisions.get(revision=0)
+ except models.PostRevision.DoesNotExist:
+ revision = question.get_latest_revision()
+
revision_form = None
try:
@@ -510,7 +514,10 @@ def edit_answer(request, id):
if askbot_settings.READ_ONLY_MODE_ENABLED:
return HttpResponseRedirect(answer.get_absolute_url())
- revision = answer.get_latest_revision()
+ try:
+ revision = answer.revisions.get(revision=0)
+ except models.PostRevision.DoesNotExist:
+ revision = answer.get_latest_revision()
class_path = getattr(settings, 'ASKBOT_EDIT_ANSWER_FORM', None)
if class_path:
@@ -794,7 +801,7 @@ def edit_comment(request):
id=form.cleaned_data['comment_id']
)
- request.user.edit_comment(
+ revision = request.user.edit_comment(
comment_post=comment_post,
body_text=form.cleaned_data['comment'],
suppress_email=form.cleaned_data['suppress_email'],
@@ -812,6 +819,11 @@ def edit_comment(request):
tz = template_filters.TIMEZONE_STR
timestamp = str(comment_post.added_at.replace(microsecond=0)) + tz
+ #need this because the post.text is due to the latest approved
+ #revision, but we may need the suggested revision
+ comment_post.text = revision.text
+ comment_post.html = comment_post.parse_post_text()['html']
+
return {
'id' : comment_post.id,
'object_id': comment_post.parent.id,