Commit 3312eb2d by wajeeha-khalid

refactored code into exclusive functions

parent fe9b1a0d
...@@ -506,17 +506,31 @@ def _do_extra_actions(api_content, cc_content, request_fields, actions_form, con ...@@ -506,17 +506,31 @@ def _do_extra_actions(api_content, cc_content, request_fields, actions_form, con
if field in request_fields and form_value != api_content[field]: if field in request_fields and form_value != api_content[field]:
api_content[field] = form_value api_content[field] = form_value
if field == "following": if field == "following":
if form_value: _handle_following_field(form_value, context["cc_requester"], cc_content)
context["cc_requester"].follow(cc_content)
else:
context["cc_requester"].unfollow(cc_content)
elif field == "abuse_flagged": elif field == "abuse_flagged":
_handle_abuse_flagged_field(form_value, context["cc_requester"], cc_content)
elif field == "voted":
_handle_voted_field(form_value, cc_content, api_content, request, context)
def _handle_following_field(form_value, user, cc_content):
"""follow/unfollow thread for the user"""
if form_value: if form_value:
cc_content.flagAbuse(context["cc_requester"], cc_content) user.follow(cc_content)
else: else:
cc_content.unFlagAbuse(context["cc_requester"], cc_content, removeAll=False) user.unfollow(cc_content)
def _handle_abuse_flagged_field(form_value, user, cc_content):
"""mark or unmark thread/comment as abused"""
if form_value:
cc_content.flagAbuse(user, cc_content)
else: else:
assert field == "voted" cc_content.unFlagAbuse(user, cc_content, removeAll=False)
def _handle_voted_field(form_value, cc_content, api_content, request, context):
"""vote or undo vote on thread/comment"""
signal = thread_voted if cc_content.type == 'thread' else comment_voted signal = thread_voted if cc_content.type == 'thread' else comment_voted
signal.send(sender=None, user=context["request"].user, post=cc_content) signal.send(sender=None, user=context["request"].user, post=cc_content)
if form_value: if form_value:
...@@ -525,7 +539,9 @@ def _do_extra_actions(api_content, cc_content, request_fields, actions_form, con ...@@ -525,7 +539,9 @@ def _do_extra_actions(api_content, cc_content, request_fields, actions_form, con
else: else:
context["cc_requester"].unvote(cc_content) context["cc_requester"].unvote(cc_content)
api_content["vote_count"] -= 1 api_content["vote_count"] -= 1
track_voted_event(request, context["course"], cc_content, "up", False if form_value else True) track_voted_event(
request, context["course"], cc_content, vote_value="up", undo_vote=False if form_value else True
)
def create_thread(request, thread_data): def create_thread(request, thread_data):
......
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