reputation_type=repute_type) post_save.connect(on_vote, sender=Vote) def on_vote_canceled(instance, **kwargs): if instance.content_object.node_type in ( "question", "answer") and not instance.content_object.wiki: post = instance.content_object.leaf question = (post.__class__ == Question) and post or post.question if instance.vote == -1: instance.user.reputes.create( value=int(settings.REP_GAIN_BY_CANCELING_DOWNVOTE), question=question, reputation_type=TYPE_REPUTATION_GAIN_BY_CANCELING_DOWNVOTE) repute_type, repute_value = (instance.vote == 1) and ( TYPE_REPUTATION_LOST_BY_UPVOTE_CANCELED, -int(settings.REP_LOST_BY_UPVOTE_CANCELED)) or ( TYPE_REPUTATION_GAIN_BY_DOWNVOTE_CANCELED, int(settings.REP_GAIN_BY_DOWNVOTE_CANCELED)) post.author.reputes.create(value=repute_value, question=question, reputation_type=repute_type) mark_canceled.connect(on_vote_canceled, sender=Vote)
) post.author.reputes.create(value=repute_value, question=question, reputation_type=repute_type) post_save.connect(on_vote, sender=Vote) def on_vote_canceled(instance, **kwargs): if instance.content_object.node_type in ("question", "answer") and not instance.content_object.wiki: post = instance.content_object.leaf question = (post.__class__ == Question) and post or post.question if instance.vote == -1: instance.user.reputes.create( value=int(settings.REP_GAIN_BY_CANCELING_DOWNVOTE), question=question, reputation_type=TYPE_REPUTATION_GAIN_BY_CANCELING_DOWNVOTE, ) repute_type, repute_value = ( (instance.vote == 1) and (TYPE_REPUTATION_LOST_BY_UPVOTE_CANCELED, -int(settings.REP_LOST_BY_UPVOTE_CANCELED)) or (TYPE_REPUTATION_GAIN_BY_DOWNVOTE_CANCELED, int(settings.REP_GAIN_BY_DOWNVOTE_CANCELED)) ) post.author.reputes.create(value=repute_value, question=question, reputation_type=repute_type) mark_canceled.connect(on_vote_canceled, sender=Vote)
def record_vote(instance, created, **kwargs): if created: act_type = (instance.vote == 1) and TYPE_ACTIVITY_VOTE_UP or TYPE_ACTIVITY_VOTE_DOWN activity = Activity(user=instance.user, active_at=instance.voted_at, content_object=instance, activity_type=act_type) activity.save() post_save.connect(record_vote, sender=Vote) def record_cancel_vote(instance, **kwargs): act_type = (instance.vote == 1) and TYPE_ACTIVITY_CANCEL_VOTE_UP or TYPE_ACTIVITY_CANCEL_VOTE_DOWN activity = Activity(user=instance.user, active_at=datetime.datetime.now(), content_object=instance, activity_type=act_type) activity.save() mark_canceled.connect(record_cancel_vote, sender=Vote) def record_delete_post(instance, **kwargs): act_type = (instance.__class__ is Question) and TYPE_ACTIVITY_DELETE_QUESTION or TYPE_ACTIVITY_DELETE_ANSWER activity = Activity(user=instance.deleted_by, active_at=datetime.datetime.now(), content_object=instance, activity_type=act_type) activity.save() marked_deleted.connect(record_delete_post, sender=Question) marked_deleted.connect(record_delete_post, sender=Answer) def record_update_tags(instance, created, **kwargs): if not created and 'tagnames' in instance.get_dirty_fields(): activity = Activity(user=instance.author, active_at=datetime.datetime.now(), content_object=instance, activity_type=TYPE_ACTIVITY_UPDATE_TAGS) activity.save()