This commit is contained in:
pacnpal
2024-10-29 01:09:14 -04:00
parent 74a1b730b9
commit 158f25b24b
195 changed files with 5000 additions and 1213 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -8,7 +8,7 @@ class ParkAdmin(SimpleHistoryAdmin):
list_filter = ('status', 'owner')
search_fields = ('name', 'location', 'description')
prepopulated_fields = {'slug': ('name',)}
readonly_fields = ('created_at', 'updated_at')
readonly_fields = ('id', 'created_at', 'updated_at')
@admin.register(ParkArea)
class ParkAreaAdmin(SimpleHistoryAdmin):
@@ -16,4 +16,4 @@ class ParkAreaAdmin(SimpleHistoryAdmin):
list_filter = ('park',)
search_fields = ('name', 'description')
prepopulated_fields = {'slug': ('name',)}
readonly_fields = ('created_at', 'updated_at')
readonly_fields = ('id', 'created_at', 'updated_at')

View File

@@ -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):

View File

@@ -0,0 +1,25 @@
# Generated manually
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('parks', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='park',
name='country',
field=models.CharField(max_length=2, default='US', help_text='Two-letter country code (ISO 3166-1 alpha-2)'),
preserve_default=False,
),
migrations.AddField(
model_name='historicalpark',
name='country',
field=models.CharField(max_length=2, default='US', help_text='Two-letter country code (ISO 3166-1 alpha-2)'),
preserve_default=False,
),
]

Binary file not shown.

View File

@@ -2,6 +2,7 @@ from django.db import models
from django.contrib.contenttypes.fields import GenericRelation
from django.utils.text import slugify
from simple_history.models import HistoricalRecords
import pycountry
class Park(models.Model):
STATUS_CHOICES = [
@@ -15,6 +16,7 @@ class Park(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique=True)
location = models.CharField(max_length=255)
country = models.CharField(max_length=2, help_text='Two-letter country code (ISO 3166-1 alpha-2)')
description = models.TextField(blank=True)
owner = models.ForeignKey(
'companies.Company',
@@ -73,6 +75,14 @@ class Park(models.Model):
return cls.objects.get(id=history.id), True
raise cls.DoesNotExist("No park found with this slug")
def get_country_name(self):
"""Get the full country name from the country code"""
try:
country = pycountry.countries.get(alpha_2=self.country)
return country.name if country else self.country
except:
return self.country
class ParkArea(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255)

View File

@@ -1,5 +1,7 @@
from django.views.generic import DetailView, ListView
from django.shortcuts import get_object_or_404
from django.core.serializers.json import DjangoJSONEncoder
from django.urls import reverse
from .models import Park, ParkArea
from rides.models import Ride
from core.views import SlugRedirectMixin
@@ -64,28 +66,43 @@ class ParkListView(ListView):
model = Park
template_name = 'parks/park_list.html'
context_object_name = 'parks'
paginate_by = 12
def get_queryset(self):
queryset = Park.objects.select_related('owner')
queryset = Park.objects.select_related('owner').prefetch_related('photos', 'rides')
# Filter by location if specified
location = self.request.GET.get('location')
# Apply filters
search = self.request.GET.get('search', '').strip()
location = self.request.GET.get('location', '').strip()
status = self.request.GET.get('status', '').strip()
if search:
queryset = queryset.filter(name__icontains=search) | queryset.filter(location__icontains=search)
if location:
queryset = queryset.filter(location__icontains=location)
# Filter by status if specified
status = self.request.GET.get('status')
queryset = queryset.filter(location=location)
if status:
queryset = queryset.filter(status=status)
return queryset.order_by('name')
return queryset
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# Add list of locations for the filter dropdown
context['locations'] = Park.objects.values_list(
'location', flat=True
).distinct().order_by('location')
context['selected_location'] = self.request.GET.get('location', '')
# Get unique locations for filter dropdown
context['locations'] = list(Park.objects.values_list('location', flat=True)
.distinct().order_by('location'))
# Add current filter values to context
context['current_filters'] = {
'search': self.request.GET.get('search', ''),
'location': self.request.GET.get('location', ''),
'status': self.request.GET.get('status', '')
}
return context
def get(self, request, *args, **kwargs):
# Check if this is an HTMX request
if request.htmx:
# If it is, return just the parks list partial
self.template_name = 'parks/partials/park_list.html'
return super().get(request, *args, **kwargs)