def onUpVotedCanceled(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.delete() if post.post_type != 'comment': post.vote_up_count = int(post.vote_up_count) - 1 if post.vote_up_count < 0: post.vote_up_count = 0 post.points = int(post.points) - 1 post.save() if post.post_type == 'comment': #comment votes do not affect reputation return if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation( -askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE ) author.save() question = post.thread._question_post() # TODO: this is suboptimal if post is already a question reputation = Repute( user=author, negative=-askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE, question=question, reputed_at=timestamp, reputation_type=-8, reputation=author.reputation ) reputation.save()
def onUpVoted(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.save() post.vote_up_count = int(post.vote_up_count) + 1 post.score = int(post.score) + 1 post.save() if not (post.wiki or post.is_anonymous): author = post.author todays_rep_gain = Repute.objects.get_reputation_by_upvoted_today(author) if todays_rep_gain < askbot_settings.MAX_REP_GAIN_PER_USER_PER_DAY: author.receive_reputation(askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE) author.save() question = post if isinstance(post, Answer): question = post.question reputation = Repute( user=author, positive=askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE, question=question, reputed_at=timestamp, reputation_type=1, reputation=author.reputation, ) reputation.save()
def onUpVoted(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.save() if post.post_type != 'comment': post.vote_up_count = int(post.vote_up_count) + 1 post.points = int(post.points) + 1 post.save() if post.post_type == 'comment': #reputation is not affected by the comment votes return if not (post.wiki or post.is_anonymous): author = post.author todays_rep_gain = Repute.objects.get_reputation_by_upvoted_today( author) if todays_rep_gain < askbot_settings.MAX_REP_GAIN_PER_USER_PER_DAY: author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE) author.save() exercise = post.thread._exercise_post( ) # TODO: this is suboptimal if post is already an exercise reputation = Repute( user=author, positive=askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE, exercise=exercise, reputed_at=timestamp, reputation_type=1, reputation=author.reputation) reputation.save()
def onUpVoted(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.save() if post.post_type != 'comment': post.vote_up_count = int(post.vote_up_count) + 1 post.score = int(post.score) + 1 post.save() if post.post_type == 'comment': #reputation is not affected by the comment votes return if not (post.wiki or post.is_anonymous): author = post.author todays_rep_gain = Repute.objects.get_reputation_by_upvoted_today( author) if todays_rep_gain < askbot_settings.MAX_REP_GAIN_PER_USER_PER_DAY: author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE) author.save() question = post if isinstance(post, Answer): question = post.question reputation = Repute( user=author, positive=askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE, question=question, reputed_at=timestamp, reputation_type=1, reputation=author.reputation) reputation.save()
def onUpVoted(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.save() if post.post_type != 'comment': post.vote_up_count = int(post.vote_up_count) + 1 post.points = int(post.points) + 1 post.save() if post.post_type == 'comment': #reputation is not affected by the comment votes return if not (post.wiki or post.is_anonymous): author = post.author todays_rep_gain = Repute.objects.get_reputation_by_upvoted_today(author) if todays_rep_gain < askbot_settings.MAX_REP_GAIN_PER_USER_PER_DAY: author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE ) author.save() question = post.thread._question_post() # TODO: this is suboptimal if post is already a question reputation = Repute(user=author, positive=askbot_settings.REP_GAIN_FOR_RECEIVING_UPVOTE, question=question, reputed_at=timestamp, reputation_type=1, reputation=author.reputation) reputation.save()
def onUpVotedCanceled(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.delete() if post.post_type != 'comment': post.vote_up_count = int(post.vote_up_count) - 1 if post.vote_up_count < 0: post.vote_up_count = 0 post.score = int(post.score) - 1 post.save() if post.post_type == 'comment': #comment votes do not affect reputation return if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_UPVOTE_CANCELATION) author.save() question = post if isinstance(post, Answer): question = post.question reputation = Repute( user=author, negative=askbot_settings.REP_LOSS_FOR_RECEIVING_UPVOTE_CANCELATION, question=question, reputed_at=timestamp, reputation_type=-8, reputation=author.reputation) reputation.save()
def onUpVotedCanceled(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.delete() post.vote_up_count = int(post.vote_up_count) - 1 if post.vote_up_count < 0: post.vote_up_count = 0 post.score = int(post.score) - 1 post.save() if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation(askbot_settings.REP_LOSS_FOR_RECEIVING_UPVOTE_CANCELATION) author.save() question = post if isinstance(post, Answer): question = post.question reputation = Repute( user=author, negative=askbot_settings.REP_LOSS_FOR_RECEIVING_UPVOTE_CANCELATION, question=question, reputed_at=timestamp, reputation_type=-8, reputation=author.reputation, ) reputation.save()
def onFlaggedItem(post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() post.offensive_flag_count = post.offensive_flag_count + 1 post.save() post.author.receive_reputation(askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG) post.author.save() question = post.get_origin_post() reputation = Repute( user=post.author, negative=askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG, question=question, reputed_at=timestamp, reputation_type=-4, # todo: clean up magic number reputation=post.author.reputation, ) reputation.save() signals.flag_offensive.send(sender=post.__class__, instance=post, mark_by=user) # todo: These should be updated to work on same revisions. if post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_HIDE_POST: post.author.receive_reputation(askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION) post.author.save() reputation = Repute( user=post.author, negative=askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION, question=question, reputed_at=timestamp, reputation_type=-6, reputation=post.author.reputation, ) reputation.save() elif post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_DELETE_POST: post.author.receive_reputation(askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION) post.author.save() reputation = Repute( user=post.author, negative=askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION, question=question, reputed_at=timestamp, reputation_type=-7, reputation=post.author.reputation, ) reputation.save() post.deleted = True # post.deleted_at = timestamp # post.deleted_by = Admin post.save()
def onAnswerAccept(answer, user, timestamp=None): answer.accepted = True answer.accepted_at = timestamp answer.question.answer_accepted = True answer.save() answer.question.save() if answer.author != user: answer.author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE) answer.author.save() reputation = Repute( user=answer.author, positive=askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE, question=answer.question, reputed_at=timestamp, reputation_type=2, reputation=answer.author.reputation) reputation.save() user.receive_reputation(askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER) user.save() reputation = Repute(user=user, positive=askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER, question=answer.question, reputed_at=timestamp, reputation_type=3, reputation=user.reputation) reputation.save()
def onAnswerAcceptCanceled(answer, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() answer.accepted = False answer.accepted_at = None answer.question.answer_accepted = False answer.save() answer.question.save() answer.author.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE ) answer.author.save() reputation = Repute( user=answer.author, negative=\ askbot_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE, question=answer.question, reputed_at=timestamp, reputation_type=-2, reputation=answer.author.reputation ) reputation.save() user.receive_reputation( askbot_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE) user.save() reputation = Repute( user=user, negative=askbot_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE, question=answer.question, reputed_at=timestamp, reputation_type=-1, reputation=user.reputation) reputation.save()
def onAnswerAccept(answer, user, timestamp=None): answer.thread.set_accepted_answer( answer=answer, actor=user, timestamp=timestamp ) question = answer.thread._question_post() if answer.author != user: answer.author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE ) answer.author.save() reputation = Repute(user=answer.author, positive=abs(askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE), question=question, reputed_at=timestamp, reputation_type=2, reputation=answer.author.reputation) reputation.save() if answer.author_id == question.author_id and user.pk == question.author_id: #a plug to prevent reputation gaming by posting a question #then answering and accepting as best all by the same person return user.receive_reputation(askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER) user.save() reputation = Repute(user=user, positive=askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER, question=question, reputed_at=timestamp, reputation_type=3, reputation=user.reputation) reputation.save()
def onProblemAccept(problem, user, timestamp=None): problem.thread.set_accepted_problem(problem=problem, timestamp=timestamp) exercise = problem.thread._exercise_post() if problem.author != user: problem.author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_PROBLEM_ACCEPTANCE) problem.author.save() reputation = Repute( user=problem.author, positive=askbot_settings.REP_GAIN_FOR_RECEIVING_PROBLEM_ACCEPTANCE, exercise=exercise, reputed_at=timestamp, reputation_type=2, reputation=problem.author.reputation) reputation.save() if problem.author == exercise.author and user == exercise.author: #a plug to prevent reputation gaming by posting an exercise #then adding a problem and accepting as best all by the same person return user.receive_reputation(askbot_settings.REP_GAIN_FOR_ACCEPTING_PROBLEM) user.save() reputation = Repute( user=user, positive=askbot_settings.REP_GAIN_FOR_ACCEPTING_PROBLEM, exercise=exercise, reputed_at=timestamp, reputation_type=3, reputation=user.reputation) reputation.save()
def onAnswerAccept(answer, user, timestamp=None): answer.thread.set_accepted_answer(answer=answer, timestamp=timestamp) question = answer.thread._question_post() if answer.author != user: answer.author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE ) answer.author.save() reputation = Repute(user=answer.author, positive=askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE, question=question, reputed_at=timestamp, reputation_type=2, reputation=answer.author.reputation) reputation.save() user.receive_reputation(askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER) user.save() reputation = Repute(user=user, positive=askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER, question=question, reputed_at=timestamp, reputation_type=3, reputation=user.reputation) reputation.save()
def onProblemAccept(problem, user, timestamp=None): problem.thread.set_accepted_problem(problem=problem, timestamp=timestamp) exercise = problem.thread._exercise_post() if problem.author != user: problem.author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_PROBLEM_ACCEPTANCE ) problem.author.save() reputation = Repute(user=problem.author, positive=askbot_settings.REP_GAIN_FOR_RECEIVING_PROBLEM_ACCEPTANCE, exercise=exercise, reputed_at=timestamp, reputation_type=2, reputation=problem.author.reputation) reputation.save() if problem.author == exercise.author and user == exercise.author: #a plug to prevent reputation gaming by posting a exercise #then probleming and accepting as best all by the same person return user.receive_reputation(askbot_settings.REP_GAIN_FOR_ACCEPTING_PROBLEM) user.save() reputation = Repute(user=user, positive=askbot_settings.REP_GAIN_FOR_ACCEPTING_PROBLEM, exercise=exercise, reputed_at=timestamp, reputation_type=3, reputation=user.reputation) reputation.save()
def onAnswerAccept(answer, user, timestamp=None): answer.accepted = True answer.accepted_at = timestamp answer.question.answer_accepted = True answer.save() answer.question.save() answer.author.receive_reputation(askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE) answer.author.save() reputation = Repute( user=answer.author, positive=askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE, question=answer.question, reputed_at=timestamp, reputation_type=2, reputation=answer.author.reputation, ) reputation.save() user.receive_reputation(askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER) user.save() reputation = Repute( user=user, positive=askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER, question=answer.question, reputed_at=timestamp, reputation_type=3, reputation=user.reputation, ) reputation.save()
def onAnswerAcceptCanceled(answer, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() answer.accepted = False answer.accepted_at = None answer.question.answer_accepted = False answer.save() answer.question.save() answer.author.receive_reputation(askbot_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE) answer.author.save() reputation = Repute( user=answer.author, negative=askbot_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE, question=answer.question, reputed_at=timestamp, reputation_type=-2, reputation=answer.author.reputation, ) reputation.save() user.receive_reputation(askbot_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE) user.save() reputation = Repute( user=user, negative=askbot_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE, question=answer.question, reputed_at=timestamp, reputation_type=-1, reputation=user.reputation, ) reputation.save()
def onAnswerAcceptCanceled(answer, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() answer.endorsed = False answer.endorsed_by = None answer.endorsed_at = None answer.save() answer.thread.accepted_answer = None answer.thread.save() question = answer.thread._question_post() if user != answer.author: answer.author.receive_reputation( -askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE ) answer.author.save() reputation = Repute( user=answer.author, negative=\ -askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE, question=question, reputed_at=timestamp, reputation_type=-2, reputation=answer.author.reputation ) reputation.save() if answer.author_id == question.author_id and user.pk == question.author_id: #a symmettric measure for the reputation gaming plug #as in the onAnswerAccept function #here it protects the user from uwanted reputation loss return user.receive_reputation( -askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER, ) user.save() reputation = Repute(user=user, negative=-askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER, question=question, reputed_at=timestamp, reputation_type=-1, reputation=user.reputation) reputation.save()
def onDownVotedCanceled(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.delete() post.vote_down_count = int(post.vote_down_count) - 1 if post.vote_down_count < 0: post.vote_down_count = 0 post.score = post.score + 1 post.save() if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION) author.save() question = post if isinstance(post, Answer): question = post.question reputation = Repute(user=author, positive=\ askbot_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION, question=question, reputed_at=timestamp, reputation_type=4, reputation=author.reputation ) reputation.save() user.receive_reputation( askbot_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE) user.save() reputation = Repute( user=user, positive=askbot_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE, question=question, reputed_at=timestamp, reputation_type=5, reputation=user.reputation) reputation.save()
def onDownVotedCanceled(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.delete() post.vote_down_count = int(post.vote_down_count) - 1 if post.vote_down_count < 0: post.vote_down_count = 0 post.points = post.points + 1 post.save() if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION) author.save() exercise = post.thread._exercise_post( ) # TODO: this is suboptimal if post is already an exercise reputation = Repute(user=author, positive=\ askbot_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION, exercise=exercise, reputed_at=timestamp, reputation_type=4, reputation=author.reputation ) reputation.save() user.receive_reputation( askbot_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE) user.save() reputation = Repute( user=user, positive=askbot_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE, exercise=exercise, reputed_at=timestamp, reputation_type=5, reputation=user.reputation) reputation.save()
def onDownVotedCanceled(vote, post, user, timestamp=None): if timestamp is None: timestamp = timezone.now() vote.delete() post.vote_down_count = int(post.vote_down_count) - 1 if post.vote_down_count < 0: post.vote_down_count = 0 post.points = post.points + 1 post.save() if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation( -askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE, post.language_code) author.save() # TODO: this is suboptimal if post is already a question question = post.thread._question_post() reputation = Repute( user=author, positive=abs(askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE), question=question, reputed_at=timestamp, reputation_type=4, reputation=author.reputation) reputation.save() user.receive_reputation(-askbot_settings.REP_LOSS_FOR_DOWNVOTING, post.language_code) user.save() reputation = Repute(user=user, positive=abs( askbot_settings.REP_LOSS_FOR_DOWNVOTING), question=question, reputed_at=timestamp, reputation_type=5, reputation=user.reputation) reputation.save()
def onAnswerAcceptCanceled(answer, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() answer.thread.set_accepted_answer(answer=answer, actor=user, timestamp=timestamp) question = answer.thread._question_post() if user != answer.author: answer.author.receive_reputation( askbot_settings. REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE) answer.author.save() reputation = Repute( user=answer.author, negative=\ askbot_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE, question=question, reputed_at=timestamp, reputation_type=-2, reputation=answer.author.reputation ) reputation.save() if answer.author == question.author and user == question.author: #a symmettric measure for the reputation gaming plug #as in the onAnswerAccept function #here it protects the user from uwanted reputation loss return user.receive_reputation( askbot_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE) user.save() reputation = Repute( user=user, negative=askbot_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE, question=question, reputed_at=timestamp, reputation_type=-1, reputation=user.reputation) reputation.save()
def onProblemAcceptCanceled(problem, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() problem.thread.set_accepted_problem(problem=None, timestamp=None) exercise = problem.thread._exercise_post() if user != problem.author: problem.author.receive_reputation( askbot_settings. REP_LOSS_FOR_RECEIVING_CANCELATION_OF_PROBLEM_ACCEPTANCE) problem.author.save() reputation = Repute( user=problem.author, negative=\ askbot_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_PROBLEM_ACCEPTANCE, exercise=exercise, reputed_at=timestamp, reputation_type=-2, reputation=problem.author.reputation ) reputation.save() if problem.author == exercise.author and user == exercise.author: #a symmettric measure for the reputation gaming plug #as in the onProblemAccept function #here it protects the user from uwanted reputation loss return user.receive_reputation( askbot_settings.REP_LOSS_FOR_CANCELING_PROBLEM_ACCEPTANCE) user.save() reputation = Repute( user=user, negative=askbot_settings.REP_LOSS_FOR_CANCELING_PROBLEM_ACCEPTANCE, exercise=exercise, reputed_at=timestamp, reputation_type=-1, reputation=user.reputation) reputation.save()
def onAnswerAcceptCanceled(answer, user, timestamp=None): if timestamp is None: timestamp = timezone.now() answer.endorsed = False answer.endorsed_by = None answer.endorsed_at = None answer.save() answer.thread.accepted_answer = None answer.thread.save() question = answer.thread._question_post() if user != answer.author: answer.author.receive_reputation( -askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE, answer.language_code ) answer.author.save() reputation = Repute( user=answer.author, negative=\ -askbot_settings.REP_GAIN_FOR_RECEIVING_ANSWER_ACCEPTANCE, question=question, reputed_at=timestamp, reputation_type=-2, reputation=answer.author.reputation ) reputation.save() if answer.author_id == question.author_id and user.pk == question.author_id: #a symmettric measure for the reputation gaming plug #as in the onAnswerAccept function #here it protects the user from uwanted reputation loss return user.receive_reputation( -askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER, answer.language_code ) user.save() reputation = Repute(user=user, negative=-askbot_settings.REP_GAIN_FOR_ACCEPTING_ANSWER, question=question, reputed_at=timestamp, reputation_type=-1, reputation=user.reputation) reputation.save()
def onDownVoted(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.save() post.vote_down_count = int(post.vote_down_count) + 1 post.points = int(post.points) - 1 post.save() if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE ) author.save() question = post.thread._question_post() # TODO: this is suboptimal if post is already a question reputation = Repute(user=author, negative=abs(askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE), question=question, reputed_at=timestamp, reputation_type=-3, reputation=author.reputation) reputation.save() user.receive_reputation( askbot_settings.REP_LOSS_FOR_DOWNVOTING, ) user.save() reputation = Repute(user=user, negative=askbot_settings.REP_LOSS_FOR_DOWNVOTING, question=question, reputed_at=timestamp, reputation_type=-5, reputation=user.reputation) reputation.save()
def onDownVoted(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.save() post.vote_down_count = int(post.vote_down_count) + 1 post.score = int(post.score) - 1 post.save() if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation(askbot_settings.REP_LOSS_FOR_DOWNVOTING) author.save() question = post if isinstance(post, Answer): question = post.question reputation = Repute(user=author, negative=askbot_settings.REP_LOSS_FOR_DOWNVOTING, question=question, reputed_at=timestamp, reputation_type=-3, reputation=author.reputation) reputation.save() user.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE) user.save() reputation = Repute( user=user, negative=askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE, question=question, reputed_at=timestamp, reputation_type=-5, reputation=user.reputation) reputation.save()
def onDownVotedCanceled(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.delete() post.vote_down_count = int(post.vote_down_count) - 1 if post.vote_down_count < 0: post.vote_down_count = 0 post.score = post.score + 1 post.save() if not post.wiki: author = post.author author.reputation = calculate_reputation( author.reputation, askbot_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION ) author.save() question = post if isinstance(post, Answer): question = post.question reputation = Repute( user=author, positive=askbot_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION, question=question, reputed_at=timestamp, reputation_type=4, reputation=author.reputation, ) reputation.save() user.reputation = calculate_reputation(user.reputation, askbot_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE) user.save() reputation = Repute( user=user, positive=askbot_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE, question=question, reputed_at=timestamp, reputation_type=5, reputation=user.reputation, ) reputation.save()
def onDownVotedCanceled(vote, post, user, timestamp=None): if timestamp is None: timestamp = timezone.now() vote.delete() post.vote_down_count = int(post.vote_down_count) - 1 if post.vote_down_count < 0: post.vote_down_count = 0 post.points = post.points + 1 post.save() if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation( -askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE, post.language_code) author.save() # TODO: this is suboptimal if post is already a question question = post.thread._question_post() reputation = Repute( user=author, positive=abs(askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE), question=question, reputed_at=timestamp, reputation_type=4, reputation=author.reputation) reputation.save() user.receive_reputation( -askbot_settings.REP_LOSS_FOR_DOWNVOTING, post.language_code) user.save() reputation = Repute( user=user, positive=abs(askbot_settings.REP_LOSS_FOR_DOWNVOTING), question=question, reputed_at=timestamp, reputation_type=5, reputation=user.reputation) reputation.save()
def onDownVoted(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.save() post.vote_down_count = int(post.vote_down_count) + 1 post.score = int(post.score) - 1 post.save() if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation(askbot_settings.REP_LOSS_FOR_DOWNVOTING) author.save() question = post if isinstance(post, Answer): question = post.question reputation = Repute( user=author, negative=askbot_settings.REP_LOSS_FOR_DOWNVOTING, question=question, reputed_at=timestamp, reputation_type=-3, reputation=author.reputation, ) reputation.save() user.receive_reputation(askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE) user.save() reputation = Repute( user=user, negative=askbot_settings.REP_LOSS_FOR_RECEIVING_DOWNVOTE, question=question, reputed_at=timestamp, reputation_type=-5, reputation=user.reputation, ) reputation.save()
def onDownVotedCanceled(vote, post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() vote.delete() post.vote_down_count = int(post.vote_down_count) - 1 if post.vote_down_count < 0: post.vote_down_count = 0 post.score = post.score + 1 post.save() if not (post.wiki or post.is_anonymous): author = post.author author.receive_reputation( askbot_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION ) author.save() question = post.thread._question_post() # TODO: this is suboptimal if post is already a question reputation = Repute(user=author, positive=\ askbot_settings.REP_GAIN_FOR_RECEIVING_DOWNVOTE_CANCELATION, question=question, reputed_at=timestamp, reputation_type=4, reputation=author.reputation ) reputation.save() user.receive_reputation(askbot_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE) user.save() reputation = Repute(user=user, positive=askbot_settings.REP_GAIN_FOR_CANCELING_DOWNVOTE, question=question, reputed_at=timestamp, reputation_type=5, reputation=user.reputation) reputation.save()
def onAnswerAcceptCanceled(answer, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() answer.thread.set_accepted_answer(answer=None, timestamp=None) question = answer.thread._question_post() if user != answer.author: answer.author.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE ) answer.author.save() reputation = Repute( user=answer.author, negative=\ askbot_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_ANSWER_ACCEPTANCE, question=question, reputed_at=timestamp, reputation_type=-2, reputation=answer.author.reputation ) reputation.save() if answer.author == question.author and user == question.author: #a symmettric measure for the reputation gaming plug #as in the onAnswerAccept function #here it protects the user from uwanted reputation loss return user.receive_reputation( askbot_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE ) user.save() reputation = Repute(user=user, negative=askbot_settings.REP_LOSS_FOR_CANCELING_ANSWER_ACCEPTANCE, question=question, reputed_at=timestamp, reputation_type=-1, reputation=user.reputation) reputation.save()
def onProblemAcceptCanceled(problem, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() problem.thread.set_accepted_problem(problem=None, timestamp=None) exercise = problem.thread._exercise_post() if user != problem.author: problem.author.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_PROBLEM_ACCEPTANCE ) problem.author.save() reputation = Repute( user=problem.author, negative=\ askbot_settings.REP_LOSS_FOR_RECEIVING_CANCELATION_OF_PROBLEM_ACCEPTANCE, exercise=exercise, reputed_at=timestamp, reputation_type=-2, reputation=problem.author.reputation ) reputation.save() if problem.author == exercise.author and user == exercise.author: #a symmettric measure for the reputation gaming plug #as in the onProblemAccept function #here it protects the user from uwanted reputation loss return user.receive_reputation( askbot_settings.REP_LOSS_FOR_CANCELING_PROBLEM_ACCEPTANCE ) user.save() reputation = Repute(user=user, negative=askbot_settings.REP_LOSS_FOR_CANCELING_PROBLEM_ACCEPTANCE, exercise=exercise, reputed_at=timestamp, reputation_type=-1, reputation=user.reputation) reputation.save()
def onFlaggedItem(post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() post.offensive_flag_count = post.offensive_flag_count + 1 post.save() post.author.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG ) post.author.save() question = post.get_origin_post() reputation = Repute( user=post.author, negative=askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG, question=question, reputed_at=timestamp, reputation_type=-4,#todo: clean up magic number reputation=post.author.reputation ) reputation.save() signals.flag_offensive.send( sender=post.__class__, instance=post, mark_by=user ) #todo: These should be updated to work on same revisions. if post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_HIDE_POST: post.author.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION ) post.author.save() reputation = Repute( user=post.author, negative=\ askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION, question=question, reputed_at=timestamp, reputation_type=-6, reputation=post.author.reputation ) reputation.save() elif post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_DELETE_POST: post.author.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION ) post.author.save() reputation = Repute( user=post.author, negative=\ askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION, question=question, reputed_at=timestamp, reputation_type=-7, reputation=post.author.reputation ) reputation.save() post.deleted = True #post.deleted_at = timestamp #post.deleted_by = Admin post.save()
def onUnFlaggedItem(post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() post.offensive_flag_count = post.offensive_flag_count - 1 post.save() flagged_user = post.author flagged_user.receive_reputation( -askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG #negative of a negative ) flagged_user.save() question = post.thread._question_post() reputation = Repute( user=flagged_user, positive=abs(askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG), question=question, reputed_at=timestamp, reputation_type=-4,#todo: clean up magic number reputation=flagged_user.reputation ) reputation.save() signals.remove_flag_offensive.send( sender=post.__class__, instance=post, mark_by=user ) if post.post_type == 'comment': #do not hide or delete comments automatically yet, #because there is no .deleted field in the comment model return #todo: These should be updated to work on same revisions. # The post fell below HIDE treshold - unhide it. if post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_HIDE_POST - 1: #todo: strange - are we supposed to hide the post here or the name of #setting is incorrect? flagged_user.receive_reputation( -askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION ) flagged_user.save() reputation = Repute( user=flagged_user, positive=\ abs(askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION), question=question, reputed_at=timestamp, reputation_type=-6, reputation=flagged_user.reputation ) reputation.save() # The post fell below DELETE treshold, undelete it elif post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_DELETE_POST-1 : flagged_user.receive_reputation( -askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION ) flagged_user.save() reputation = Repute( user=flagged_user, positive =\ abs(askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION), question=question, reputed_at=timestamp, reputation_type=-7, reputation=flagged_user.reputation ) reputation.save() post.deleted = False post.save() signals.after_post_restored.send( sender=post.__class__, instance=post, restored_by=user, )
def onUnFlaggedItem(post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() post.offensive_flag_count = post.offensive_flag_count - 1 post.save() flagged_user = post.author flagged_user.receive_reputation( - askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG ) flagged_user.save() exercise = post.thread._exercise_post() reputation = Repute( user=flagged_user, positive=askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG, exercise=exercise, reputed_at=timestamp, reputation_type=-4,#todo: clean up magic number reputation=flagged_user.reputation ) reputation.save() signals.remove_flag_offensive.send( sender=post.__class__, instance=post, mark_by=user ) if post.post_type == 'comment': #do not hide or delete comments automatically yet, #because there is no .deleted field in the comment model return #todo: These should be updated to work on same revisions. # The post fell below HIDE treshold - unhide it. if post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_HIDE_POST - 1: #todo: strange - are we supposed to hide the post here or the name of #setting is incorrect? flagged_user.receive_reputation( - askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION ) flagged_user.save() reputation = Repute( user=flagged_user, positive=\ askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION, exercise=exercise, reputed_at=timestamp, reputation_type=-6, reputation=flagged_user.reputation ) reputation.save() # The post fell below DELETE treshold, undelete it elif post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_DELETE_POST-1 : flagged_user.receive_reputation( - askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION ) flagged_user.save() reputation = Repute( user=flagged_user, positive =\ askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION, exercise=exercise, reputed_at=timestamp, reputation_type=-7, reputation=flagged_user.reputation ) reputation.save() post.deleted = False post.save()
def onFlaggedItem(post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() post.offensive_flag_count = post.offensive_flag_count + 1 post.save() flagged_user = post.author flagged_user.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG ) flagged_user.save() question = post.thread._question_post() reputation = Repute( user=flagged_user, negative=askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG, question=question, reputed_at=timestamp, reputation_type=-4,#todo: clean up magic number reputation=flagged_user.reputation ) reputation.save() signals.flag_offensive.send( sender=post.__class__, instance=post, mark_by=user ) if post.post_type == 'comment': #do not hide or delete comments automatically yet, #because there is no .deleted field in the comment model return #todo: These should be updated to work on same revisions. if post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_HIDE_POST: #todo: strange - are we supposed to hide the post here or the name of #setting is incorrect? flagged_user.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION ) flagged_user.save() reputation = Repute( user=flagged_user, negative=\ askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION, question=question, reputed_at=timestamp, reputation_type=-6, reputation=flagged_user.reputation ) reputation.save() elif post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_DELETE_POST: flagged_user.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION ) flagged_user.save() reputation = Repute( user=flagged_user, negative=\ askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION, question=question, reputed_at=timestamp, reputation_type=-7, reputation=flagged_user.reputation ) reputation.save() post.deleted = True #post.deleted_at = timestamp #post.deleted_by = Admin post.save() signals.after_post_removed.send( sender=post.__class__, instance=post, deleted_by=user, )
def onFlaggedItem(post, user, timestamp=None): if timestamp is None: timestamp = datetime.datetime.now() post.offensive_flag_count = post.offensive_flag_count + 1 post.save() if post.post_type == 'comment': #todo: fix this flagged_user = post.user else: flagged_user = post.author flagged_user.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG) flagged_user.save() question = post.get_origin_post() reputation = Repute( user=flagged_user, negative=askbot_settings.REP_LOSS_FOR_RECEIVING_FLAG, question=question, reputed_at=timestamp, reputation_type=-4, #todo: clean up magic number reputation=flagged_user.reputation) reputation.save() signals.flag_offensive.send(sender=post.__class__, instance=post, mark_by=user) if post.post_type == 'comment': #do not hide or delete comments automatically yet, #because there is no .deleted field in the comment model return #todo: These should be updated to work on same revisions. if post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_HIDE_POST: #todo: strange - are we supposed to hide the post here or the name of #setting is incorrect? flagged_user.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION) flagged_user.save() reputation = Repute( user=flagged_user, negative=\ askbot_settings.REP_LOSS_FOR_RECEIVING_THREE_FLAGS_PER_REVISION, question=question, reputed_at=timestamp, reputation_type=-6, reputation=flagged_user.reputation ) reputation.save() elif post.offensive_flag_count == askbot_settings.MIN_FLAGS_TO_DELETE_POST: flagged_user.receive_reputation( askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION) flagged_user.save() reputation = Repute( user=flagged_user, negative=\ askbot_settings.REP_LOSS_FOR_RECEIVING_FIVE_FLAGS_PER_REVISION, question=question, reputed_at=timestamp, reputation_type=-7, reputation=flagged_user.reputation ) reputation.save() post.deleted = True #post.deleted_at = timestamp #post.deleted_by = Admin post.save()