from django.db.models.signals import post_save\r
-from forum.models.meta import vote_canceled\r
+from forum.models.base import mark_canceled\r
+from forum.models.answer import answer_accepted, answer_accepted_canceled\r
\r
from forum.models import *\r
from forum.const import *\r
if not created:\r
return\r
\r
- post = instance.content_object\r
+ post = instance.content_object.leaf\r
question = (post.__class__ == Question) and post or post.question\r
\r
- user.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED), question=question,\r
+ post.author.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED), question=question,\r
reputation_type=TYPE_REPUTATION_LOST_BY_FLAGGED)\r
\r
\r
\r
post_save.connect(on_flagged_item, sender=FlaggedItem)\r
\r
+def on_answer_accepted(answer, user, **kwargs):\r
+ if user == answer.question.author and not user == answer.author:\r
+ user.reputes.create(\r
+ value=int(settings.REP_GAIN_BY_ACCEPTING), question=answer.question,\r
+ reputation_type=TYPE_REPUTATION_GAIN_BY_ACCEPTING_ANSWER)\r
\r
-def on_answer_accepted_switch(instance, created, **kwargs):\r
- if not created and 'accepted' in instance.get_dirty_fields() and (\r
- not instance.accepted_by == instance.question.author):\r
- repute_type, repute_value = instance.accepted and (\r
- TYPE_REPUTATION_GAIN_BY_ANSWER_ACCEPTED, int(settings.REP_GAIN_BY_ACCEPTED)) or (\r
- TYPE_REPUTATION_LOST_BY_ACCEPTED_ANSWER_CANCELED, -int(settings.REP_LOST_BY_ACCEPTED_CANCELED))\r
+ if not user == answer.author:\r
+ answer.author.reputes.create(\r
+ value=int(settings.REP_GAIN_BY_ACCEPTED), question=answer.question,\r
+ reputation_type=TYPE_REPUTATION_GAIN_BY_ANSWER_ACCEPTED)\r
\r
- instance.author.reputes.create(value=repute_value, question=instance.question, reputation_type=repute_type)\r
- \r
- if instance.accepted_by == instance.question.author:\r
- repute_type, repute_value = instance.accepted and (\r
- TYPE_REPUTATION_GAIN_BY_ACCEPTING_ANSWER, int(settings.REP_GAIN_BY_ACCEPTING)) or (\r
- TYPE_REPUTATION_LOST_BY_CANCELLING_ACCEPTED_ANSWER, -int(settings.REP_LOST_BY_CANCELING_ACCEPTED))\r
+answer_accepted.connect(on_answer_accepted)\r
\r
- instance.question.author.reputes.create(value=repute_value, question=instance.question, reputation_type=repute_type)\r
\r
-post_save.connect(on_answer_accepted_switch, sender=Answer)\r
+def on_answer_accepted_canceled(answer, user, **kwargs):\r
+ if user == answer.accepted_by:\r
+ user.reputes.create(\r
+ value=-int(settings.REP_LOST_BY_CANCELING_ACCEPTED), question=answer.question,\r
+ reputation_type=TYPE_REPUTATION_LOST_BY_CANCELLING_ACCEPTED_ANSWER)\r
+\r
+ if not user == answer.author:\r
+ answer.author.reputes.create(\r
+ value=-int(settings.REP_LOST_BY_ACCEPTED_CANCELED), question=answer.question,\r
+ reputation_type=TYPE_REPUTATION_LOST_BY_ACCEPTED_ANSWER_CANCELED)\r
+\r
+answer_accepted_canceled.connect(on_answer_accepted)\r
\r
\r
def on_vote(instance, created, **kwargs):\r
- if created and not instance.content_object.wiki:\r
- post = instance.content_object\r
+ if created and (instance.content_object.node_type in ("question", "answer") and not instance.content_object.wiki):\r
+ post = instance.content_object.leaf\r
question = (post.__class__ == Question) and post or post.question\r
\r
if instance.vote == -1:\r
\r
\r
def on_vote_canceled(instance, **kwargs):\r
- if not instance.content_object.wiki:\r
- post = instance.content_object\r
+ if instance.content_object.node_type in ("question", "answer") and not instance.content_object.wiki:\r
+ post = instance.content_object.leaf\r
question = (post.__class__ == Question) and post or post.question\r
\r
if instance.vote == -1:\r
\r
post.author.reputes.create(value=repute_value, question=question, reputation_type=repute_type)\r
\r
-vote_canceled.connect(on_vote_canceled)\r
+mark_canceled.connect(on_vote_canceled, sender=Vote)\r
\r
\r
\r