예제 #1
0
    def handle(self, *args, **options):
        items_to_create = options['categories']
        min_level = options['minlevel']

        categories = Category.objects.all_categories(True)

        copy_acl_from = list(Category.objects.all_categories())[0]

        categories = categories.filter(level__gte=min_level)
        fake = Factory.create()

        message = 'Creating %s fake categories...\n'
        self.stdout.write(message % items_to_create)

        message = '\n\nSuccessfully created %s fake categories in %s'

        created_count = 0
        start_time = time.time()
        show_progress(self, created_count, items_to_create)

        while created_count < items_to_create:
            parent = random.choice(categories)

            new_category = Category()
            if random.randint(1, 100) > 75:
                new_category.set_name(fake.catch_phrase().title())
            else:
                new_category.set_name(fake.street_name())

            if random.randint(1, 100) > 50:
                if random.randint(1, 100) > 80:
                    new_category.description = '\r\n'.join(fake.paragraphs())
                else:
                    new_category.description = fake.paragraph()

            new_category.insert_at(parent,
                position='last-child',
                save=True,
            )

            copied_acls = []
            for acl in copy_acl_from.category_role_set.all():
                copied_acls.append(RoleCategoryACL(
                    role_id=acl.role_id,
                    category=new_category,
                    category_role_id=acl.category_role_id,
                ))

            if copied_acls:
                RoleCategoryACL.objects.bulk_create(copied_acls)

            created_count += 1
            show_progress(
                self, created_count, items_to_create, start_time)

        acl_version.invalidate()

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (created_count, total_humanized))
예제 #2
0
    def handle(self, *args, **options):
        User = get_user_model()
        total_users = User.objects.count()

        message = 'Adding fake followers to %s users...\n'
        self.stdout.write(message % total_users)

        message = '\nSuccessfully added %s fake followers'

        total_followers = 0
        processed_count = 0

        show_progress(self, processed_count, total_users)
        for user in User.objects.iterator():
            user.followed_by.clear()

            users_to_add = random.randint(1, total_users - 1)
            random_queryset = User.objects.exclude(id=user.id).order_by('?')
            while users_to_add > 0:
                new_follower = random_queryset[:1][0]
                if not new_follower.is_following(user):
                    user.followed_by.add(new_follower)
                    users_to_add -= 1
                    total_followers += 1

            processed_count += 1
            show_progress(self, processed_count, total_users)

        self.stdout.write('\nSyncing models...')
        for user in User.objects.iterator():
            user.followers = user.followed_by.count()
            user.following = user.follows.count()
            user.save(update_fields=['followers', 'following'])

        self.stdout.write(message % total_followers)
    def sync_threads(self, posts_to_sync):
        message = "Rebuilding %s posts...\n"
        self.stdout.write(message % posts_to_sync)

        message = "\n\nRebuild %s posts"

        synchronized_count = 0
        show_progress(self, synchronized_count, posts_to_sync)
        start_time = time.time()

        queryset = Post.objects.select_related('thread').filter(is_event=False)
        for post in batch_update(queryset):
            if post.id == post.thread.first_post_id:
                post.set_search_document(post.thread.title)
            else:
                post.set_search_document()
            post.save(update_fields=['search_document'])

            post.update_search_vector()
            post.save(update_fields=['search_vector'])

            synchronized_count += 1
            show_progress(self, synchronized_count, posts_to_sync, start_time)

        self.stdout.write(message % synchronized_count)
    def sync_users(self, users_to_sync):
        categories = Category.objects.root_category().get_descendants()

        self.stdout.write("Synchronizing {} users...\n".format(users_to_sync))

        synchronized_count = 0
        show_progress(self, synchronized_count, users_to_sync)
        start_time = time.time()

        for user in chunk_queryset(UserModel.objects.all()):
            user.threads = user.thread_set.filter(
                category__in=categories,
                is_hidden=False,
                is_unapproved=False,
            ).count()

            user.posts = user.post_set.filter(
                category__in=categories,
                is_event=False,
                is_unapproved=False,
            ).count()

            user.followers = user.followed_by.count()
            user.following = user.follows.count()

            user.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, users_to_sync, start_time)

        self.stdout.write(
            "\n\nSynchronized {} users".format(synchronized_count))
예제 #5
0
    def sync_threads(self, posts_to_sync):
        message = "Rebuilding %s posts...\n"
        self.stdout.write(message % posts_to_sync)

        message = "\n\nRebuild %s posts"

        synchronized_count = 0
        show_progress(self, synchronized_count, posts_to_sync)
        start_time = time.time()

        queryset = Post.objects.select_related('thread').filter(is_event=False)
        for post in chunk_queryset(queryset):
            if post.id == post.thread.first_post_id:
                post.set_search_document(post.thread.title)
            else:
                post.set_search_document()
            post.save(update_fields=['search_document'])

            post.update_search_vector()
            post.save(update_fields=['search_vector'])

            synchronized_count += 1
            show_progress(self, synchronized_count, posts_to_sync, start_time)

        self.stdout.write(message % synchronized_count)
    def sync_users(self, users_to_sync):
        categories = Category.objects.root_category().get_descendants()

        message = "Synchronizing %s users...\n"
        self.stdout.write(message % users_to_sync)

        synchronized_count = 0
        show_progress(self, synchronized_count, users_to_sync)
        start_time = time.time()
        for user in batch_update(UserModel.objects.all()):
            user.threads = user.thread_set.filter(
                category__in=categories,
                is_hidden=False,
                is_unapproved=False,
            ).count()

            user.posts = user.post_set.filter(
                category__in=categories,
                is_event=False,
                is_unapproved=False,
            ).count()

            user.followers = user.followed_by.count()
            user.following = user.follows.count()

            user.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, users_to_sync, start_time)

        self.stdout.write("\n\nSynchronized %s users" % synchronized_count)
