Commit 1c1d449a by Rocky Duan

minor refactoring

parent 0dd5428e
...@@ -64,10 +64,12 @@ def ajax_content_response(request, course_id, content, template_name): ...@@ -64,10 +64,12 @@ def ajax_content_response(request, course_id, content, template_name):
def create_thread(request, course_id, commentable_id): def create_thread(request, course_id, commentable_id):
post = request.POST post = request.POST
thread = cc.Thread(**extract(post, ['body', 'title', 'tags'])) thread = cc.Thread(**extract(post, ['body', 'title', 'tags']))
thread.anonymous = post.get('anonymous', 'false').lower() == 'true' thread.update_attributes({
thread.commentable_id = commentable_id 'anonymous' : post.get('anonymous', 'false').lower() == 'true',
thread.course_id = course_id 'commentable_id' : commentable_id,
thread.user_id = request.user.id 'course_id' : course_id,
'user_id' : request.user.id,
})
thread.save() thread.save()
if post.get('auto_subscribe', 'false').lower() == 'true': if post.get('auto_subscribe', 'false').lower() == 'true':
user = cc.User.from_django_user(request.user) user = cc.User.from_django_user(request.user)
...@@ -92,13 +94,14 @@ def update_thread(request, course_id, thread_id): ...@@ -92,13 +94,14 @@ def update_thread(request, course_id, thread_id):
def _create_comment(request, course_id, thread_id=None, parent_id=None): def _create_comment(request, course_id, thread_id=None, parent_id=None):
post = request.POST post = request.POST
comment = cc.Comment(**extract(post, ['body'])) comment = cc.Comment(**extract(post, ['body']))
comment.anonymous = post.get('anonymous', 'false').lower() == 'true' comment.update_attributes({
comment.user_id = request.user.id 'anonymous' : post.get('anonymous', 'false').lower() == 'true',
comment.course_id = course_id 'user_id' : request.user.id,
comment.thread_id = thread_id 'course_id' : course_id,
comment.parent_id = parent_id 'thread_id' : thread_id,
'parent_id' : parent_id,
})
comment.save() comment.save()
dict_comment = comment.to_dict()
if post.get('auto_subscribe', 'false').lower() == 'true': if post.get('auto_subscribe', 'false').lower() == 'true':
user = cc.User.from_django_user(request.user) user = cc.User.from_django_user(request.user)
user.follow(comment.thread) user.follow(comment.thread)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment