def __init__(self, model, countable, expected_value, handler): sender = getattr(model, "%s_sender" % countable) def wrapper(sender, **kwargs): if kwargs['new_value'] == expected_value: handler(instance=kwargs['instance']) countable_update.connect(wrapper, sender=sender, weak=False)
def __init__(self): def handler(sender, **kwargs): if kwargs['new_value'] == settings.NECROMANCER_UP_VOTES: answer = kwargs['instance'] if answer.added_at >= (answer.question.added_at + timedelta(days=int(settings.NECROMANCER_DIF_DAYS))): self.award_badge(answer.author, answer) countable_update.connect(handler, sender=getattr(Answer, "vote_up_count_sender"), weak=False)
def __init__(self, up_votes, handler): def handler(sender, **kwargs): if sender is const.TYPE_ACTIVITY_MARK_ANSWER: answer = kwargs['instance'].content_object accepted = True vote_count = answer.vote_up_count else: answer = kwargs['instance'] accepted = answer.accepted vote_count = kwargs['new_value'] if accepted and vote_count == up_votes: handler(answer) activity_record.connect(handler, sender=const.TYPE_ACTIVITY_MARK_ANSWER, weak=False) countable_update.connect(handler, sender=getattr(Answer, "vote_up_count_sender"), weak=False)