예제 #7
0
    def handle(self, *args, **options):
        try:
            fake_users_to_create = int(args[0])
        except IndexError:
            fake_users_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        fake = Factory.create()
        User = get_user_model()

        ranks = [r for r in Rank.objects.all()]

        message = 'Creating %s fake user accounts...\n'
        self.stdout.write(message % fake_users_to_create)

        message = '\n\nSuccessfully created %s fake user accounts in %s'

        created_count = 0
        start_time = time.time()
        show_progress(self, created_count, fake_users_to_create)
        for i in range(fake_users_to_create):
            try:
                kwargs = {
                    'rank': random.choice(ranks),
                }

                user = User.objects.create_user(fake.first_name(),
                                                fake.email(),
                                                'pass123',
                                                set_default_avatar=False,
                                                **kwargs)

                if random.randint(0, 100) > 90:
                    dynamic.set_avatar(user)
                else:
                    gallery.set_random_avatar(user)

                user.avatar_hash = get_avatar_hash(user)
                user.save(update_fields=['avatar_hash'])
            except (ValidationError, IntegrityError):
                pass
            else:
                created_count += 1
                show_progress(self, created_count, fake_users_to_create,
                              start_time)

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (created_count, total_humanized))
예제 #8
0
    def sync_attachments(self, queryset, attachments_to_sync):
        self.stdout.write("Clearing %s attachments...\n" % attachments_to_sync)

        cleared_count = 0
        show_progress(self, cleared_count, attachments_to_sync)
        start_time = time.time()
        
        for attachment in chunk_queryset(queryset):
            attachment.delete()

            cleared_count += 1
            show_progress(self, cleared_count, attachments_to_sync, start_time)

        self.stdout.write("\n\nCleared %s attachments" % cleared_count)
예제 #9
0
    def handle(self, *args, **options):
        try:
            fake_users_to_create = int(args[0])
        except IndexError:
            fake_users_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        fake = Factory.create()
        User = get_user_model()

        ranks = [r for r in Rank.objects.all()]

        message = 'Creating %s fake user accounts...\n'
        self.stdout.write(message % fake_users_to_create)

        message = '\n\nSuccessfully created %s fake user accounts in %s'

        created_count = 0
        start_time = time.time()
        show_progress(self, created_count, fake_users_to_create)
        for i in range(fake_users_to_create):
            try:
                kwargs = {
                    'rank': random.choice(ranks),
                }

                user = User.objects.create_user(
                    fake.first_name(), fake.email(), 'pass123',
                    set_default_avatar=False, **kwargs)

                if random.randint(0, 100) > 90:
                    dynamic.set_avatar(user)
                else:
                    gallery.set_random_avatar(user)

                user.avatar_hash = get_avatar_hash(user)
                user.save(update_fields=['avatar_hash'])
            except (ValidationError, IntegrityError):
                pass
            else:
                created_count += 1
                show_progress(
                    self, created_count, fake_users_to_create, start_time)

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (created_count, total_humanized))
    def sync_threads(self, threads_to_sync):
        self.stdout.write("Synchronizing {} threads...\n".format(threads_to_sync))

        synchronized_count = 0
        show_progress(self, synchronized_count, threads_to_sync)
        start_time = time.time()

        for thread in chunk_queryset(Thread.objects.all()):
            thread.synchronize()
            thread.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, threads_to_sync, start_time)

        self.stdout.write("\n\nSynchronized {} threads".format(synchronized_count))
예제 #11
0
    def update_posts_checksums(self, posts_to_update):
        self.stdout.write("Updating %s posts checksums...\n" % posts_to_update)

        updated_count = 0
        show_progress(self, updated_count, posts_to_update)
        start_time = time.time()

        queryset = Post.objects.filter(is_event=False)
        for post in chunk_queryset(queryset):
            update_post_checksum(post)
            post.save(update_fields=['checksum'])

            updated_count += 1
            show_progress(self, updated_count, posts_to_update, start_time)

        self.stdout.write("\n\nUpdated %s posts checksums" % updated_count)
    def sync_attachments(self, queryset, attachments_to_sync):
        message = "Clearing %s attachments...\n"
        self.stdout.write(message % attachments_to_sync)

        message = "\n\nCleared %s attachments"

        synchronized_count = 0
        show_progress(self, synchronized_count, attachments_to_sync)
        start_time = time.time()
        for attachment in chunk_queryset(queryset):
            attachment.delete()

            synchronized_count += 1
            show_progress(self, synchronized_count, attachments_to_sync, start_time)

        self.stdout.write(message % synchronized_count)
    def sync_attachments(self, queryset, attachments_to_sync):
        message = "Clearing %s attachments...\n"
        self.stdout.write(message % attachments_to_sync)

        message = "\n\nCleared %s attachments"

        synchronized_count = 0
        show_progress(self, synchronized_count, attachments_to_sync)
        start_time = time.time()
        for attachment in batch_update(queryset):
            attachment.delete()

            synchronized_count += 1
            show_progress(self, synchronized_count, attachments_to_sync, start_time)

        self.stdout.write(message % synchronized_count)
예제 #14
0
    def sync_threads(self, threads_to_sync):
        message = "Synchronizing %s threads...\n"
        self.stdout.write(message % threads_to_sync)

        message = "\n\nSynchronized %s threads"

        synchronized_count = 0
        show_progress(self, synchronized_count, threads_to_sync)
        start_time = time.time()
        for thread in batch_update(Thread.objects.all()):
            thread.synchronize()
            thread.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, threads_to_sync, start_time)

        self.stdout.write(message % synchronized_count)
예제 #15
0
    def sync_threads(self, threads_to_sync):
        message = "Synchronizing %s threads...\n"
        self.stdout.write(message % threads_to_sync)

        message = "\n\nSynchronized %s threads"

        synchronized_count = 0
        show_progress(self, synchronized_count, threads_to_sync)
        start_time = time.time()
        for thread in batch_update(Thread.objects.all()):
            thread.synchronize()
            thread.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, threads_to_sync, start_time)

        self.stdout.write(message % synchronized_count)
