예제 #1
0
def on_answer_accepted(answer, user, **kwargs):
    if user == answer.question.author and not user == answer.author:
        user.reputes.create(
            value=int(settings.REP_GAIN_BY_ACCEPTING),
            question=answer.question,
            reputation_type=TYPE_REPUTATION_GAIN_BY_ACCEPTING_ANSWER)

    if not user == answer.author:
        answer.author.reputes.create(
            value=int(settings.REP_GAIN_BY_ACCEPTED),
            question=answer.question,
            reputation_type=TYPE_REPUTATION_GAIN_BY_ANSWER_ACCEPTED)


answer_accepted.connect(on_answer_accepted)


def on_answer_accepted_canceled(answer, user, **kwargs):
    if user == answer.accepted_by:
        user.reputes.create(
            value=-int(settings.REP_LOST_BY_CANCELING_ACCEPTED),
            question=answer.question,
            reputation_type=TYPE_REPUTATION_LOST_BY_CANCELLING_ACCEPTED_ANSWER)

    if not user == answer.author:
        answer.author.reputes.create(
            value=-int(settings.REP_LOST_BY_ACCEPTED_CANCELED),
            question=answer.question,
            reputation_type=TYPE_REPUTATION_LOST_BY_ACCEPTED_ANSWER_CANCELED)
예제 #2
0
    if user == answer.question.author and not user == answer.author:
        user.reputes.create(
            value=int(settings.REP_GAIN_BY_ACCEPTING),
            question=answer.question,
            reputation_type=TYPE_REPUTATION_GAIN_BY_ACCEPTING_ANSWER,
        )

    if not user == answer.author:
        answer.author.reputes.create(
            value=int(settings.REP_GAIN_BY_ACCEPTED),
            question=answer.question,
            reputation_type=TYPE_REPUTATION_GAIN_BY_ANSWER_ACCEPTED,
        )


answer_accepted.connect(on_answer_accepted)


def on_answer_accepted_canceled(answer, user, **kwargs):
    if user == answer.accepted_by:
        user.reputes.create(
            value=-int(settings.REP_LOST_BY_CANCELING_ACCEPTED),
            question=answer.question,
            reputation_type=TYPE_REPUTATION_LOST_BY_CANCELLING_ACCEPTED_ANSWER,
        )

    if not user == answer.author:
        answer.author.reputes.create(
            value=-int(settings.REP_LOST_BY_ACCEPTED_CANCELED),
            question=answer.question,
            reputation_type=TYPE_REPUTATION_LOST_BY_ACCEPTED_ANSWER_CANCELED,
예제 #3
0

def record_award_event(instance, created, **kwargs):
    if created:
        activity = Activity(user=instance.user, active_at=instance.awarded_at, content_object=instance,
            activity_type=TYPE_ACTIVITY_PRIZE)
        activity.save()

post_save.connect(record_award_event, sender=Award)


def record_answer_accepted(answer, user, **kwargs):
    activity = Activity(user=user, active_at=datetime.datetime.now(), content_object=answer, activity_type=TYPE_ACTIVITY_MARK_ANSWER)
    activity.save()

answer_accepted.connect(record_answer_accepted)


def update_last_seen(instance, **kwargs):
    user = instance.user
    user.last_seen = datetime.datetime.now()
    user.save()

post_save.connect(update_last_seen, sender=Activity)


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)