1 from django.db.models.signals import post_save
\r
2 from forum.models.base import mark_canceled
\r
3 from forum.models.answer import answer_accepted, answer_accepted_canceled
\r
5 from forum.models import *
\r
6 from forum.const import *
\r
9 def on_flagged_item(instance, created, **kwargs):
\r
13 post = instance.content_object.leaf
\r
14 question = (post.__class__ == Question) and post or post.question
\r
16 post.author.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED), question=question,
\r
17 reputation_type=TYPE_REPUTATION_LOST_BY_FLAGGED)
\r
20 if post.offensive_flag_count == settings.FLAG_COUNT_TO_HIDE_POST:
\r
21 post.author.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED_3_TIMES),
\r
22 question=question, reputation_type=TYPE_REPUTATION_LOST_BY_FLAGGED_3_TIMES)
\r
24 if post.offensive_flag_count == settings.FLAG_COUNT_TO_DELETE_POST:
\r
25 post.author.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED_5_TIMES),
\r
26 question=question, reputation_type=TYPE_REPUTATION_LOST_BY_FLAGGED_5_TIMES)
\r
28 post.mark_deleted(User.objects.get_site_owner())
\r
30 post_save.connect(on_flagged_item, sender=FlaggedItem)
\r
32 def on_answer_accepted(answer, user, **kwargs):
\r
33 if user == answer.question.author and not user == answer.author:
\r
34 user.reputes.create(
\r
35 value=int(settings.REP_GAIN_BY_ACCEPTING), question=answer.question,
\r
36 reputation_type=TYPE_REPUTATION_GAIN_BY_ACCEPTING_ANSWER)
\r
38 if not user == answer.author:
\r
39 answer.author.reputes.create(
\r
40 value=int(settings.REP_GAIN_BY_ACCEPTED), question=answer.question,
\r
41 reputation_type=TYPE_REPUTATION_GAIN_BY_ANSWER_ACCEPTED)
\r
43 answer_accepted.connect(on_answer_accepted)
\r
46 def on_answer_accepted_canceled(answer, user, **kwargs):
\r
47 if user == answer.accepted_by:
\r
48 user.reputes.create(
\r
49 value=-int(settings.REP_LOST_BY_CANCELING_ACCEPTED), question=answer.question,
\r
50 reputation_type=TYPE_REPUTATION_LOST_BY_CANCELLING_ACCEPTED_ANSWER)
\r
52 if not user == answer.author:
\r
53 answer.author.reputes.create(
\r
54 value=-int(settings.REP_LOST_BY_ACCEPTED_CANCELED), question=answer.question,
\r
55 reputation_type=TYPE_REPUTATION_LOST_BY_ACCEPTED_ANSWER_CANCELED)
\r
57 answer_accepted_canceled.connect(on_answer_accepted)
\r
60 def on_vote(instance, created, **kwargs):
\r
61 if created and not instance.content_object.wiki:
\r
62 post = instance.content_object.leaf
\r
63 question = (post.__class__ == Question) and post or post.question
\r
65 if instance.vote == -1:
\r
66 instance.user.reputes.create(value=-int(settings.REP_LOST_BY_DOWNVOTING),
\r
67 question=question, reputation_type=TYPE_REPUTATION_LOST_BY_DOWNVOTING)
\r
69 if instance.vote == 1 and post.author.get_reputation_by_upvoted_today() >= int(settings.MAX_REP_BY_UPVOTE_DAY):
\r
72 repute_type, repute_value = (instance.vote == 1) and (
\r
73 TYPE_REPUTATION_GAIN_BY_UPVOTED, int(settings.REP_GAIN_BY_UPVOTED)) or (
\r
74 TYPE_REPUTATION_LOST_BY_DOWNVOTED, -int(settings.REP_LOST_BY_DOWNVOTED))
\r
76 post.author.reputes.create(value=repute_value, question=question, reputation_type=repute_type)
\r
78 post_save.connect(on_vote, sender=Vote)
\r
81 def on_vote_canceled(instance, **kwargs):
\r
82 if not instance.content_object.wiki:
\r
83 post = instance.content_object.leaf
\r
84 question = (post.__class__ == Question) and post or post.question
\r
86 if instance.vote == -1:
\r
87 instance.user.reputes.create(value=int(settings.REP_GAIN_BY_CANCELING_DOWNVOTE),
\r
88 question=question, reputation_type=TYPE_REPUTATION_GAIN_BY_CANCELING_DOWNVOTE)
\r
90 repute_type, repute_value = (instance.vote == 1) and (
\r
91 TYPE_REPUTATION_LOST_BY_UPVOTE_CANCELED, -int(settings.REP_LOST_BY_UPVOTE_CANCELED)) or (
\r
92 TYPE_REPUTATION_GAIN_BY_DOWNVOTE_CANCELED, int(settings.REP_GAIN_BY_DOWNVOTE_CANCELED))
\r
94 post.author.reputes.create(value=repute_value, question=question, reputation_type=repute_type)
\r
96 mark_canceled.connect(on_vote_canceled, sender=Vote)
\r