예제 #16
0
    def handle(self, *args, **options):
        categories_to_sync = Category.objects.count()

        message = 'Synchronizing %s categories...\n'
        self.stdout.write(message % categories_to_sync)

        message = '\n\nSynchronized %s categories'

        synchronized_count = 0
        show_progress(self, synchronized_count, categories_to_sync)
        for category in Category.objects.iterator():
            category.synchronize()
            category.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, categories_to_sync)

        self.stdout.write(message % synchronized_count)
    def handle(self, *args, **options):
        categories_to_sync = Category.objects.count()

        message = 'Synchronizing %s categories...\n'
        self.stdout.write(message % categories_to_sync)

        message = '\n\nSynchronized %s categories'

        synchronized_count = 0
        show_progress(self, synchronized_count, categories_to_sync)
        for category in Category.objects.iterator():
            category.synchronize()
            category.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, categories_to_sync)

        self.stdout.write(message % synchronized_count)
예제 #18
0
    def handle(self, *args, **options):
        forums_to_sync = Forum.objects.count()

        message = 'Synchronizing %s forums...\n'
        self.stdout.write(message % forums_to_sync)

        message = '\n\nSynchronized %s forums'

        synchronized_count = 0
        show_progress(self, synchronized_count, forums_to_sync)
        for forum in Forum.objects.iterator():
            forum.synchronize()
            forum.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, forums_to_sync)

        self.stdout.write(message % synchronized_count)
    def handle(self, *args, **options):
        items_to_create = options['users']

        fake = Factory.create()

        ranks = [r for r in Rank.objects.all()]

        message = 'Creating %s fake user accounts...\n'
        self.stdout.write(message % items_to_create)

        created_count = 0
        start_time = time.time()
        show_progress(self, created_count, items_to_create)

        while created_count < items_to_create:
            try:
                possible_usernames = [
                    fake.first_name(),
                    fake.last_name(),
                    fake.name().replace(' ', ''),
                    fake.user_name(),
                ]

                user = UserModel.objects.create_user(
                    random.choice(possible_usernames),
                    fake.email(),
                    'pass123',
                    set_default_avatar=False,
                    rank=random.choice(ranks),
                )

                dynamic.set_avatar(user)
                user.save(update_fields=['avatars'])
            except (ValidationError, IntegrityError):
                pass
            else:
                created_count += 1
                show_progress(self, created_count, items_to_create, start_time)

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        message = '\n\nSuccessfully created %s fake user accounts in %s'
        self.stdout.write(message % (created_count, total_humanized))
예제 #20
0
    def handle(self, *args, **options):
        try:
            fake_bans_to_create = int(args[0])
        except IndexError:
            fake_bans_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        fake = Factory.create()

        message = 'Creating %s fake bans...\n'
        self.stdout.write(message % fake_bans_to_create)

        message = '\n\nSuccessfully created %s fake bans'

        created_count = 0
        show_progress(self, created_count, fake_bans_to_create)
        for i in xrange(fake_bans_to_create):
            ban = Ban(check_type=random.randint(BAN_USERNAME, BAN_IP))
            ban.banned_value = create_fake_test(fake, ban.check_type)

            if random.randint(0, 10) == 0:
                ban.user_message = fake.sentence()

            if random.randint(0, 10) == 0:
                ban.staff_message = fake.sentence()

            if random.randint(0, 1):
                # Lets make ban temporary
                ban_length = timedelta(days=random.randint(0, 300))
                if random.randint(0, 1):
                    ban.valid_until = timezone.now().date() - ban_length
                else:
                    ban.valid_until = timezone.now().date() + ban_length

            ban.save()

            created_count += 1
            show_progress(self, created_count, fake_bans_to_create)

        self.stdout.write(message % created_count)
예제 #21
0
    def handle(self, *args, **options):
        items_to_create = options['users']

        fake = Factory.create()

        ranks = [r for r in Rank.objects.all()]

        message = 'Creating %s fake user accounts...\n'
        self.stdout.write(message % items_to_create)

        message = '\n\nSuccessfully created %s fake user accounts in %s'

        created_count = 0
        start_time = time.time()
        show_progress(self, created_count, items_to_create)

        while created_count < items_to_create:
            try:
                kwargs = {
                    'rank': random.choice(ranks),
                }

                user = UserModel.objects.create_user(fake.first_name(),
                                                     fake.email(),
                                                     'pass123',
                                                     set_default_avatar=False,
                                                     **kwargs)

                if random.randint(0, 100) > 90:
                    dynamic.set_avatar(user)
                else:
                    gallery.set_random_avatar(user)
                user.save(update_fields=['avatars'])
            except (ValidationError, IntegrityError):
                pass
            else:
                created_count += 1
                show_progress(self, created_count, items_to_create, start_time)

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (created_count, total_humanized))
예제 #22
0
    def handle(self, *args, **options):
        try:
            fake_bans_to_create = int(args[0])
        except IndexError:
            fake_bans_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        fake = Factory.create()

        message = 'Creating %s fake bans...\n'
        self.stdout.write(message % fake_bans_to_create)

        message = '\n\nSuccessfully created %s fake bans'

        created_count = 0
        show_progress(self, created_count, fake_bans_to_create)
        for i in range(fake_bans_to_create):
            ban = Ban(check_type=random.randint(Ban.USERNAME, Ban.IP))
            ban.banned_value = create_fake_test(fake, ban.check_type)

            if random.randint(0, 10) == 0:
                ban.user_message = fake.sentence()

            if random.randint(0, 10) == 0:
                ban.staff_message = fake.sentence()

            if random.randint(0, 1):
                # Lets make ban temporary
                ban_length = timedelta(days=random.randint(0, 300))
                if random.randint(0, 1):
                    ban.valid_until = timezone.now().date() - ban_length
                else:
                    ban.valid_until = timezone.now().date() + ban_length

            ban.save()

            created_count += 1
            show_progress(self, created_count, fake_bans_to_create)

        self.stdout.write(message % created_count)
