feat: Implement initial schema and add various API, service, and management command enhancements across the application.

This commit is contained in:
pacnpal
2026-01-01 15:13:01 -05:00
parent c95f99ca10
commit b243b17af7
413 changed files with 11164 additions and 17433 deletions

View File

@@ -27,9 +27,7 @@ class Command(BaseCommand):
self.create_park_areas()
self.create_reviews()
self.stdout.write(
self.style.SUCCESS("Successfully created comprehensive sample data!")
)
self.stdout.write(self.style.SUCCESS("Successfully created comprehensive sample data!"))
self.print_summary()
except Exception as e:
@@ -101,13 +99,9 @@ class Command(BaseCommand):
]
for company_data in park_operators_data:
company, created = ParkCompany.objects.get_or_create(
slug=company_data["slug"], defaults=company_data
)
company, created = ParkCompany.objects.get_or_create(slug=company_data["slug"], defaults=company_data)
self.created_companies[company.slug] = company
self.stdout.write(
f" {'Created' if created else 'Found'} park company: {company.name}"
)
self.stdout.write(f" {'Created' if created else 'Found'} park company: {company.name}")
# Ride manufacturers and designers (using rides.models.Company)
ride_companies_data = [
@@ -194,13 +188,9 @@ class Command(BaseCommand):
]
for company_data in ride_companies_data:
company, created = RideCompany.objects.get_or_create(
slug=company_data["slug"], defaults=company_data
)
company, created = RideCompany.objects.get_or_create(slug=company_data["slug"], defaults=company_data)
self.created_companies[company.slug] = company
self.stdout.write(
f" {'Created' if created else 'Found'} ride company: {company.name}"
)
self.stdout.write(f" {'Created' if created else 'Found'} ride company: {company.name}")
def create_parks(self):
"""Create parks with proper operator relationships."""

View File

