Karma.objects.filter(thread=sender).update(thread=kwargs['new_thread']) merge_thread.connect(merge_thread_handler, dispatch_uid="merge_threads_karmas") def move_posts_handler(sender, **kwargs): 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")
def move_posts_handler(sender, **kwargs): 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
def move_thread_handler(sender, **kwargs): Change.objects.filter(thread=sender).update(forum=kwargs['move_to']) move_thread.connect(move_thread_handler, dispatch_uid="move_thread_changes") def merge_thread_handler(sender, **kwargs): Change.objects.filter(thread=sender).update(thread=kwargs['new_thread']) merge_thread.connect(merge_thread_handler, dispatch_uid="merge_threads_changes") def move_posts_handler(sender, **kwargs): Change.objects.filter(post=sender).update(forum=kwargs['move_to'].forum, thread=kwargs['move_to']) move_post.connect(move_posts_handler, dispatch_uid="move_posts_changes") def merge_posts_handler(sender, **kwargs): Change.objects.filter(post=sender).update(post=kwargs['new_post']) merge_post.connect(merge_posts_handler, dispatch_uid="merge_posts_changes")
def move_forum_content_handler(sender, **kwargs): sender.attachment_set.update(forum=kwargs['move_to']) move_forum_content.connect(move_forum_content_handler, dispatch_uid="move_forum_attachments") def move_thread_handler(sender, **kwargs): sender.attachment_set.update(forum=kwargs['move_to']) move_thread.connect(move_thread_handler, dispatch_uid="move_thread_attachments") def move_post_handler(sender, **kwargs): sender.attachment_set.update(forum=kwargs['move_to'].forum, thread=kwargs['move_to']) move_post.connect(move_thread_handler, dispatch_uid="move_post_attachments") def merge_thread_handler(sender, **kwargs): sender.attachment_set.update(thread=kwargs['new_thread']) merge_thread.connect(merge_thread_handler, dispatch_uid="merge_threads_attachments") def merge_post_handler(sender, **kwargs): sender.attachment_set.update(post=kwargs['new_post'], session=('attachments_%s' % kwargs['new_post'].pk)) merge_post.connect(merge_post_handler, dispatch_uid="merge_posts_attachments")
sender.attachment_set.update(forum=kwargs['move_to']) move_thread.connect(move_thread_handler, dispatch_uid="move_thread_attachments") def move_post_handler(sender, **kwargs): sender.attachment_set.update(forum=kwargs['move_to'].forum, thread=kwargs['move_to']) move_post.connect(move_thread_handler, dispatch_uid="move_post_attachments") def merge_thread_handler(sender, **kwargs): sender.attachment_set.update(thread=kwargs['new_thread']) merge_thread.connect(merge_thread_handler, dispatch_uid="merge_threads_attachments") def merge_post_handler(sender, **kwargs): sender.attachment_set.update(post=kwargs['new_post'], session=('attachments_%s' % kwargs['new_post'].pk)) merge_post.connect(merge_post_handler, dispatch_uid="merge_posts_attachments")
def move_thread_handler(sender, **kwargs): Checkpoint.objects.filter(thread=sender).update(forum=kwargs['move_to']) move_thread.connect(move_thread_handler, dispatch_uid="move_thread_checkpoints") def merge_thread_handler(sender, **kwargs): Checkpoint.objects.filter(thread=sender).delete() merge_thread.connect(merge_thread_handler, dispatch_uid="merge_threads_checkpoints") def move_posts_handler(sender, **kwargs): if sender.checkpoints: prev_post = Post.objects.filter(thread=sender.thread_id).filter(merge__lte=sender.merge).exclude(id=sender.pk).order_by('merge', '-id')[:1][0] Checkpoint.objects.filter(post=sender).update(post=prev_post) prev_post.checkpoints = True prev_post.save(force_update=True) sender.checkpoints = False move_post.connect(move_posts_handler, dispatch_uid="move_posts_checkpoints") def merge_posts_handler(sender, **kwargs): Checkpoint.objects.filter(post=sender).update(post=kwargs['new_post']) if sender.checkpoints: kwargs['new_post'].checkpoints = True merge_post.connect(merge_posts_handler, dispatch_uid="merge_posts_checkpoints")
def move_forum_content_handler(sender, **kwargs): Change.objects.filter(forum=sender).update(forum=kwargs['move_to']) move_forum_content.connect(move_forum_content_handler, dispatch_uid="move_forum_changes") def move_thread_handler(sender, **kwargs): Change.objects.filter(thread=sender).update(forum=kwargs['move_to']) move_thread.connect(move_thread_handler, dispatch_uid="move_thread_changes") def merge_thread_handler(sender, **kwargs): Change.objects.filter(thread=sender).update(thread=kwargs['new_thread']) merge_thread.connect(merge_thread_handler, dispatch_uid="merge_threads_changes") def move_posts_handler(sender, **kwargs): Change.objects.filter(post=sender).update(forum=kwargs['move_to'].forum, thread=kwargs['move_to']) move_post.connect(move_posts_handler, dispatch_uid="move_posts_changes") def merge_posts_handler(sender, **kwargs): Change.objects.filter(post=sender).update(post=kwargs['new_post']) merge_post.connect(merge_posts_handler, dispatch_uid="merge_posts_changes")