mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 16:11:08 -05:00
yay
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import os
|
||||
import json
|
||||
import random
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.hashers import make_password
|
||||
from django.core.files import File
|
||||
from django.utils.text import slugify
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import connection
|
||||
from faker import Faker
|
||||
import requests
|
||||
from io import BytesIO
|
||||
@@ -42,70 +44,68 @@ class Command(BaseCommand):
|
||||
def create_users(self, count):
|
||||
self.stdout.write('Creating users...')
|
||||
users = []
|
||||
|
||||
# Get existing admin user
|
||||
admin_user = User.objects.get(username='admin')
|
||||
users.append(admin_user)
|
||||
self.stdout.write('Added existing admin user')
|
||||
|
||||
# Create regular users using raw SQL
|
||||
roles = ['USER'] * 20 + ['MODERATOR'] * 3 + ['ADMIN'] * 2
|
||||
|
||||
# Create or get superuser
|
||||
try:
|
||||
superuser = User.objects.get(username='admin')
|
||||
self.stdout.write('Superuser already exists')
|
||||
except User.DoesNotExist:
|
||||
superuser = User.objects.create_superuser(
|
||||
username='admin',
|
||||
email='admin@thrillwiki.com',
|
||||
password='admin',
|
||||
role='SUPERUSER'
|
||||
)
|
||||
UserProfile.objects.create(
|
||||
user=superuser,
|
||||
display_name='Admin',
|
||||
pronouns='they/them',
|
||||
bio='ThrillWiki Administrator'
|
||||
)
|
||||
self.stdout.write('Created superuser')
|
||||
|
||||
users.append(superuser)
|
||||
|
||||
# Delete existing non-superuser users if any
|
||||
User.objects.exclude(username='admin').delete()
|
||||
self.stdout.write('Deleted existing users')
|
||||
|
||||
for _ in range(count):
|
||||
username = fake.user_name()
|
||||
while User.objects.filter(username=username).exists():
|
||||
with connection.cursor() as cursor:
|
||||
for _ in range(count):
|
||||
# Create user
|
||||
username = fake.user_name()
|
||||
|
||||
user = User.objects.create_user(
|
||||
username=username,
|
||||
email=fake.email(),
|
||||
password='password123',
|
||||
role=random.choice(roles)
|
||||
)
|
||||
|
||||
# Create user profile
|
||||
profile = UserProfile.objects.create(
|
||||
user=user,
|
||||
display_name=fake.name(),
|
||||
pronouns=random.choice(['he/him', 'she/her', 'they/them', '']),
|
||||
bio=fake.text(max_nb_chars=200),
|
||||
twitter=fake.url() if random.choice([True, False]) else '',
|
||||
instagram=fake.url() if random.choice([True, False]) else '',
|
||||
youtube=fake.url() if random.choice([True, False]) else '',
|
||||
discord=fake.user_name() if random.choice([True, False]) else '',
|
||||
coaster_credits=random.randint(0, 500),
|
||||
dark_ride_credits=random.randint(0, 200),
|
||||
flat_ride_credits=random.randint(0, 300),
|
||||
water_ride_credits=random.randint(0, 100)
|
||||
)
|
||||
|
||||
# Add avatar
|
||||
img_url = f'https://picsum.photos/200/200?random={fake.random_number(5)}'
|
||||
filename, file = self.download_and_save_image(img_url, 'avatar')
|
||||
if filename and file:
|
||||
profile.avatar.save(filename, file, save=True)
|
||||
|
||||
users.append(user)
|
||||
self.stdout.write(f'Created user: {username}')
|
||||
|
||||
while User.objects.filter(username=username).exists():
|
||||
username = fake.user_name()
|
||||
|
||||
user_id = str(uuid.uuid4())[:10]
|
||||
cursor.execute("""
|
||||
INSERT INTO accounts_user (
|
||||
username, password, email, is_superuser, is_staff,
|
||||
is_active, date_joined, user_id, first_name,
|
||||
last_name, role, is_banned, ban_reason,
|
||||
theme_preference
|
||||
) VALUES (
|
||||
%s, %s, %s, false, false,
|
||||
true, NOW(), %s, '', '',
|
||||
%s, false, '', 'light'
|
||||
) RETURNING id;
|
||||
""", [username, make_password('password123'), fake.email(), user_id, random.choice(roles)])
|
||||
|
||||
user_db_id = cursor.fetchone()[0]
|
||||
|
||||
# Create profile
|
||||
profile_id = str(uuid.uuid4())[:10]
|
||||
display_name = f"{fake.first_name()}_{fake.last_name()}_{fake.random_number(digits=4)}"
|
||||
cursor.execute("""
|
||||
INSERT INTO accounts_userprofile (
|
||||
profile_id, display_name, pronouns, bio,
|
||||
twitter, instagram, youtube, discord,
|
||||
coaster_credits, dark_ride_credits,
|
||||
flat_ride_credits, water_ride_credits,
|
||||
user_id, avatar
|
||||
) VALUES (
|
||||
%s, %s, %s, %s,
|
||||
%s, %s, %s, %s,
|
||||
%s, %s, %s, %s,
|
||||
%s, ''
|
||||
);
|
||||
""", [
|
||||
profile_id, display_name, random.choice(['he/him', 'she/her', 'they/them', '']),
|
||||
fake.text(max_nb_chars=200),
|
||||
fake.url() if random.choice([True, False]) else '',
|
||||
fake.url() if random.choice([True, False]) else '',
|
||||
fake.url() if random.choice([True, False]) else '',
|
||||
fake.user_name() if random.choice([True, False]) else '',
|
||||
random.randint(0, 500), random.randint(0, 200),
|
||||
random.randint(0, 300), random.randint(0, 100),
|
||||
user_db_id
|
||||
])
|
||||
|
||||
users.append(User.objects.get(id=user_db_id))
|
||||
self.stdout.write(f'Created user: {username}')
|
||||
|
||||
return users
|
||||
|
||||
def create_companies(self):
|
||||
|
||||
Reference in New Issue
Block a user