예제 #23
0
    def handle(self, *args, **options):
        threads_to_sync = Thread.objects.count()

        message = 'Synchronizing %s threads...\n'
        self.stdout.write(message % threads_to_sync)

        message = '\n\nSynchronized %s threads'

        synchronized_count = 0
        show_progress(self, synchronized_count, threads_to_sync)
        start_time = time.time()
        for thread in batch_update(Thread.objects.all()):
            thread.synchronize()
            thread.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, threads_to_sync,
                          start_time)

        self.stdout.write(message % synchronized_count)
예제 #24
0
    def sync_users(self, users_to_sync):
        message = 'Synchronizing %s users...\n'
        self.stdout.write(message % users_to_sync)

        message = '\n\nSynchronized %s users'

        synchronized_count = 0
        show_progress(self, synchronized_count, users_to_sync)
        start_time = time.time()
        for user in batch_update(get_user_model().objects.all()):
            user.threads = user.thread_set.count()
            user.posts = user.post_set.count()
            user.followers = user.followed_by.count()
            user.following = user.follows.count()
            user.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, users_to_sync, start_time)

        self.stdout.write(message % synchronized_count)
예제 #25
0
    def handle(self, *args, **options):
        threads_to_sync = Thread.objects.count()

        message = 'Synchronizing %s threads...\n'
        self.stdout.write(message % threads_to_sync)

        message = '\n\nSynchronized %s threads'

        synchronized_count = 0
        show_progress(self, synchronized_count, threads_to_sync)
        start_time = time.time()
        for thread in batch_update(Thread.objects.all()):
            thread.synchronize()
            thread.save()

            synchronized_count += 1
            show_progress(
                self, synchronized_count, threads_to_sync, start_time)

        self.stdout.write(message % synchronized_count)
예제 #26
0
    def handle(self, *args, **options):
        try:
            fake_users_to_create = int(args[0])
        except IndexError:
            fake_users_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        fake = Factory.create()
        User = get_user_model()

        ranks = [r for r in Rank.objects.all()]

        message = 'Creating %s fake user accounts...\n'
        self.stdout.write(message % fake_users_to_create)

        message = '\n\nSuccessfully created %s fake user accounts'

        created_count = 0
        start_time = time.time()
        show_progress(self, created_count, fake_users_to_create)
        for i in xrange(fake_users_to_create):
            try:
                kwargs = {
                    'rank': random.choice(ranks),
                }

                User.objects.create_user(fake.first_name(),
                                         fake.email(),
                                         'pass123',
                                         set_default_avatar=True,
                                         **kwargs)
            except (ValidationError, IntegrityError):
                pass
            else:
                created_count += 1
                show_progress(self, created_count, fake_users_to_create,
                              start_time)

        self.stdout.write(message % created_count)
    def handle(self, *args, **options):
        items_to_create = options['users']

        fake = Factory.create()

        ranks = [r for r in Rank.objects.all()]

        message = 'Creating %s fake user accounts...\n'
        self.stdout.write(message % items_to_create)

        message = '\n\nSuccessfully created %s fake user accounts in %s'

        created_count = 0
        start_time = time.time()
        show_progress(self, created_count, items_to_create)

        while created_count < items_to_create:
            try:
                user = UserModel.objects.create_user(
                    fake.first_name(),
                    fake.email(),
                    'pass123',
                    set_default_avatar=False,
                    rank=random.choice(ranks),
                )

                if random.randint(0, 100) > 90:
                    dynamic.set_avatar(user)
                else:
                    gallery.set_random_avatar(user)
                user.save(update_fields=['avatars'])
            except (ValidationError, IntegrityError):
                pass
            else:
                created_count += 1
                show_progress(self, created_count, items_to_create, start_time)

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (created_count, total_humanized))
예제 #28
0
    def handle(self, *args, **options):
        try:
            fake_users_to_create = int(args[0])
        except IndexError:
            fake_users_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        fake = Factory.create()
        User = get_user_model()

        ranks = [r for r in Rank.objects.all()]

        message = 'Creating %s fake user accounts...\n'
        self.stdout.write(message % fake_users_to_create)

        message = '\n\nSuccessfully created %s fake user accounts'

        created_count = 0
        start_time = time.time()
        show_progress(self, created_count, fake_users_to_create)
        for i in xrange(fake_users_to_create):
            try:
                kwargs = {
                    'rank': random.choice(ranks),
                }

                User.objects.create_user(fake.first_name(), fake.email(),
                                         'pass123', set_default_avatar=True,
                                         **kwargs)
            except (ValidationError, IntegrityError):
                pass
            else:
                created_count += 1
                show_progress(
                    self, created_count, fake_users_to_create, start_time)

        self.stdout.write(message % created_count)
    def rebuild_posts_search(self, posts_to_reindex):
        self.stdout.write("Rebuilding search for {} posts...\n".format(posts_to_reindex))

        rebuild_count = 0
        show_progress(self, rebuild_count, posts_to_reindex)
        start_time = time.time()

        queryset = Post.objects.select_related('thread').filter(is_event=False)
        for post in chunk_queryset(queryset):
            if post.id == post.thread.first_post_id:
                post.set_search_document(post.thread.title)
            else:
                post.set_search_document()
            post.save(update_fields=['search_document'])

            post.update_search_vector()
            post.save(update_fields=['search_vector'])

            rebuild_count += 1
            show_progress(self, rebuild_count, posts_to_reindex, start_time)

        self.stdout.write("\n\nRebuild search for {} posts".format(rebuild_count))
    def handle(self, *args, **options):
        categories_to_sync = Category.objects.count()

        message = 'Synchronizing %s categories...\n'
        self.stdout.write(message % categories_to_sync)

        message = '\n\nSynchronized %s categories in %s'

        start_time = time.time()

        synchronized_count = 0
        show_progress(self, synchronized_count, categories_to_sync)
        for category in Category.objects.iterator():
            category.synchronize()
            category.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, categories_to_sync)

        end_time = time.time() - start_time
        total_time = time.strftime('%H:%M:%S', time.gmtime(end_time))

        self.stdout.write(message % (synchronized_count, total_time))
