本文整理汇总了Python中askbot.models.Repute类的典型用法代码示例。如果您正苦于以下问题:Python Repute类的具体用法?Python Repute怎么用?Python Repute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Repute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onUpVotedCanceled
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()
示例2: onUpVoted
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()
示例3: onUpVoted
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()
示例4: onUpVotedCanceled
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()
示例5: onFlaggedItem
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()
示例6: onAnswerAcceptCanceled
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()
示例7: onAnswerAccept
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()
示例8: onAnswerAccept
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()
示例9: onProblemAccept
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()
示例10: onAnswerAccept
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()
示例11: onAnswerAcceptCanceled
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()
示例12: onDownVotedCanceled
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()
示例13: onDownVotedCanceled
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()
示例14: onDownVotedCanceled
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()
示例15: onDownVoted
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()