summaryrefslogtreecommitdiffstats
path: root/askbot/views
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-03-06 20:50:21 -0300
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-03-06 20:50:21 -0300
commitd13ee8aa889304ca95cbd8cc777ab5e957fbed54 (patch)
treeb2f484651b068e5df9c204fdff459633f7cd00e3 /askbot/views
parentfb0df1a738d3a9dc01c5b54619f286148532c6ce (diff)
downloadaskbot-d13ee8aa889304ca95cbd8cc777ab5e957fbed54.tar.gz
askbot-d13ee8aa889304ca95cbd8cc777ab5e957fbed54.tar.bz2
askbot-d13ee8aa889304ca95cbd8cc777ab5e957fbed54.zip
added function to repost answer as comment under the latest previously posted answer
Diffstat (limited to 'askbot/views')
-rw-r--r--askbot/views/readers.py1
-rw-r--r--askbot/views/writers.py27
2 files changed, 25 insertions, 3 deletions
diff --git a/askbot/views/readers.py b/askbot/views/readers.py
index 7fbcf6d0..51a4da8e 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -598,6 +598,7 @@ def question(request, id):#refactor - long subroutine. display question body, an
'user_post_id_list': user_post_id_list,
'user_can_post_comment': user_can_post_comment,#in general
'user_already_gave_answer': user_already_gave_answer,
+ 'oldest_answer_id': thread.get_oldest_answer_id(request.user),
'previous_answer': previous_answer,
'tab_id' : answer_sort_method,
'favorited' : favorited,
diff --git a/askbot/views/writers.py b/askbot/views/writers.py
index b581036c..8c421fb7 100644
--- a/askbot/views/writers.py
+++ b/askbot/views/writers.py
@@ -771,22 +771,43 @@ def comment_to_answer(request):
@decorators.admins_only
@decorators.post_only
-def answer_to_comment(request):
+#todo: change the urls config for this
+def repost_answer_as_comment(request, destination=None):
+ assert(
+ destination in (
+ 'comment_under_question',
+ 'comment_under_previous_answer'
+ )
+ )
answer_id = request.POST.get('answer_id')
if answer_id:
answer_id = int(answer_id)
answer = get_object_or_404(models.Post,
post_type = 'answer', id=answer_id)
+
+ if destination == 'comment_under_question':
+ destination_post = answer.thread._question_post()
+ else:
+ #comment_under_previous_answer
+ destination_post = answer.get_previous_answer(user=request.user)
+ #todo: implement for comment under other answer
+
+ if destination_post is None:
+ message = _('Error - could not find the destination post')
+ request.user.message_set.create(message=message)
+ return HttpResponseRedirect(answer.get_absolute_url())
+
if len(answer.text) <= askbot_settings.MAX_COMMENT_LENGTH:
answer.post_type = 'comment'
- answer.parent = answer.thread._question_post()
+ answer.parent = destination_post
#can we trust this?
old_comment_count = answer.comment_count
answer.comment_count = 0
answer_comments = models.Post.objects.get_comments().filter(parent=answer)
- answer_comments.update(parent=answer.parent)
+ answer_comments.update(parent=destination_post)
+ #why this and not just "save"?
answer.parse_and_save(author=answer.author)
answer.thread.update_answer_count()