예제 #31
0
    def sync_users(self, users_to_sync):
        categories = Category.objects.root_category().get_descendants()

        message = "Synchronizing %s users...\n"
        self.stdout.write(message % users_to_sync)

        synchronized_count = 0
        show_progress(self, synchronized_count, users_to_sync)
        start_time = time.time()
        for user in batch_update(get_user_model().objects.all()):
            user.threads = user.thread_set.filter(category__in=categories,
                                                  is_hidden=False,
                                                  is_unapproved=False).count()
            user.posts = user.post_set.filter(category__in=categories,
                                              is_event=False,
                                              is_unapproved=False).count()
            user.followers = user.followed_by.count()
            user.following = user.follows.count()
            user.save()

            synchronized_count += 1
            show_progress(self, synchronized_count, users_to_sync, start_time)

        self.stdout.write("\n\nSynchronized %s users" % synchronized_count)
예제 #32
0
    def handle(self, *args, **options):
        User = get_user_model()
        total_users = User.objects.count()

        message = 'Adding fake followers to %s users...\n'
        self.stdout.write(message % total_users)

        message = '\nSuccessfully added %s fake followers in %s'

        total_followers = 0
        processed_count = 0

        start_time = time.time()
        show_progress(self, processed_count, total_users)
        for user in User.objects.iterator():
            user.followed_by.clear()

            if random.randint(1, 100) > 10:
                processed_count += 1
                show_progress(self, processed_count, total_users)
                continue # 10% active users

            users_to_add = random.randint(1, total_users / 5)
            random_queryset = User.objects.exclude(id=user.id).order_by('?')
            while users_to_add > 0:
                new_follower = random_queryset[:1][0]
                if not new_follower.is_following(user):
                    user.followed_by.add(new_follower)
                    users_to_add -= 1
                    total_followers += 1

            processed_count += 1
            show_progress(self, processed_count, total_users)

        self.stdout.write('\nSyncing models...')
        for user in User.objects.iterator():
            user.followers = user.followed_by.count()
            user.following = user.follows.count()
            user.save(update_fields=['followers', 'following'])

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (total_followers, total_humanized))
예제 #33
0
    def handle(self, *args, **options):
        total_users = UserModel.objects.count()

        message = 'Adding fake followers to %s users...\n'
        self.stdout.write(message % total_users)

        message = '\nSuccessfully added %s fake followers in %s'

        total_followers = 0
        processed_count = 0

        start_time = time.time()
        show_progress(self, processed_count, total_users)
        for user in UserModel.objects.iterator():
            user.followed_by.clear()

            if random.randint(1, 100) > 10:
                processed_count += 1
                show_progress(self, processed_count, total_users)
                continue  # 10% active users

            users_to_add = random.randint(1, total_users / 5)
            random_queryset = UserModel.objects.exclude(
                id=user.id).order_by('?')
            while users_to_add > 0:
                new_follower = random_queryset[:1][0]
                if not new_follower.is_following(user):
                    user.followed_by.add(new_follower)
                    users_to_add -= 1
                    total_followers += 1

            processed_count += 1
            show_progress(self, processed_count, total_users)

        self.stdout.write('\nSyncing models...')
        for user in UserModel.objects.iterator():
            user.followers = user.followed_by.count()
            user.following = user.follows.count()
            user.save(update_fields=['followers', 'following'])

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (total_followers, total_humanized))
예제 #34
0
    def handle(self, *args, **options):
        try:
            fake_cats_to_create = int(args[0])
        except IndexError:
            fake_cats_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        categories = Category.objects.all_categories(True)

        try:
            min_level = int(args[1])
        except (IndexError):
            min_level = 0
        except ValueError:
            self.stderr.write("\nSecond optional argument should be integer.")
            sys.exit(1)

        copy_acl_from = list(Category.objects.all_categories())[0]

        categories = categories.filter(level__gte=min_level)
        fake = Factory.create()

        message = 'Creating %s fake categories...\n'
        self.stdout.write(message % fake_cats_to_create)

        message = '\n\nSuccessfully created %s fake categories in %s'

        created_count = 0
        start_time = time.time()
        show_progress(self, created_count, fake_cats_to_create)
        for i in xrange(fake_cats_to_create):
            parent = random.choice(categories)

            new_category = Category()
            if random.randint(1, 100) > 75:
                new_category.set_name(fake.catch_phrase().title())
            else:
                new_category.set_name(fake.street_name())

            if random.randint(1, 100) > 50:
                if random.randint(1, 100) > 80:
                    new_category.description = '\r\n'.join(fake.paragraphs())
                else:
                    new_category.description = fake.paragraph()

            new_category.insert_at(
                parent,
                position='last-child',
                save=True,
            )

            copied_acls = []
            for acl in copy_acl_from.category_role_set.all():
                copied_acls.append(
                    RoleCategoryACL(
                        role_id=acl.role_id,
                        category=new_category,
                        category_role_id=acl.category_role_id,
                    ))

            if copied_acls:
                RoleCategoryACL.objects.bulk_create(copied_acls)

            created_count += 1
            show_progress(self, created_count, fake_cats_to_create, start_time)

        acl_version.invalidate()

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (created_count, total_humanized))
예제 #35
0
    def handle(self, *args, **options):
        items_to_create = options['threads']

        categories = list(Category.objects.all_categories())

        fake = Factory.create()

        User = get_user_model()
        total_users = User.objects.count()

        self.stdout.write('Creating fake threads...\n')

        message = '\nSuccessfully created %s fake threads in %s'

        created_threads = 0
        start_time = time.time()
        show_progress(self, created_threads, items_to_create)

        while created_threads < items_to_create:
            with atomic():
                datetime = timezone.now()
                category = random.choice(categories)
                user = User.objects.order_by('?')[:1][0]

                thread_is_unapproved = random.randint(0, 100) > 90
                thread_is_hidden = random.randint(0, 100) > 90
                thread_is_closed = random.randint(0, 100) > 90

                thread = Thread(
                    category=category,
                    started_on=datetime,
                    starter_name='-',
                    starter_slug='-',
                    last_post_on=datetime,
                    last_poster_name='-',
                    last_poster_slug='-',
                    replies=0,
                    is_unapproved=thread_is_unapproved,
                    is_hidden=thread_is_hidden,
                    is_closed=thread_is_closed
                )
                thread.set_title(fake.sentence())
                thread.save()

                fake_message = "\n\n".join(fake.paragraphs())
                post = Post.objects.create(
                    category=category,
                    thread=thread,
                    poster=user,
                    poster_name=user.username,
                    poster_ip=fake.ipv4(),
                    original=fake_message,
                    parsed=linebreaks_filter(fake_message),
                    posted_on=datetime,
                    updated_on=datetime
                )
                update_post_checksum(post)
                post.save(update_fields=['checksum'])

                thread.set_first_post(post)
                thread.set_last_post(post)
                thread.save()

                user.threads += 1
                user.posts += 1
                user.save()

                thread_type = random.randint(0, 100)
                if thread_type > 95:
                    thread_replies = random.randint(200, 2500)
                elif thread_type > 50:
                    thread_replies = random.randint(5, 30)
                else:
                    thread_replies = random.randint(0, 10)

                for x in range(thread_replies):
                    datetime = timezone.now()
                    user = User.objects.order_by('?')[:1][0]
                    fake_message = "\n\n".join(fake.paragraphs())

                    is_unapproved = random.randint(0, 100) > 97

                    post = Post.objects.create(
                        category=category,
                        thread=thread,
                        poster=user,
                        poster_name=user.username,
                        poster_ip=fake.ipv4(),
                        original=fake_message,
                        parsed=linebreaks_filter(fake_message),
                        is_unapproved=is_unapproved,
                        posted_on=datetime,
                        updated_on=datetime
                    )

                    if not is_unapproved:
                        is_hidden = random.randint(0, 100) > 97
                    else:
                        is_hidden = False

                    if is_hidden:
                        post.is_hidden = True

                        if random.randint(0, 100) < 80:
                            user = User.objects.order_by('?')[:1][0]
                            post.hidden_by = user
                            post.hidden_by_name = user.username
                            post.hidden_by_slug = user.username
                        else:
                            post.hidden_by_name = fake.first_name()
                            post.hidden_by_slug = post.hidden_by_name.lower()

                    update_post_checksum(post)
                    post.save()

                    user.posts += 1
                    user.save()

                thread.synchronize()
                thread.save()

                created_threads += 1
                show_progress(
                    self, created_threads, items_to_create, start_time)

        pinned_threads = random.randint(0, int(created_threads * 0.025)) or 1
        self.stdout.write('\nPinning %s threads...' % pinned_threads)
        for i in range(0, pinned_threads):
            thread = Thread.objects.order_by('?')[:1][0]
            if random.randint(0, 100) > 75:
                thread.weight = 2
            else:
                thread.weight = 1
            thread.save()

        for category in categories:
            category.synchronize()
            category.save()

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (created_threads, total_humanized))
예제 #36
0
    def handle(self, *args, **options):
        try:
            fake_threads_to_create = int(args[0])
        except IndexError:
            fake_threads_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        forums = [f for f in Forum.objects.all_forums().filter(role='forum')]

        fake = Factory.create()

        User = get_user_model()
        total_users = User.objects.count()

        self.stdout.write('Creating fake threads...\n')

        message = '\nSuccessfully created %s fake threads'

        created_threads = 0
        start_time = time.time()
        show_progress(self, created_threads, fake_threads_to_create)
        for i in xrange(fake_threads_to_create):
            with atomic():
                datetime = timezone.now()
                forum = random.choice(forums)
                user = User.objects.order_by('?')[:1][0]

                thread_is_moderated = random.randint(0, 100) > 90
                thread_is_hidden = random.randint(0, 100) > 90
                thread_is_closed = random.randint(0, 100) > 90

                thread = Thread(forum=forum,
                                started_on=datetime,
                                starter_name='-',
                                starter_slug='-',
                                last_post_on=datetime,
                                last_poster_name='-',
                                last_poster_slug='-',
                                replies=0,
                                is_moderated=thread_is_moderated,
                                is_hidden=thread_is_hidden,
                                is_closed=thread_is_closed)
                thread.set_title(fake.sentence())
                thread.save()

                fake_message = "\n\n".join(fake.paragraphs())
                post = Post.objects.create(
                    forum=forum,
                    thread=thread,
                    poster=user,
                    poster_name=user.username,
                    poster_ip=fake.ipv4(),
                    original=fake_message,
                    parsed=linebreaks_filter(fake_message),
                    posted_on=datetime,
                    updated_on=datetime)
                update_post_checksum(post)
                post.save(update_fields=['checksum'])

                thread.set_first_post(post)
                thread.set_last_post(post)
                thread.save()

                user.threads += 1
                user.posts += 1
                user.save()

                thread_type = random.randint(0, 100)
                if thread_type > 95:
                    thread_replies = random.randint(200, 500)
                elif thread_type > 50:
                    thread_replies = random.randint(5, 30)
                else:
                    thread_replies = random.randint(0, 10)

                for x in xrange(thread_replies):
                    datetime = timezone.now()
                    user = User.objects.order_by('?')[:1][0]
                    fake_message = "\n\n".join(fake.paragraphs())

                    is_moderated = random.randint(0, 100) > 97
                    if not is_moderated:
                        is_hidden = random.randint(0, 100) > 97
                    else:
                        is_hidden = False

                    post = Post.objects.create(
                        forum=forum,
                        thread=thread,
                        poster=user,
                        poster_name=user.username,
                        poster_ip=fake.ipv4(),
                        original=fake_message,
                        parsed=linebreaks_filter(fake_message),
                        is_hidden=is_hidden,
                        is_moderated=is_moderated,
                        posted_on=datetime,
                        updated_on=datetime)
                    update_post_checksum(post)
                    post.save(update_fields=['checksum'])

                    user.posts += 1
                    user.save()

                thread.synchronize()
                thread.save()

                created_threads += 1
                show_progress(self, created_threads, fake_threads_to_create,
                              start_time)

        pinned_threads = random.randint(0, int(created_threads * 0.025)) or 1
        self.stdout.write('\nPinning %s threads...' % pinned_threads)
        for i in xrange(0, pinned_threads):
            thread = Thread.objects.order_by('?')[:1][0]
            thread.is_pinned = True
            thread.save()

        for forum in forums:
            forum.synchronize()
            forum.save()

        self.stdout.write(message % created_threads)