@@ -31,6 +31,4 @@ class Command(BaseCommand):
"""
)
self.stdout.write(
self.style.SUCCESS("Successfully fixed migration history")
)
self.stdout.write(self.style.SUCCESS("Successfully fixed migration history"))

View File

@@ -50,13 +50,9 @@ class Command(BaseCommand):
companies = {}
for company_data in companies_data:
operator, created = Operator.objects.get_or_create(
name=company_data["name"], defaults=company_data
)
operator, created = Operator.objects.get_or_create(name=company_data["name"], defaults=company_data)
companies[operator.name] = operator
self.stdout.write(
f"{'Created' if created else 'Found'} company: {operator.name}"
)
self.stdout.write(f"{'Created' if created else 'Found'} company: {operator.name}")
# Create parks with their locations
parks_data = [
@@ -317,9 +313,7 @@ class Command(BaseCommand):
postal_code=loc_data["postal_code"],
)
# Set coordinates using the helper method
park_location.set_coordinates(
loc_data["latitude"], loc_data["longitude"]
)
park_location.set_coordinates(loc_data["latitude"], loc_data["longitude"])
park_location.save()
# Create areas for park
@@ -329,8 +323,6 @@ class Command(BaseCommand):
park=park,
defaults={"description": area_data["description"]},
)
self.stdout.write(
f"{'Created' if created else 'Found'} area: {area.name} in {park.name}"
)
self.stdout.write(f"{'Created' if created else 'Found'} area: {area.name} in {park.name}")
self.stdout.write(self.style.SUCCESS("Successfully seeded initial park data"))

View File

@@ -43,19 +43,13 @@ class Command(BaseCommand):
# Log what will be deleted
self.stdout.write(f" Found {park_review_count} park reviews to delete")
self.stdout.write(f" Found {ride_review_count} ride reviews to delete")
self.stdout.write(
f" Found {rollercoaster_stats_count} roller coaster stats to delete"
)
self.stdout.write(f" Found {rollercoaster_stats_count} roller coaster stats to delete")
self.stdout.write(f" Found {ride_count} rides to delete")
self.stdout.write(f" Found {ride_model_count} ride models to delete")
self.stdout.write(f" Found {park_area_count} park areas to delete")
self.stdout.write(
f" Found {park_location_count} park locations to delete"
)
self.stdout.write(f" Found {park_location_count} park locations to delete")
self.stdout.write(f" Found {park_count} parks to delete")
self.stdout.write(
f" Found {ride_company_count} ride companies to delete"
)
self.stdout.write(f" Found {ride_company_count} ride companies to delete")
self.stdout.write(f" Found {company_count} park companies to delete")
self.stdout.write(f" Found {test_user_count} test users to delete")
@@ -72,9 +66,7 @@ class Command(BaseCommand):
# Roller coaster stats (references Ride)
if rollercoaster_stats_count > 0:
RollerCoasterStats.objects.all().delete()
self.stdout.write(
f" Deleted {rollercoaster_stats_count} roller coaster stats"
)
self.stdout.write(f" Deleted {rollercoaster_stats_count} roller coaster stats")
# Rides (references Park, RideCompany, RideModel)
if ride_count > 0:
@@ -116,18 +108,14 @@ class Command(BaseCommand):
User.objects.filter(username="testuser").delete()
self.stdout.write(f" Deleted {test_user_count} test users")
self.stdout.write(
self.style.SUCCESS("Successfully cleaned up existing sample data!")
)
self.stdout.write(self.style.SUCCESS("Successfully cleaned up existing sample data!"))
except Exception as e:
self.logger.error(
f"Error during data cleanup: {str(e)}",
exc_info=True,
)
self.stdout.write(
self.style.ERROR(f"Failed to clean up existing data: {str(e)}")
)
self.stdout.write(self.style.ERROR(f"Failed to clean up existing data: {str(e)}"))
raise
def handle(self, *args, **options):
@@ -137,9 +125,7 @@ class Command(BaseCommand):
# Check if required tables exist
if not self.check_required_tables():
self.stdout.write(
self.style.ERROR(
"Required database tables are missing. Please run migrations first."
)
self.style.ERROR("Required database tables are missing. Please run migrations first.")
)
return
@@ -163,17 +149,11 @@ class Command(BaseCommand):
# Add sample reviews for testing
self.create_reviews()
self.stdout.write(
self.style.SUCCESS("Successfully created comprehensive sample data!")
)
self.stdout.write(self.style.SUCCESS("Successfully created comprehensive sample data!"))
except Exception as e:
self.logger.error(
f"Error during sample data creation: {str(e)}", exc_info=True
)
self.stdout.write(
self.style.ERROR(f"Failed to create sample data: {str(e)}")
)
self.logger.error(f"Error during sample data creation: {str(e)}", exc_info=True)
self.stdout.write(self.style.ERROR(f"Failed to create sample data: {str(e)}"))
raise
def check_required_tables(self):
@@ -202,11 +182,7 @@ class Command(BaseCommand):
missing_tables.append(model._meta.label)
if missing_tables:
self.stdout.write(
self.style.WARNING(
f"Missing tables for models: {', '.join(missing_tables)}"
)
)
self.stdout.write(self.style.WARNING(f"Missing tables for models: {', '.join(missing_tables)}"))
return False
self.stdout.write(self.style.SUCCESS("All required tables exist."))
@@ -357,9 +333,7 @@ class Command(BaseCommand):
}"
)
except Exception as e:
self.logger.error(
f"Error creating park company {data['name']}: {str(e)}"
)
self.logger.error(f"Error creating park company {data['name']}: {str(e)}")
raise
# Create companies in rides app (for manufacturers and designers)
@@ -382,9 +356,7 @@ class Command(BaseCommand):
}"
)
except Exception as e:
self.logger.error(
f"Error creating ride company {data['name']}: {str(e)}"
)
self.logger.error(f"Error creating ride company {data['name']}: {str(e)}")
raise
except Exception as e:
@@ -512,9 +484,7 @@ class Command(BaseCommand):
try:
operator = self.park_companies[park_data["operator"]]
property_owner = (
self.park_companies.get(park_data["property_owner"])
if park_data["property_owner"]
else None
self.park_companies.get(park_data["property_owner"]) if park_data["property_owner"] else None
)
park, created = Park.objects.get_or_create(
@@ -530,9 +500,7 @@ class Command(BaseCommand):
},
)
self.parks[park_data["name"]] = park
self.stdout.write(
f" {'Created' if created else 'Found'} park: {park.name}"
)
self.stdout.write(f" {'Created' if created else 'Found'} park: {park.name}")
# Create location for park
if created:
@@ -547,9 +515,7 @@ class Command(BaseCommand):
postal_code=loc_data["postal_code"],
)
# Set coordinates using the helper method
park_location.set_coordinates(
loc_data["latitude"], loc_data["longitude"]
)
park_location.set_coordinates(loc_data["latitude"], loc_data["longitude"])
park_location.save()
except Exception as e:
self.logger.error(
@@ -560,9 +526,7 @@ class Command(BaseCommand):
raise
except Exception as e:
self.logger.error(
f"Error creating park {park_data['name']}: {str(e)}"
)
self.logger.error(f"Error creating park {park_data['name']}: {str(e)}")
raise
except Exception as e:
@@ -633,9 +597,7 @@ class Command(BaseCommand):
}"
)
except Exception as e:
self.logger.error(
f"Error creating ride model {model_data['name']}: {str(e)}"
)
self.logger.error(f"Error creating ride model {model_data['name']}: {str(e)}")
raise
# Create rides
@@ -834,9 +796,7 @@ class Command(BaseCommand):
for ride_data in rides_data:
try:
park = self.parks[ride_data["park"]]
manufacturer = self.ride_companies.get(
ride_data.get("manufacturer")
)
manufacturer = self.ride_companies.get(ride_data.get("manufacturer"))
designer = self.ride_companies.get(ride_data.get("designer"))
ride_model = self.ride_models.get(ride_data.get("ride_model"))
@@ -854,9 +814,7 @@ class Command(BaseCommand):
},
)
self.rides[ride_data["name"]] = ride
self.stdout.write(
f" {'Created' if created else 'Found'} ride: {ride.name}"
)
self.stdout.write(f" {'Created' if created else 'Found'} ride: {ride.name}")
# Create roller coaster stats if provided
if created and "coaster_stats" in ride_data:
@@ -872,9 +830,7 @@ class Command(BaseCommand):
raise
except Exception as e:
self.logger.error(
f"Error creating ride {ride_data['name']}: {str(e)}"
)
self.logger.error(f"Error creating ride {ride_data['name']}: {str(e)}")
raise
except Exception as e:
@@ -1011,9 +967,7 @@ class Command(BaseCommand):
} in {park.name}"
)
except Exception as e:
self.logger.error(
f"Error creating areas for park {area_group['park']}: {str(e)}"
)
self.logger.error(f"Error creating areas for park {area_group['park']}: {str(e)}")
raise
except Exception as e:

View File

@@ -85,9 +85,7 @@ class Command(BaseCommand):
"country": "USA",
},
)
location2.set_coordinates(
34.4244, -118.5971
) # Six Flags Magic Mountain coordinates
location2.set_coordinates(34.4244, -118.5971) # Six Flags Magic Mountain coordinates
location2.save()
# Test distance calculation
@@ -107,9 +105,7 @@ class Command(BaseCommand):
# Find parks within 100km of a point
# Same as Disneyland
search_point = Point(-117.9190, 33.8121, srid=4326)
nearby_locations = ParkLocation.objects.filter(
point__distance_lte=(search_point, D(km=100))
)
nearby_locations = ParkLocation.objects.filter(point__distance_lte=(search_point, D(km=100)))
self.stdout.write(f" Found {nearby_locations.count()} parks within 100km")
for loc in nearby_locations:
self.stdout.write(f" - {loc.park.name} in {loc.city}, {loc.state}")

View File

@@ -20,11 +20,7 @@ class Command(BaseCommand):
total_coasters = park.rides.filter(operating_rides, category="RC").count()
# Update park counts
Park.objects.filter(id=park.id).update(
total_rides=total_rides, total_roller_coasters=total_coasters
)
Park.objects.filter(id=park.id).update(total_rides=total_rides, total_roller_coasters=total_coasters)
updated += 1
self.stdout.write(
self.style.SUCCESS(f"Successfully updated counts for {updated} parks")
)
self.stdout.write(self.style.SUCCESS(f"Successfully updated counts for {updated} parks"))