本文整理汇总了Python中models.Repute.save方法的典型用法代码示例。如果您正苦于以下问题:Python Repute.save方法的具体用法?Python Repute.save怎么用?Python Repute.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Repute
的用法示例。
在下文中一共展示了Repute.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onAnswerAcceptCanceled
# 需要导入模块: from models import Repute [as 别名]
# 或者: from 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.reputation = calculate_reputation(answer.author.reputation,
int(REPUTATION_RULES['lose_by_accepted_answer_cancled']))
answer.author.save()
reputation = Repute(user=answer.author,
negative=int(REPUTATION_RULES['lose_by_accepted_answer_cancled']),
question=answer.question,
reputed_at=timestamp,
reputation_type=-2,
reputation=answer.author.reputation)
reputation.save()
user.reputation = calculate_reputation(user.reputation,
int(REPUTATION_RULES['lose_by_canceling_accepted_answer']))
user.save()
reputation = Repute(user=user,
negative=int(REPUTATION_RULES['lose_by_canceling_accepted_answer']),
question=answer.question,
reputed_at=timestamp,
reputation_type=-1,
reputation=user.reputation)
reputation.save()
示例2: onUpVoted
# 需要导入模块: from models import Repute [as 别名]
# 或者: from models.Repute import save [as 别名]
def onUpVoted(vote, post, user):
vote.save()
post.vote_up_count = int(post.vote_up_count) + 1
post.score = int(post.score) + 1
post.save()
if not post.wiki:
author = post.author
if Repute.objects.get_reputation_by_upvoted_today(author) < int(REPUTATION_RULES["scope_per_day_by_upvotes"]):
author.reputation = calculate_reputation(author.reputation, int(REPUTATION_RULES["gain_by_upvoted"]))
author.save()
question = post
if ContentType.objects.get_for_model(post) == answer_type:
question = post.question
reputation = Repute(
user=author,
positive=int(REPUTATION_RULES["gain_by_upvoted"]),
question=question,
reputed_at=datetime.datetime.now(),
reputation_type=1,
reputation=author.reputation,
)
reputation.save()
示例3: onAnswerAccept
# 需要导入模块: from models import Repute [as 别名]
# 或者: from models.Repute import save [as 别名]
def onAnswerAccept(answer, user):
answer.accepted = True
answer.accepted_at = datetime.datetime.now()
answer.question.answer_accepted = True
answer.save()
answer.question.save()
answer.author.reputation = calculate_reputation(answer.author.reputation,
int(settings.REP_GAIN_BY_ACCEPTED))
answer.author.save()
reputation = Repute(user=answer.author,
positive=int(settings.REP_GAIN_BY_ACCEPTED),
question=answer.question,
reputed_at=datetime.datetime.now(),
reputation_type=2,
reputation=answer.author.reputation)
reputation.save()
user.reputation = calculate_reputation(user.reputation,
int(settings.REP_GAIN_BY_ACCEPTING))
user.save()
reputation = Repute(user=user,
positive=int(settings.REP_GAIN_BY_ACCEPTING),
question=answer.question,
reputed_at=datetime.datetime.now(),
reputation_type=3,
reputation=user.reputation)
reputation.save()
示例4: onUpVotedCanceled
# 需要导入模块: from models import Repute [as 别名]
# 或者: from models.Repute import save [as 别名]
def onUpVotedCanceled(vote, post, user):
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:
author = post.author
author.reputation = calculate_reputation(author.reputation, int(REPUTATION_RULES["lose_by_upvote_canceled"]))
author.save()
question = post
if ContentType.objects.get_for_model(post) == answer_type:
question = post.question
reputation = Repute(
user=author,
negative=int(REPUTATION_RULES["lose_by_upvote_canceled"]),
question=question,
reputed_at=datetime.datetime.now(),
reputation_type=-8,
reputation=author.reputation,
)
reputation.save()
示例5: onUpVotedCanceled
# 需要导入模块: from models import Repute [as 别名]
# 或者: from 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:
author = post.author
author.reputation = calculate_reputation(author.reputation,
int(REPUTATION_RULES['lose_by_upvote_canceled']))
author.save()
question = post
if isinstance(post, Answer):
question = post.question
reputation = Repute(user=author,
negative=int(REPUTATION_RULES['lose_by_upvote_canceled']),
question=question,
reputed_at=timestamp,
reputation_type=-8,
reputation=author.reputation)
reputation.save()
示例6: onUpVoted
# 需要导入模块: from models import Repute [as 别名]
# 或者: from 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:
author = post.author
todays_rep_gain = Repute.objects.get_reputation_by_upvoted_today(author)
if todays_rep_gain < int(REPUTATION_RULES['scope_per_day_by_upvotes']):
author.reputation = calculate_reputation(author.reputation,
int(REPUTATION_RULES['gain_by_upvoted']))
author.save()
question = post
if isinstance(post, Answer):
question = post.question
reputation = Repute(user=author,
positive=int(REPUTATION_RULES['gain_by_upvoted']),
question=question,
reputed_at=timestamp,
reputation_type=1,
reputation=author.reputation)
reputation.save()
示例7: onUpVotedCanceled
# 需要导入模块: from models import Repute [as 别名]
# 或者: from models.Repute import save [as 别名]
def onUpVotedCanceled(vote, post, user):
vote.delete()
post.decrement_vote_up_count()
if post.vote_up_count < 0:
post.vote_up_count = 0
post.score = int(post.score) - 1
post.save()
if not post.wiki:
author = post.author
author.reputation = calculate_reputation(author.reputation,
-int(settings.REP_LOST_BY_UPVOTE_CANCELED))
author.save()
question = post
if post.__class__ == Answer:
question = post.question
reputation = Repute(user=author,
negative=-int(settings.REP_LOST_BY_UPVOTE_CANCELED),
question=question,
reputed_at=datetime.datetime.now(),
reputation_type=-8,
reputation=author.reputation)
reputation.save()
示例8: onUpVoted
# 需要导入模块: from models import Repute [as 别名]
# 或者: from models.Repute import save [as 别名]
def onUpVoted(vote, post, user):
vote.save()
post.increment_vote_up_count()
post.score = int(post.score) + 1
post.save()
if not post.wiki:
author = post.author
if Repute.objects.get_reputation_by_upvoted_today(author) < int(settings.MAX_REP_BY_UPVOTE_DAY):
author.reputation = calculate_reputation(author.reputation,
int(settings.REP_GAIN_BY_UPVOTED))
author.save()
question = post
if post.__class__ == Answer:
question = post.question
reputation = Repute(user=author,
positive=int(settings.REP_GAIN_BY_UPVOTED),
question=question,
reputed_at=datetime.datetime.now(),
reputation_type=1,
reputation=author.reputation)
reputation.save()
示例9: onAnswerAcceptCanceled
# 需要导入模块: from models import Repute [as 别名]
# 或者: from models.Repute import save [as 别名]
def onAnswerAcceptCanceled(answer, user):
answer.accepted = False
answer.accepted_at = None
answer.question.answer_accepted = False
answer.save()
answer.question.save()
answer.author.reputation = calculate_reputation(answer.author.reputation,
-int(settings.REP_GAIN_BY_ACCEPTED_CANCELED))
answer.author.save()
reputation = Repute(user=answer.author,
negative=-int(settings.REP_GAIN_BY_ACCEPTED_CANCELED),
question=answer.question,
reputed_at=datetime.datetime.now(),
reputation_type=-2,
reputation=answer.author.reputation)
reputation.save()
user.reputation = calculate_reputation(user.reputation,
-int(settings.REP_LOST_BY_CANCELING_ACCEPTED))
user.save()
reputation = Repute(user=user,
negative=-int(settings.REP_LOST_BY_CANCELING_ACCEPTED),
question=answer.question,
reputed_at=datetime.datetime.now(),
reputation_type=-1,
reputation=user.reputation)
reputation.save()
示例10: onAnswerAccept
# 需要导入模块: from models import Repute [as 别名]
# 或者: from models.Repute import save [as 别名]
def onAnswerAccept(answer, user, timestamp=None):
if timestamp is None:
timestamp = datetime.datetime.now()
answer.accepted = True
answer.accepted_at = timestamp
answer.question.answer_accepted = True
answer.save()
answer.question.save()
answer.author.reputation = calculate_reputation(answer.author.reputation,
int(REPUTATION_RULES['gain_by_answer_accepted']))
answer.author.save()
reputation = Repute(user=answer.author,
positive=int(REPUTATION_RULES['gain_by_answer_accepted']),
question=answer.question,
reputed_at=timestamp,
reputation_type=2,
reputation=answer.author.reputation)
reputation.save()
user.reputation = calculate_reputation(user.reputation,
int(REPUTATION_RULES['gain_by_accepting_answer']))
user.save()
reputation = Repute(user=user,
positive=int(REPUTATION_RULES['gain_by_accepting_answer']),
question=answer.question,
reputed_at=timestamp,
reputation_type=3,
reputation=user.reputation)
reputation.save()
示例11: onAnswerAccept
# 需要导入模块: from models import Repute [as 别名]
# 或者: from models.Repute import save [as 别名]
def onAnswerAccept(answer, user):
answer.accepted = True
answer.accepted_at = datetime.datetime.now()
answer.question.answer_accepted = True
answer.save()
answer.question.save()
answer.author.reputation = calculate_reputation(
answer.author.reputation, int(REPUTATION_RULES["gain_by_answer_accepted"])
)
answer.author.save()
reputation = Repute(
user=answer.author,
positive=int(REPUTATION_RULES["gain_by_answer_accepted"]),
question=answer.question,
reputed_at=datetime.datetime.now(),
reputation_type=2,
reputation=answer.author.reputation,
)
reputation.save()
user.reputation = calculate_reputation(user.reputation, int(REPUTATION_RULES["gain_by_accepting_answer"]))
user.save()
reputation = Repute(
user=user,
positive=int(REPUTATION_RULES["gain_by_accepting_answer"]),
question=answer.question,
reputed_at=datetime.datetime.now(),
reputation_type=3,
reputation=user.reputation,
)
reputation.save()
示例12: onDownVotedCanceled
# 需要导入模块: from models import Repute [as 别名]
# 或者: from models.Repute import save [as 别名]
def onDownVotedCanceled(vote, post, user):
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, int(REPUTATION_RULES["gain_by_downvote_canceled"]))
author.save()
question = post
if ContentType.objects.get_for_model(post) == answer_type:
question = post.question
reputation = Repute(
user=author,
positive=int(REPUTATION_RULES["gain_by_downvote_canceled"]),
question=question,
reputed_at=datetime.datetime.now(),
reputation_type=4,
reputation=author.reputation,
)
reputation.save()
user.reputation = calculate_reputation(user.reputation, int(REPUTATION_RULES["gain_by_canceling_downvote"]))
user.save()
reputation = Repute(
user=user,
positive=int(REPUTATION_RULES["gain_by_canceling_downvote"]),
question=question,
reputed_at=datetime.datetime.now(),
reputation_type=5,
reputation=user.reputation,
)
reputation.save()
示例13: onFlaggedItem
# 需要导入模块: from models import Repute [as 别名]
# 或者: from models.Repute import save [as 别名]
def onFlaggedItem(item, post, user):
item.save()
post.offensive_flag_count = post.offensive_flag_count + 1
post.save()
post.author.reputation = calculate_reputation(post.author.reputation, int(REPUTATION_RULES["lose_by_flagged"]))
post.author.save()
question = post
if ContentType.objects.get_for_model(post) == answer_type:
question = post.question
reputation = Repute(
user=post.author,
negative=int(REPUTATION_RULES["lose_by_flagged"]),
question=question,
reputed_at=datetime.datetime.now(),
reputation_type=-4,
reputation=post.author.reputation,
)
reputation.save()
# todo: These should be updated to work on same revisions.
if post.offensive_flag_count == VOTE_RULES["scope_flags_invisible_main_page"]:
post.author.reputation = calculate_reputation(
post.author.reputation, int(REPUTATION_RULES["lose_by_flagged_lastrevision_3_times"])
)
post.author.save()
reputation = Repute(
user=post.author,
negative=int(REPUTATION_RULES["lose_by_flagged_lastrevision_3_times"]),
question=question,
reputed_at=datetime.datetime.now(),
reputation_type=-6,
reputation=post.author.reputation,
)
reputation.save()
elif post.offensive_flag_count == VOTE_RULES["scope_flags_delete_post"]:
post.author.reputation = calculate_reputation(
post.author.reputation, int(REPUTATION_RULES["lose_by_flagged_lastrevision_5_times"])
)
post.author.save()
reputation = Repute(
user=post.author,
negative=int(REPUTATION_RULES["lose_by_flagged_lastrevision_5_times"]),
question=question,
reputed_at=datetime.datetime.now(),
reputation_type=-7,
reputation=post.author.reputation,
)
reputation.save()
post.deleted = True
# post.deleted_at = datetime.datetime.now()
# post.deleted_by = Admin
post.save()
示例14: onDownVotedCanceled
# 需要导入模块: from models import Repute [as 别名]
# 或者: from 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,
int(REPUTATION_RULES['gain_by_downvote_canceled']))
author.save()
question = post
if isinstance(post, Answer):
question = post.question
reputation = Repute(user=author,
positive=int(REPUTATION_RULES['gain_by_downvote_canceled']),
question=question,
reputed_at=timestamp,
reputation_type=4,
reputation=author.reputation)
reputation.save()
user.reputation = calculate_reputation(user.reputation,
int(REPUTATION_RULES['gain_by_canceling_downvote']))
user.save()
reputation = Repute(user=user,
positive=int(REPUTATION_RULES['gain_by_canceling_downvote']),
question=question,
reputed_at=timestamp,
reputation_type=5,
reputation=user.reputation)
reputation.save()
示例15: onFlaggedItem
# 需要导入模块: from models import Repute [as 别名]
# 或者: from models.Repute import save [as 别名]
def onFlaggedItem(item, post, user, timestamp=None):
if timestamp is None:
timestamp = datetime.datetime.now()
item.save()
post.offensive_flag_count = post.offensive_flag_count + 1
post.save()
post.author.reputation = calculate_reputation(post.author.reputation,
int(REPUTATION_RULES['lose_by_flagged']))
post.author.save()
question = post
if isinstance(post, Answer):
question = post.question
reputation = Repute(user=post.author,
negative=int(REPUTATION_RULES['lose_by_flagged']),
question=question, reputed_at=timestamp,
reputation_type=-4,
reputation=post.author.reputation)
reputation.save()
#todo: These should be updated to work on same revisions.
if post.offensive_flag_count == VOTE_RULES['scope_flags_invisible_main_page'] :
post.author.reputation = calculate_reputation(post.author.reputation,
int(REPUTATION_RULES['lose_by_flagged_lastrevision_3_times']))
post.author.save()
reputation = Repute(user=post.author,
negative=int(REPUTATION_RULES['lose_by_flagged_lastrevision_3_times']),
question=question,
reputed_at=timestamp,
reputation_type=-6,
reputation=post.author.reputation)
reputation.save()
elif post.offensive_flag_count == VOTE_RULES['scope_flags_delete_post']:
post.author.reputation = calculate_reputation(post.author.reputation,
int(REPUTATION_RULES['lose_by_flagged_lastrevision_5_times']))
post.author.save()
reputation = Repute(user=post.author,
negative=int(REPUTATION_RULES['lose_by_flagged_lastrevision_5_times']),
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()
mark_offensive.send(
sender=post.__class__,
instance=post,
mark_by=user
)