예제 #37
0
    def handle(self, *args, **options):
        try:
            fake_threads_to_create = int(args[0])
        except IndexError:
            fake_threads_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        forums = [f for f in Forum.objects.all_forums().filter(role='forum')]

        fake = Factory.create()

        User = get_user_model()
        total_users = User.objects.count()

        self.stdout.write('Creating fake threads...\n')

        message = '\nSuccessfully created %s fake threads'

        created_threads = 0
        start_time = time.time()
        show_progress(self, created_threads, fake_threads_to_create)
        for i in xrange(fake_threads_to_create):
            with atomic():
                datetime = timezone.now()
                forum = random.choice(forums)
                user = User.objects.order_by('?')[:1][0]

                thread_is_moderated = random.randint(0, 100) > 90
                thread_is_hidden = random.randint(0, 100) > 90
                thread_is_closed = random.randint(0, 100) > 90

                thread = Thread(
                    forum=forum,
                    started_on=datetime,
                    starter_name='-',
                    starter_slug='-',
                    last_post_on=datetime,
                    last_poster_name='-',
                    last_poster_slug='-',
                    replies=random.randint(0, 2000),
                    is_moderated=thread_is_moderated,
                    is_hidden=thread_is_hidden,
                    is_closed=thread_is_closed)
                thread.set_title(fake.sentence())
                thread.save()

                fake_message = "\n\n".join(fake.paragraphs())
                post = Post.objects.create(
                    forum=forum,
                    thread=thread,
                    poster=user,
                    poster_name=user.username,
                    poster_ip=fake.ipv4(),
                    original=fake_message,
                    parsed=linebreaks_filter(fake_message),
                    posted_on=datetime,
                    updated_on=datetime)
                update_post_checksum(post)
                post.save(update_fields=['checksum'])

                thread.set_first_post(post)
                thread.set_last_post(post)
                thread.save()

                forum.threads += 1
                forum.posts += 1
                forum.set_last_thread(thread)
                forum.save()

                user.threads += 1
                user.posts += 1
                user.save()

                created_threads += 1
                show_progress(
                    self, created_threads, fake_threads_to_create, start_time)

        pinned_threads = random.randint(0, int(created_threads * 0.025)) or 1
        self.stdout.write('\nPinning %s threads...' % pinned_threads)
        for i in xrange(0, pinned_threads):
            thread = Thread.objects.order_by('?')[:1][0]
            thread.is_pinned = True
            thread.save()

        self.stdout.write(message % created_threads)
