1 from django.db.models.signals import post_save
\r
2 from forum.models.meta import vote_canceled
\r
4 from forum.models import *
\r
5 from forum.const import *
\r
8 def on_flagged_item(instance, created, **kwargs):
\r
12 post = instance.content_object
\r
13 question = (post.__class__ == Question) and post or post.question
\r
15 user.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED), question=question,
\r
16 reputation_type=TYPE_REPUTATION_LOST_BY_FLAGGED)
\r
19 if post.offensive_flag_count == settings.FLAG_COUNT_TO_HIDE_POST:
\r
20 post.author.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED_3_TIMES),
\r
21 question=question, reputation_type=TYPE_REPUTATION_LOST_BY_FLAGGED_3_TIMES)
\r
23 if post.offensive_flag_count == settings.FLAG_COUNT_TO_DELETE_POST:
\r
24 post.author.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED_5_TIMES),
\r
25 question=question, reputation_type=TYPE_REPUTATION_LOST_BY_FLAGGED_5_TIMES)
\r
27 post.mark_deleted(User.objects.get_site_owner())
\r
29 post_save.connect(on_flagged_item, sender=FlaggedItem)
\r
32 def on_answer_accepted_switch(instance, created, **kwargs):
\r
33 if not created and 'accepted' in instance.get_dirty_fields() and (
\r
34 not instance.accepted_by == instance.question.author):
\r
35 repute_type, repute_value = instance.accepted and (
\r
36 TYPE_REPUTATION_GAIN_BY_ANSWER_ACCEPTED, int(settings.REP_GAIN_BY_ACCEPTED)) or (
\r
37 TYPE_REPUTATION_LOST_BY_ACCEPTED_ANSWER_CANCELED, -int(settings.REP_LOST_BY_ACCEPTED_CANCELED))
\r
39 instance.author.reputes.create(value=repute_value, question=instance.question, reputation_type=repute_type)
\r
41 if instance.accepted_by == instance.question.author:
\r
42 repute_type, repute_value = instance.accepted and (
\r
43 TYPE_REPUTATION_GAIN_BY_ACCEPTING_ANSWER, int(settings.REP_GAIN_BY_ACCEPTING)) or (
\r
44 TYPE_REPUTATION_LOST_BY_CANCELLING_ACCEPTED_ANSWER, -int(settings.REP_LOST_BY_CANCELING_ACCEPTED))
\r
46 instance.question.author.reputes.create(value=repute_value, question=instance.question, reputation_type=repute_type)
\r
48 post_save.connect(on_answer_accepted_switch, sender=Answer)
\r
51 def on_vote(instance, created, **kwargs):
\r
52 if created and not instance.content_object.wiki:
\r
53 post = instance.content_object
\r
54 question = (post.__class__ == Question) and post or post.question
\r
56 if instance.vote == -1:
\r
57 instance.user.reputes.create(value=-int(settings.REP_LOST_BY_DOWNVOTING),
\r
58 question=question, reputation_type=TYPE_REPUTATION_LOST_BY_DOWNVOTING)
\r
60 if instance.vote == 1 and post.author.get_reputation_by_upvoted_today() >= int(settings.MAX_REP_BY_UPVOTE_DAY):
\r
63 repute_type, repute_value = (instance.vote == 1) and (
\r
64 TYPE_REPUTATION_GAIN_BY_UPVOTED, int(settings.REP_GAIN_BY_UPVOTED)) or (
\r
65 TYPE_REPUTATION_LOST_BY_DOWNVOTED, -int(settings.REP_LOST_BY_DOWNVOTED))
\r
67 post.author.reputes.create(value=repute_value, question=question, reputation_type=repute_type)
\r
69 post_save.connect(on_vote, sender=Vote)
\r
72 def on_vote_canceled(instance, **kwargs):
\r
73 if not instance.content_object.wiki:
\r
74 post = instance.content_object
\r
75 question = (post.__class__ == Question) and post or post.question
\r
77 if instance.vote == -1:
\r
78 instance.user.reputes.create(value=int(settings.REP_GAIN_BY_CANCELING_DOWNVOTE),
\r
79 question=question, reputation_type=TYPE_REPUTATION_GAIN_BY_CANCELING_DOWNVOTE)
\r
81 repute_type, repute_value = (instance.vote == 1) and (
\r
82 TYPE_REPUTATION_LOST_BY_UPVOTE_CANCELED, -int(settings.REP_LOST_BY_UPVOTE_CANCELED)) or (
\r
83 TYPE_REPUTATION_GAIN_BY_DOWNVOTE_CANCELED, int(settings.REP_GAIN_BY_DOWNVOTE_CANCELED))
\r
85 post.author.reputes.create(value=repute_value, question=question, reputation_type=repute_type)
\r
87 vote_canceled.connect(on_vote_canceled)
\r