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