Commit 3312eb2d by wajeeha-khalid

refactored code into exclusive functions

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