def __init__(self, activity_type, count): def handler(sender, **kwargs): instance = kwargs['instance'] if Activity.objects.filter(user=instance.user, activity_type__in=activity_type).count() == count: self.award_badge(instance.user, instance.content_object) if not isinstance(activity_type, (tuple, list)): activity_type = (activity_type, ) for type in activity_type: activity_record.connect(handler, sender=type, weak=False)
def __init__(self, activity_type, count): def handler(sender, **kwargs): instance = kwargs['instance'] if Activity.objects.filter( user=instance.user, activity_type__in=activity_type).count() == count: self.award_badge(instance.user, instance.content_object) if not isinstance(activity_type, (tuple, list)): activity_type = (activity_type, ) for type in activity_type: activity_record.connect(handler, sender=type, 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)
def __init__(self, up_votes, handler): def wrapper(sender, instance, **kwargs): if sender is Answer: if (not kwargs['field'] == "score") or (kwargs['new'] < kwargs['old']): return answer = instance.leaf vote_count = kwargs['new'] else: answer = instance.content_object vote_count = answer.vote_up_count if answer.accepted and vote_count == up_votes: handler(answer) activity_record.connect(wrapper, sender=const.TYPE_ACTIVITY_MARK_ANSWER, weak=False) denorm_update.connect(wrapper, sender=Node, weak=False)
def __init__(self, up_votes, handler): def wrapper(sender, instance, **kwargs): if sender is Answer: answer = instance if not "vote_up_count" in answer.get_dirty_fields(): return else: answer = instance.content_object accepted = answer.accepted vote_count = answer.vote_up_count if accepted and vote_count == up_votes: handler(answer) activity_record.connect(wrapper, sender=const.TYPE_ACTIVITY_MARK_ANSWER, weak=False) post_save.connect(wrapper, sender=Answer, weak=False)
def __init__(self, up_votes, handler): def wrapper(sender, instance, **kwargs): if sender is Node: if not (instance.node_type == "answer" and "vote_up_count" in instance.get_dirty_fields()): return answer = instance.leaf else: answer = instance.content_object accepted = answer.accepted vote_count = answer.vote_up_count if accepted and vote_count == up_votes: handler(answer) activity_record.connect(wrapper, sender=const.TYPE_ACTIVITY_MARK_ANSWER, weak=False) post_save.connect(wrapper, sender=Node, weak=False)
def __init__(self, activity_type, handler): def wrapper(sender, **kwargs): handler(instance=kwargs['instance']) activity_record.connect(wrapper, sender=activity_type, weak=False)
}) if question.author.subscription_settings.questions_asked: subscription = QuestionSubscription(question=question, user=question.author) subscription.save() new_subscribers = User.objects.filter( Q(subscription_settings__all_questions=True) | Q(subscription_settings__all_questions_watched_tags=True, marked_tags__name__in=question.tagnames.split(' '), tag_selections__reason='good')) for user in new_subscribers: create_subscription_if_not_exists(question, user) activity_record.connect(question_posted, sender=const.TYPE_ACTIVITY_ASK_QUESTION, weak=False) def answer_posted(sender, instance, **kwargs): answer = instance.content_object question = answer.question subscribers = question.subscribers.values('email', 'username').filter( subscription_settings__enable_notifications=True, subscription_settings__notify_answers=True, subscription_settings__subscribed_questions='i' ).exclude(id=answer.author.id) recipients = create_recipients_dict(subscribers) send_email(settings.EMAIL_SUBJECT_PREFIX + _("New answer to '%s'") % question.title, recipients, "notifications/newanswer.html", {