예제 #38
0
    def handle(self, *args, **options):
        items_to_create = options['threads']

        categories = list(Category.objects.all_categories())

        fake = Factory.create()

        User = get_user_model()
        total_users = User.objects.count()

        self.stdout.write('Creating fake threads...\n')

        message = '\nSuccessfully created %s fake threads in %s'

        created_threads = 0
        start_time = time.time()
        show_progress(self, created_threads, items_to_create)

        while created_threads < items_to_create:
            with atomic():
                datetime = timezone.now()
                category = random.choice(categories)
                user = User.objects.order_by('?')[:1][0]

                thread_is_unapproved = random.randint(0, 100) > 90
                thread_is_hidden = random.randint(0, 100) > 90
                thread_is_closed = random.randint(0, 100) > 90

                thread = Thread(
                    category=category,
                    started_on=datetime,
                    starter_name='-',
                    starter_slug='-',
                    last_post_on=datetime,
                    last_poster_name='-',
                    last_poster_slug='-',
                    replies=0,
                    is_unapproved=thread_is_unapproved,
                    is_hidden=thread_is_hidden,
                    is_closed=thread_is_closed
                )
                thread.set_title(fake.sentence())
                thread.save()

                fake_message = "\n\n".join(fake.paragraphs())
                post = Post.objects.create(
                    category=category,
                    thread=thread,
                    poster=user,
                    poster_name=user.username,
                    poster_ip=fake.ipv4(),
                    original=fake_message,
                    parsed=linebreaks_filter(fake_message),
                    posted_on=datetime,
                    updated_on=datetime
                )
                update_post_checksum(post)
                post.save(update_fields=['checksum'])

                thread.set_first_post(post)
                thread.set_last_post(post)
                thread.save()

                user.threads += 1
                user.posts += 1
                user.save()

                thread_type = random.randint(0, 100)
                if thread_type > 95:
                    thread_replies = random.randint(200, 2500)
                elif thread_type > 50:
                    thread_replies = random.randint(5, 30)
                else:
                    thread_replies = random.randint(0, 10)

                for x in range(thread_replies):
                    datetime = timezone.now()
                    user = User.objects.order_by('?')[:1][0]
                    fake_message = "\n\n".join(fake.paragraphs())

                    is_unapproved = random.randint(0, 100) > 97
                    if not is_unapproved:
                        is_hidden = random.randint(0, 100) > 97
                    else:
                        is_hidden = False

                    post = Post.objects.create(
                        category=category,
                        thread=thread,
                        poster=user,
                        poster_name=user.username,
                        poster_ip=fake.ipv4(),
                        original=fake_message,
                        parsed=linebreaks_filter(fake_message),
                        is_hidden=is_hidden,
                        is_unapproved=is_unapproved,
                        posted_on=datetime,
                        updated_on=datetime
                    )
                    update_post_checksum(post)
                    post.save(update_fields=['checksum'])

                    user.posts += 1
                    user.save()

                thread.synchronize()
                thread.save()

                created_threads += 1
                show_progress(
                    self, created_threads, items_to_create, start_time)

        pinned_threads = random.randint(0, int(created_threads * 0.025)) or 1
        self.stdout.write('\nPinning %s threads...' % pinned_threads)
        for i in range(0, pinned_threads):
            thread = Thread.objects.order_by('?')[:1][0]
            if random.randint(0, 100) > 75:
                thread.weight = 2
            else:
                thread.weight = 1
            thread.save()

        for category in categories:
            category.synchronize()
            category.save()

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (created_threads, total_humanized))
예제 #39
0
    def handle(self, *args, **options):
        try:
            fake_cats_to_create = int(args[0])
        except IndexError:
            fake_cats_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        categories = Category.objects.all_categories(True)

        try:
            min_level = int(args[1])
        except (IndexError):
            min_level = 0
        except ValueError:
            self.stderr.write("\nSecond optional argument should be integer.")
            sys.exit(1)

        copy_acl_from = list(Category.objects.all_categories())[0]

        categories = categories.filter(level__gte=min_level)
        fake = Factory.create()

        message = 'Creating %s fake categories...\n'
        self.stdout.write(message % fake_cats_to_create)

        message = '\n\nSuccessfully created %s fake categories in %s'

        created_count = 0
        start_time = time.time()
        show_progress(self, created_count, fake_cats_to_create)
        for i in range(fake_cats_to_create):
            parent = random.choice(categories)

            new_category = Category()
            if random.randint(1, 100) > 75:
                new_category.set_name(fake.catch_phrase().title())
            else:
                new_category.set_name(fake.street_name())

            if random.randint(1, 100) > 50:
                if random.randint(1, 100) > 80:
                    new_category.description = '\r\n'.join(fake.paragraphs())
                else:
                    new_category.description = fake.paragraph()

            new_category.insert_at(parent,
                position='last-child',
                save=True,
            )

            copied_acls = []
            for acl in copy_acl_from.category_role_set.all():
                copied_acls.append(RoleCategoryACL(
                    role_id=acl.role_id,
                    category=new_category,
                    category_role_id=acl.category_role_id,
                ))

            if copied_acls:
                RoleCategoryACL.objects.bulk_create(copied_acls)

            created_count += 1
            show_progress(
                self, created_count, fake_cats_to_create, start_time)

        acl_version.invalidate()

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (created_count, total_humanized))
예제 #40
0
    def handle(self, *args, **options):
        items_to_create = options['threads']

        categories = list(Category.objects.all_categories())

        fake = Factory.create()

        message = 'Creating %s fake threads...\n'
        self.stdout.write(message % items_to_create)

        created_threads = 0
        start_time = time.time()
        show_progress(self, created_threads, items_to_create)

        while created_threads < items_to_create:
            with atomic():
                datetime = timezone.now()
                category = random.choice(categories)
                user = UserModel.objects.order_by('?')[:1][0]

                thread_is_unapproved = random.randint(0, 100) > 90
                thread_is_hidden = random.randint(0, 100) > 90
                thread_is_closed = random.randint(0, 100) > 90

                thread = Thread(
                    category=category,
                    started_on=datetime,
                    starter_name='-',
                    starter_slug='-',
                    last_post_on=datetime,
                    last_poster_name='-',
                    last_poster_slug='-',
                    replies=0,
                    is_unapproved=thread_is_unapproved,
                    is_hidden=thread_is_hidden,
                    is_closed=thread_is_closed,
                )
                thread.set_title(corpus_short.random_choice())
                thread.save()

                original, parsed = self.fake_post_content()

                post = Post.objects.create(
                    category=category,
                    thread=thread,
                    poster=user,
                    poster_name=user.username,
                    original=original,
                    parsed=parsed,
                    posted_on=datetime,
                    updated_on=datetime,
                )
                update_post_checksum(post)
                post.save(update_fields=['checksum'])

                thread.set_first_post(post)
                thread.set_last_post(post)
                thread.save()

                user.threads += 1
                user.posts += 1
                user.save()

                thread_type = random.randint(0, 100)
                if thread_type > 98:
                    thread_replies = random.randint(200, 2500)
                elif thread_type > 50:
                    thread_replies = random.randint(5, 30)
                else:
                    thread_replies = random.randint(0, 10)

                for _ in range(thread_replies):
                    datetime = timezone.now()
                    user = UserModel.objects.order_by('?')[:1][0]

                    original, parsed = self.fake_post_content()

                    is_unapproved = random.randint(0, 100) > 97

                    post = Post.objects.create(
                        category=category,
                        thread=thread,
                        poster=user,
                        poster_name=user.username,
                        original=original,
                        parsed=parsed,
                        is_unapproved=is_unapproved,
                        posted_on=datetime,
                        updated_on=datetime,
                    )

                    if not is_unapproved:
                        is_hidden = random.randint(0, 100) > 97
                    else:
                        is_hidden = False

                    if is_hidden:
                        post.is_hidden = True

                        if random.randint(0, 100) < 80:
                            user = UserModel.objects.order_by('?')[:1][0]
                            post.hidden_by = user
                            post.hidden_by_name = user.username
                            post.hidden_by_slug = user.username
                        else:
                            post.hidden_by_name = fake.first_name()
                            post.hidden_by_slug = post.hidden_by_name.lower()

                    update_post_checksum(post)
                    post.save()

                    user.posts += 1
                    user.save()

                thread.synchronize()
                thread.save()

                created_threads += 1
                show_progress(self, created_threads, items_to_create, start_time)

        pinned_threads = random.randint(0, int(created_threads * 0.025)) or 1
        self.stdout.write('\nPinning %s threads...' % pinned_threads)
        
        for _ in range(0, pinned_threads):
            thread = Thread.objects.order_by('?')[:1][0]
            if random.randint(0, 100) > 75:
                thread.weight = 2
            else:
                thread.weight = 1
            thread.save()

        for category in categories:
            category.synchronize()
            category.save()

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        message = '\nSuccessfully created %s fake threads in %s'
        self.stdout.write(message % (created_threads, total_humanized))