示例#1
0
delete_user_content.connect(delete_user_content_handler, dispatch_uid="delete_user_posts")


def move_forum_content_handler(sender, **kwargs):
    Post.objects.filter(forum=sender).update(forum=kwargs["move_to"])


move_forum_content.connect(move_forum_content_handler, dispatch_uid="move_forum_posts")


def move_thread_handler(sender, **kwargs):
    Post.objects.filter(thread=sender).update(forum=kwargs["move_to"])


move_thread.connect(move_thread_handler, dispatch_uid="move_thread_posts")


def merge_thread_handler(sender, **kwargs):
    Post.objects.filter(thread=sender).update(thread=kwargs["new_thread"])


merge_thread.connect(merge_thread_handler, dispatch_uid="merge_threads_posts")


def sync_user_handler(sender, **kwargs):
    sender.posts = sender.post_set.count()


sync_user_profile.connect(sync_user_handler, dispatch_uid="sync_user_posts")
示例#2
0
    Karma.objects.filter(post=sender).update(forum=kwargs['move_to'].forum,
                                             thread=kwargs['move_to'])


move_post.connect(move_posts_handler, dispatch_uid="move_posts_karmas")


def merge_posts_handler(sender, **kwargs):
    Karma.objects.filter(post=sender).update(post=kwargs['new_post'])
    kwargs['new_post'].upvotes += sender.upvotes
    kwargs['new_post'].downvotes += sender.downvotes


merge_post.connect(merge_posts_handler, dispatch_uid="merge_posts_karmas")


def sync_user_handler(sender, **kwargs):
    sender.karma_given_p = sender.karma_set.filter(score__gt=0).count()
    sender.karma_given_n = sender.karma_set.filter(score__lt=0).count()
    sender.karma_p = sender.post_set.all().aggregate(
        Sum('upvotes'))['upvotes__sum']
    if not sender.karma_p:
        sender.karma_p = 0
    sender.karma_n = sender.post_set.all().aggregate(
        Sum('downvotes'))['downvotes__sum']
    if not sender.karma_n:
        sender.karma_n = 0


sync_user_profile.connect(sync_user_handler, dispatch_uid="sync_user_karmas")
示例#3
0
delete_user_content.connect(delete_user_content_handler,
                            dispatch_uid="delete_user_threads")


def move_forum_content_handler(sender, **kwargs):
    Thread.objects.filter(forum=sender).update(forum=kwargs['move_to'])


move_forum_content.connect(move_forum_content_handler,
                           dispatch_uid="move_forum_threads")


def delete_user_handler(sender, instance, using, **kwargs):
    from misago.models import User
    if sender == User:
        for thread in instance.private_thread_set.all():
            thread.participants.remove(instance)
            if not thread.participants.count():
                thread.delete()


pre_delete.connect(delete_user_handler,
                   dispatch_uid="delete_user_participations")


def sync_user_handler(sender, **kwargs):
    sender.threads = sender.thread_set.count()


sync_user_profile.connect(sync_user_handler, dispatch_uid="sync_user_threads")
示例#4
0
class Crawler(Guest):
    """
    Misago Crawler dummy
    """
    is_team = False

    def __init__(self, username):
        self.username = username

    def is_anonymous(self):
        return False

    def is_authenticated(self):
        return False

    def is_crawler(self):
        return True


"""
Signals handlers
"""


def sync_user_handler(sender, **kwargs):
    sender.following = sender.follows.count()
    sender.followers = sender.follows_set.count()


sync_user_profile.connect(sync_user_handler, dispatch_uid="sync_user_follows")