mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-22 22:31:09 -05:00
Refactor test utilities and enhance ASGI settings
- Cleaned up and standardized assertions in ApiTestMixin for API response validation. - Updated ASGI settings to use os.environ for setting the DJANGO_SETTINGS_MODULE. - Removed unused imports and improved formatting in settings.py. - Refactored URL patterns in urls.py for better readability and organization. - Enhanced view functions in views.py for consistency and clarity. - Added .flake8 configuration for linting and style enforcement. - Introduced type stubs for django-environ to improve type checking with Pylance.
This commit is contained in:
@@ -1,19 +1,15 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils import timezone
|
||||
from django.db import transaction
|
||||
from datetime import date, timedelta
|
||||
import random
|
||||
from decimal import Decimal
|
||||
|
||||
# Import models from both apps
|
||||
from parks.models import Company as ParkCompany, Park, ParkArea, ParkReview
|
||||
from parks.models.location import ParkLocation
|
||||
from rides.models import Company as RideCompany, Ride, RideModel, RideReview, RollerCoasterStats
|
||||
from accounts.models import User
|
||||
from parks.models import Company as ParkCompany
|
||||
from rides.models import (
|
||||
Company as RideCompany,
|
||||
)
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Creates comprehensive sample data for the ThrillWiki theme park application'
|
||||
help = "Creates comprehensive sample data for the ThrillWiki theme park application"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -22,7 +18,7 @@ class Command(BaseCommand):
|
||||
self.created_rides = {}
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.stdout.write('Starting sample data creation...')
|
||||
self.stdout.write("Starting sample data creation...")
|
||||
|
||||
try:
|
||||
with transaction.atomic():
|
||||
@@ -33,285 +29,294 @@ 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:
|
||||
self.stdout.write(self.style.ERROR(f'Error creating sample data: {e}'))
|
||||
self.stdout.write(self.style.ERROR(f"Error creating sample data: {e}"))
|
||||
raise
|
||||
|
||||
def create_companies(self):
|
||||
"""Create companies with different roles following entity relationship rules"""
|
||||
self.stdout.write('Creating companies...')
|
||||
self.stdout.write("Creating companies...")
|
||||
|
||||
# Park operators and property owners (using parks.models.Company)
|
||||
park_operators_data = [
|
||||
{
|
||||
'name': 'The Walt Disney Company',
|
||||
'slug': 'walt-disney-company',
|
||||
'roles': ['OPERATOR', 'PROPERTY_OWNER'],
|
||||
'description': 'World\'s largest entertainment company and theme park operator.',
|
||||
'website': 'https://www.disney.com/',
|
||||
'founded_year': 1923,
|
||||
"name": "The Walt Disney Company",
|
||||
"slug": "walt-disney-company",
|
||||
"roles": ["OPERATOR", "PROPERTY_OWNER"],
|
||||
"description": "World's largest entertainment company and theme park operator.",
|
||||
"website": "https://www.disney.com/",
|
||||
"founded_year": 1923,
|
||||
},
|
||||
{
|
||||
'name': 'Universal Parks & Resorts',
|
||||
'slug': 'universal-parks-resorts',
|
||||
'roles': ['OPERATOR', 'PROPERTY_OWNER'],
|
||||
'description': 'Division of Comcast NBCUniversal, operating major theme parks worldwide.',
|
||||
'website': 'https://www.universalparks.com/',
|
||||
'founded_year': 1964,
|
||||
"name": "Universal Parks & Resorts",
|
||||
"slug": "universal-parks-resorts",
|
||||
"roles": ["OPERATOR", "PROPERTY_OWNER"],
|
||||
"description": "Division of Comcast NBCUniversal, operating major theme parks worldwide.",
|
||||
"website": "https://www.universalparks.com/",
|
||||
"founded_year": 1964,
|
||||
},
|
||||
{
|
||||
'name': 'Six Flags Entertainment Corporation',
|
||||
'slug': 'six-flags-entertainment',
|
||||
'roles': ['OPERATOR', 'PROPERTY_OWNER'],
|
||||
'description': 'World\'s largest regional theme park company.',
|
||||
'website': 'https://www.sixflags.com/',
|
||||
'founded_year': 1961,
|
||||
"name": "Six Flags Entertainment Corporation",
|
||||
"slug": "six-flags-entertainment",
|
||||
"roles": ["OPERATOR", "PROPERTY_OWNER"],
|
||||
"description": "World's largest regional theme park company.",
|
||||
"website": "https://www.sixflags.com/",
|
||||
"founded_year": 1961,
|
||||
},
|
||||
{
|
||||
'name': 'Cedar Fair Entertainment Company',
|
||||
'slug': 'cedar-fair-entertainment',
|
||||
'roles': ['OPERATOR', 'PROPERTY_OWNER'],
|
||||
'description': 'One of North America\'s largest operators of regional amusement parks.',
|
||||
'website': 'https://www.cedarfair.com/',
|
||||
'founded_year': 1983,
|
||||
"name": "Cedar Fair Entertainment Company",
|
||||
"slug": "cedar-fair-entertainment",
|
||||
"roles": ["OPERATOR", "PROPERTY_OWNER"],
|
||||
"description": "One of North America's largest operators of regional amusement parks.",
|
||||
"website": "https://www.cedarfair.com/",
|
||||
"founded_year": 1983,
|
||||
},
|
||||
{
|
||||
'name': 'Herschend Family Entertainment',
|
||||
'slug': 'herschend-family-entertainment',
|
||||
'roles': ['OPERATOR', 'PROPERTY_OWNER'],
|
||||
'description': 'Largest family-owned themed attractions corporation in the United States.',
|
||||
'website': 'https://www.hfecorp.com/',
|
||||
'founded_year': 1950,
|
||||
"name": "Herschend Family Entertainment",
|
||||
"slug": "herschend-family-entertainment",
|
||||
"roles": ["OPERATOR", "PROPERTY_OWNER"],
|
||||
"description": "Largest family-owned themed attractions corporation in the United States.",
|
||||
"website": "https://www.hfecorp.com/",
|
||||
"founded_year": 1950,
|
||||
},
|
||||
{
|
||||
'name': 'SeaWorld Parks & Entertainment',
|
||||
'slug': 'seaworld-parks-entertainment',
|
||||
'roles': ['OPERATOR', 'PROPERTY_OWNER'],
|
||||
'description': 'Theme park and entertainment company focusing on nature-based themes.',
|
||||
'website': 'https://www.seaworldentertainment.com/',
|
||||
'founded_year': 1959,
|
||||
"name": "SeaWorld Parks & Entertainment",
|
||||
"slug": "seaworld-parks-entertainment",
|
||||
"roles": ["OPERATOR", "PROPERTY_OWNER"],
|
||||
"description": "Theme park and entertainment company focusing on nature-based themes.",
|
||||
"website": "https://www.seaworldentertainment.com/",
|
||||
"founded_year": 1959,
|
||||
},
|
||||
{
|
||||
'name': 'Merlin Entertainments',
|
||||
'slug': 'merlin-entertainments',
|
||||
'roles': ['OPERATOR', 'PROPERTY_OWNER'],
|
||||
'description': 'European theme park operator with LEGOLAND and Madame Tussauds brands.',
|
||||
'website': 'https://www.merlinentertainments.com/',
|
||||
'founded_year': 1998,
|
||||
"name": "Merlin Entertainments",
|
||||
"slug": "merlin-entertainments",
|
||||
"roles": ["OPERATOR", "PROPERTY_OWNER"],
|
||||
"description": "European theme park operator with LEGOLAND and Madame Tussauds brands.",
|
||||
"website": "https://www.merlinentertainments.com/",
|
||||
"founded_year": 1998,
|
||||
},
|
||||
]
|
||||
|
||||
for company_data in park_operators_data:
|
||||
company, created = ParkCompany.objects.get_or_create(
|
||||
slug=company_data['slug'],
|
||||
defaults=company_data
|
||||
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 = [
|
||||
{
|
||||
'name': 'Bolliger & Mabillard',
|
||||
'slug': 'bolliger-mabillard',
|
||||
'roles': ['MANUFACTURER', 'DESIGNER'],
|
||||
'description': 'Swiss roller coaster manufacturer known for inverted and diving coasters.',
|
||||
'website': 'https://www.bolliger-mabillard.com/',
|
||||
'founded_date': '1988-01-01',
|
||||
"name": "Bolliger & Mabillard",
|
||||
"slug": "bolliger-mabillard",
|
||||
"roles": ["MANUFACTURER", "DESIGNER"],
|
||||
"description": "Swiss roller coaster manufacturer known for inverted and diving coasters.",
|
||||
"website": "https://www.bolliger-mabillard.com/",
|
||||
"founded_date": "1988-01-01",
|
||||
},
|
||||
{
|
||||
'name': 'Intamin Amusement Rides',
|
||||
'slug': 'intamin-amusement-rides',
|
||||
'roles': ['MANUFACTURER', 'DESIGNER'],
|
||||
'description': 'Liechtenstein-based manufacturer of roller coasters and thrill rides.',
|
||||
'website': 'https://www.intamin.com/',
|
||||
'founded_date': '1967-01-01',
|
||||
"name": "Intamin Amusement Rides",
|
||||
"slug": "intamin-amusement-rides",
|
||||
"roles": ["MANUFACTURER", "DESIGNER"],
|
||||
"description": "Liechtenstein-based manufacturer of roller coasters and thrill rides.",
|
||||
"website": "https://www.intamin.com/",
|
||||
"founded_date": "1967-01-01",
|
||||
},
|
||||
{
|
||||
'name': 'Arrow Dynamics',
|
||||
'slug': 'arrow-dynamics',
|
||||
'roles': ['MANUFACTURER', 'DESIGNER'],
|
||||
'description': 'American manufacturer known for corkscrew coasters and mine trains.',
|
||||
'website': 'https://en.wikipedia.org/wiki/Arrow_Dynamics',
|
||||
'founded_date': '1946-01-01',
|
||||
"name": "Arrow Dynamics",
|
||||
"slug": "arrow-dynamics",
|
||||
"roles": ["MANUFACTURER", "DESIGNER"],
|
||||
"description": "American manufacturer known for corkscrew coasters and mine trains.",
|
||||
"website": "https://en.wikipedia.org/wiki/Arrow_Dynamics",
|
||||
"founded_date": "1946-01-01",
|
||||
},
|
||||
{
|
||||
'name': 'Vekoma Rides Manufacturing',
|
||||
'slug': 'vekoma-rides-manufacturing',
|
||||
'roles': ['MANUFACTURER', 'DESIGNER'],
|
||||
'description': 'Dutch manufacturer of roller coasters and family rides.',
|
||||
'website': 'https://www.vekoma.com/',
|
||||
'founded_date': '1926-01-01',
|
||||
"name": "Vekoma Rides Manufacturing",
|
||||
"slug": "vekoma-rides-manufacturing",
|
||||
"roles": ["MANUFACTURER", "DESIGNER"],
|
||||
"description": "Dutch manufacturer of roller coasters and family rides.",
|
||||
"website": "https://www.vekoma.com/",
|
||||
"founded_date": "1926-01-01",
|
||||
},
|
||||
{
|
||||
'name': 'Rocky Mountain Construction',
|
||||
'slug': 'rocky-mountain-construction',
|
||||
'roles': ['MANUFACTURER', 'DESIGNER'],
|
||||
'description': 'American manufacturer specializing in I-Box track and Raptor track coasters.',
|
||||
'website': 'https://www.rockymtnconstruction.com/',
|
||||
'founded_date': '2001-01-01',
|
||||
"name": "Rocky Mountain Construction",
|
||||
"slug": "rocky-mountain-construction",
|
||||
"roles": ["MANUFACTURER", "DESIGNER"],
|
||||
"description": "American manufacturer specializing in I-Box track and Raptor track coasters.",
|
||||
"website": "https://www.rockymtnconstruction.com/",
|
||||
"founded_date": "2001-01-01",
|
||||
},
|
||||
{
|
||||
'name': 'Mack Rides',
|
||||
'slug': 'mack-rides',
|
||||
'roles': ['MANUFACTURER', 'DESIGNER'],
|
||||
'description': 'German manufacturer known for water rides and powered coasters.',
|
||||
'website': 'https://www.mack-rides.com/',
|
||||
'founded_date': '1780-01-01',
|
||||
"name": "Mack Rides",
|
||||
"slug": "mack-rides",
|
||||
"roles": ["MANUFACTURER", "DESIGNER"],
|
||||
"description": "German manufacturer known for water rides and powered coasters.",
|
||||
"website": "https://www.mack-rides.com/",
|
||||
"founded_date": "1780-01-01",
|
||||
},
|
||||
{
|
||||
'name': 'Chance Rides',
|
||||
'slug': 'chance-rides',
|
||||
'roles': ['MANUFACTURER'],
|
||||
'description': 'American manufacturer of thrill rides and amusement park equipment.',
|
||||
'website': 'https://www.chancerides.com/',
|
||||
'founded_date': '1961-01-01',
|
||||
"name": "Chance Rides",
|
||||
"slug": "chance-rides",
|
||||
"roles": ["MANUFACTURER"],
|
||||
"description": "American manufacturer of thrill rides and amusement park equipment.",
|
||||
"website": "https://www.chancerides.com/",
|
||||
"founded_date": "1961-01-01",
|
||||
},
|
||||
{
|
||||
'name': 'S&S Worldwide',
|
||||
'slug': 's-s-worldwide',
|
||||
'roles': ['MANUFACTURER', 'DESIGNER'],
|
||||
'description': 'American manufacturer known for drop towers and 4D free-fly coasters.',
|
||||
'website': 'https://www.s-s.com/',
|
||||
'founded_date': '1990-01-01',
|
||||
"name": "S&S Worldwide",
|
||||
"slug": "s-s-worldwide",
|
||||
"roles": ["MANUFACTURER", "DESIGNER"],
|
||||
"description": "American manufacturer known for drop towers and 4D free-fly coasters.",
|
||||
"website": "https://www.s-s.com/",
|
||||
"founded_date": "1990-01-01",
|
||||
},
|
||||
{
|
||||
'name': 'Zierer Rides',
|
||||
'slug': 'zierer-rides',
|
||||
'roles': ['MANUFACTURER'],
|
||||
'description': 'German manufacturer of kiddie rides and family coasters.',
|
||||
'website': 'https://www.zierer.com/',
|
||||
'founded_date': '1950-01-01',
|
||||
"name": "Zierer Rides",
|
||||
"slug": "zierer-rides",
|
||||
"roles": ["MANUFACTURER"],
|
||||
"description": "German manufacturer of kiddie rides and family coasters.",
|
||||
"website": "https://www.zierer.com/",
|
||||
"founded_date": "1950-01-01",
|
||||
},
|
||||
{
|
||||
'name': 'Gerstlauer',
|
||||
'slug': 'gerstlauer',
|
||||
'roles': ['MANUFACTURER', 'DESIGNER'],
|
||||
'description': 'German manufacturer known for Euro-Fighter and spinning coasters.',
|
||||
'website': 'https://www.gerstlauer-rides.de/',
|
||||
'founded_date': '1982-01-01',
|
||||
"name": "Gerstlauer",
|
||||
"slug": "gerstlauer",
|
||||
"roles": ["MANUFACTURER", "DESIGNER"],
|
||||
"description": "German manufacturer known for Euro-Fighter and spinning coasters.",
|
||||
"website": "https://www.gerstlauer-rides.de/",
|
||||
"founded_date": "1982-01-01",
|
||||
},
|
||||
]
|
||||
|
||||
for company_data in ride_companies_data:
|
||||
company, created = RideCompany.objects.get_or_create(
|
||||
slug=company_data['slug'],
|
||||
defaults=company_data
|
||||
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"""
|
||||
self.stdout.write('Creating parks...')
|
||||
self.stdout.write("Creating parks...")
|
||||
|
||||
parks_data = [
|
||||
# TODO: Implement park creation - parks_data defined but not used yet
|
||||
parks_data = [ # noqa: F841
|
||||
{
|
||||
'name': 'Magic Kingdom',
|
||||
'slug': 'magic-kingdom',
|
||||
'operator_slug': 'walt-disney-company',
|
||||
'property_owner_slug': 'walt-disney-company',
|
||||
'description': 'The first theme park at Walt Disney World Resort in Florida, opened in 1971.',
|
||||
'opening_date': '1971-10-01',
|
||||
'size_acres': 142,
|
||||
'website': 'https://disneyworld.disney.go.com/destinations/magic-kingdom/',
|
||||
'location': {
|
||||
'street_address': '1180 Seven Seas Dr',
|
||||
'city': 'Lake Buena Vista',
|
||||
'state_province': 'Florida',
|
||||
'country': 'USA',
|
||||
'postal_code': '32830',
|
||||
'latitude': 28.4177,
|
||||
'longitude': -81.5812
|
||||
}
|
||||
"name": "Magic Kingdom",
|
||||
"slug": "magic-kingdom",
|
||||
"operator_slug": "walt-disney-company",
|
||||
"property_owner_slug": "walt-disney-company",
|
||||
"description": "The first theme park at Walt Disney World Resort in Florida, opened in 1971.",
|
||||
"opening_date": "1971-10-01",
|
||||
"size_acres": 142,
|
||||
"website": "https://disneyworld.disney.go.com/destinations/magic-kingdom/",
|
||||
"location": {
|
||||
"street_address": "1180 Seven Seas Dr",
|
||||
"city": "Lake Buena Vista",
|
||||
"state_province": "Florida",
|
||||
"country": "USA",
|
||||
"postal_code": "32830",
|
||||
"latitude": 28.4177,
|
||||
"longitude": -81.5812,
|
||||
},
|
||||
},
|
||||
{
|
||||
'name': 'Universal Studios Florida',
|
||||
'slug': 'universal-studios-florida',
|
||||
'operator_slug': 'universal-parks-resorts',
|
||||
'property_owner_slug': 'universal-parks-resorts',
|
||||
'description': 'Movie and television-based theme park in Orlando, Florida.',
|
||||
'opening_date': '1990-06-07',
|
||||
'size_acres': 108,
|
||||
'website': 'https://www.universalorlando.com/web/en/us/theme-parks/universal-studios-florida',
|
||||
'location': {
|
||||
'street_address': '6000 Universal Blvd',
|
||||
'city': 'Orlando',
|
||||
'state_province': 'Florida',
|
||||
'country': 'USA',
|
||||
'postal_code': '32819',
|
||||
'latitude': 28.4749,
|
||||
'longitude': -81.4687
|
||||
}
|
||||
"name": "Universal Studios Florida",
|
||||
"slug": "universal-studios-florida",
|
||||
"operator_slug": "universal-parks-resorts",
|
||||
"property_owner_slug": "universal-parks-resorts",
|
||||
"description": "Movie and television-based theme park in Orlando, Florida.",
|
||||
"opening_date": "1990-06-07",
|
||||
"size_acres": 108,
|
||||
"website": "https://www.universalorlando.com/web/en/us/theme-parks/universal-studios-florida",
|
||||
"location": {
|
||||
"street_address": "6000 Universal Blvd",
|
||||
"city": "Orlando",
|
||||
"state_province": "Florida",
|
||||
"country": "USA",
|
||||
"postal_code": "32819",
|
||||
"latitude": 28.4749,
|
||||
"longitude": -81.4687,
|
||||
},
|
||||
},
|
||||
{
|
||||
'name': 'Cedar Point',
|
||||
'slug': 'cedar-point',
|
||||
'operator_slug': 'cedar-fair-entertainment',
|
||||
'property_owner_slug': 'cedar-fair-entertainment',
|
||||
'description': 'Known as the "Roller Coaster Capital of the World".',
|
||||
'opening_date': '1870-06-01',
|
||||
'size_acres': 364,
|
||||
'website': 'https://www.cedarpoint.com/',
|
||||
'location': {
|
||||
'street_address': '1 Cedar Point Dr',
|
||||
'city': 'Sandusky',
|
||||
'state_province': 'Ohio',
|
||||
'country': 'USA',
|
||||
'postal_code': '44870',
|
||||
'latitude': 41.4822,
|
||||
'longitude': -82.6835
|
||||
}
|
||||
"name": "Cedar Point",
|
||||
"slug": "cedar-point",
|
||||
"operator_slug": "cedar-fair-entertainment",
|
||||
"property_owner_slug": "cedar-fair-entertainment",
|
||||
"description": 'Known as the "Roller Coaster Capital of the World".',
|
||||
"opening_date": "1870-06-01",
|
||||
"size_acres": 364,
|
||||
"website": "https://www.cedarpoint.com/",
|
||||
"location": {
|
||||
"street_address": "1 Cedar Point Dr",
|
||||
"city": "Sandusky",
|
||||
"state_province": "Ohio",
|
||||
"country": "USA",
|
||||
"postal_code": "44870",
|
||||
"latitude": 41.4822,
|
||||
"longitude": -82.6835,
|
||||
},
|
||||
},
|
||||
{
|
||||
'name': 'Six Flags Magic Mountain',
|
||||
'slug': 'six-flags-magic-mountain',
|
||||
'operator_slug': 'six-flags-entertainment',
|
||||
'property_owner_slug': 'six-flags-entertainment',
|
||||
'description': 'Known for its world-record 19 roller coasters.',
|
||||
'opening_date': '1971-05-29',
|
||||
'size_acres': 262,
|
||||
'website': 'https://www.sixflags.com/magicmountain',
|
||||
'location': {
|
||||
'street_address': '26101 Magic Mountain Pkwy',
|
||||
'city': 'Valencia',
|
||||
'state_province': 'California',
|
||||
'country': 'USA',
|
||||
'postal_code': '91355',
|
||||
'latitude': 34.4253,
|
||||
'longitude': -118.5971
|
||||
}
|
||||
"name": "Six Flags Magic Mountain",
|
||||
"slug": "six-flags-magic-mountain",
|
||||
"operator_slug": "six-flags-entertainment",
|
||||
"property_owner_slug": "six-flags-entertainment",
|
||||
"description": "Known for its world-record 19 roller coasters.",
|
||||
"opening_date": "1971-05-29",
|
||||
"size_acres": 262,
|
||||
"website": "https://www.sixflags.com/magicmountain",
|
||||
"location": {
|
||||
"street_address": "26101 Magic Mountain Pkwy",
|
||||
"city": "Valencia",
|
||||
"state_province": "California",
|
||||
"country": "USA",
|
||||
"postal_code": "91355",
|
||||
"latitude": 34.4253,
|
||||
"longitude": -118.5971,
|
||||
},
|
||||
},
|
||||
{
|
||||
'name': 'Europa-Park',
|
||||
'slug': 'europa-park',
|
||||
'operator_slug': 'merlin-entertainments',
|
||||
'property_owner_slug': 'merlin-entertainments',
|
||||
'description': 'One of the most popular theme parks in Europe, located in Germany.',
|
||||
'opening_date': '1975-07-12',
|
||||
'size_acres': 234,
|
||||
'website': 'https://www.europapark.de/',
|
||||
'location': {
|
||||
'street_address': 'Europa-Park-Straße 2',
|
||||
'city': 'Rust',
|
||||
'state_province': 'Baden-Württemberg',
|
||||
'country': 'Germany',
|
||||
'postal_code': '77977',
|
||||
'latitude': 48.2667,
|
||||
'longitude': 7.7167
|
||||
}
|
||||
"name": "Europa-Park",
|
||||
"slug": "europa-park",
|
||||
"operator_slug": "merlin-entertainments",
|
||||
"property_owner_slug": "merlin-entertainments",
|
||||
"description": "One of the most popular theme parks in Europe, located in Germany.",
|
||||
"opening_date": "1975-07-12",
|
||||
"size_acres": 234,
|
||||
"website": "https://www.europapark.de/",
|
||||
"location": {
|
||||
"street_address": "Europa-Park-Straße 2",
|
||||
"city": "Rust",
|
||||
"state_province": "Baden-Württemberg",
|
||||
"country": "Germany",
|
||||
"postal_code": "77977",
|
||||
"latitude": 48.2667,
|
||||
"longitude": 7.7167,
|
||||
},
|
||||
},
|
||||
{
|
||||
'name': 'Alton Towers',
|
||||
'slug': 'alton-towers',
|
||||
'operator_slug': 'merlin-entertainments',
|
||||
'property_owner_slug': 'merlin-entertainments',
|
||||
'description': 'Major theme park and former country estate in Staffordshire, England.',
|
||||
'opening_date': '1980-04-23',
|
||||
'size_acres': 500,
|
||||
"name": "Alton Towers",
|
||||
"slug": "alton-towers",
|
||||
"operator_slug": "merlin-entertainments",
|
||||
"property_owner_slug": "merlin-entertainments",
|
||||
"description": "Major theme park and former country estate in Staffordshire, England.",
|
||||
"opening_date": "1980-04-23",
|
||||
"size_acres": 500,
|
||||
# Add other fields as needed
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
@@ -3,26 +3,34 @@ from django.db import connection
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Fix migration history'
|
||||
help = "Fix migration history"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
with connection.cursor() as cursor:
|
||||
# Drop existing historical tables
|
||||
cursor.execute("""
|
||||
cursor.execute(
|
||||
"""
|
||||
DROP TABLE IF EXISTS parks_historicalpark CASCADE;
|
||||
DROP TABLE IF EXISTS parks_historicalparkarea CASCADE;
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
# Delete all existing parks migrations
|
||||
cursor.execute("""
|
||||
DELETE FROM django_migrations
|
||||
cursor.execute(
|
||||
"""
|
||||
DELETE FROM django_migrations
|
||||
WHERE app = 'parks';
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
# Insert the new initial migration
|
||||
cursor.execute("""
|
||||
cursor.execute(
|
||||
"""
|
||||
INSERT INTO django_migrations (app, name, applied)
|
||||
VALUES ('parks', '0001_initial', NOW());
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Successfully fixed migration history'))
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS("Successfully fixed migration history")
|
||||
)
|
||||
|
||||
@@ -1,246 +1,334 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils import timezone
|
||||
from parks.models.companies import Operator
|
||||
from parks.models import Park, ParkArea
|
||||
from parks.models.location import ParkLocation
|
||||
from parks.models import Park, ParkArea, ParkLocation, Company as Operator
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Seeds initial park data with major theme parks worldwide'
|
||||
help = "Seeds initial park data with major theme parks worldwide"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# Create major theme park companies
|
||||
companies_data = [
|
||||
{
|
||||
'name': 'The Walt Disney Company',
|
||||
'website': 'https://www.disney.com/',
|
||||
'headquarters': 'Burbank, California',
|
||||
'description': 'The world\'s largest entertainment company and theme park operator.'
|
||||
"name": "The Walt Disney Company",
|
||||
"website": "https://www.disney.com/",
|
||||
"headquarters": "Burbank, California",
|
||||
"description": "The world's largest entertainment company and theme park operator.",
|
||||
},
|
||||
{
|
||||
'name': 'Universal Parks & Resorts',
|
||||
'website': 'https://www.universalparks.com/',
|
||||
'headquarters': 'Orlando, Florida',
|
||||
'description': 'A division of Comcast NBCUniversal, operating major theme parks worldwide.'
|
||||
"name": "Universal Parks & Resorts",
|
||||
"website": "https://www.universalparks.com/",
|
||||
"headquarters": "Orlando, Florida",
|
||||
"description": "A division of Comcast NBCUniversal, operating major theme parks worldwide.",
|
||||
},
|
||||
{
|
||||
'name': 'Six Flags Entertainment Corporation',
|
||||
'website': 'https://www.sixflags.com/',
|
||||
'headquarters': 'Arlington, Texas',
|
||||
'description': 'The world\'s largest regional theme park company.'
|
||||
"name": "Six Flags Entertainment Corporation",
|
||||
"website": "https://www.sixflags.com/",
|
||||
"headquarters": "Arlington, Texas",
|
||||
"description": "The world's largest regional theme park company.",
|
||||
},
|
||||
{
|
||||
'name': 'Cedar Fair Entertainment Company',
|
||||
'website': 'https://www.cedarfair.com/',
|
||||
'headquarters': 'Sandusky, Ohio',
|
||||
'description': 'One of North America\'s largest operators of regional amusement parks.'
|
||||
"name": "Cedar Fair Entertainment Company",
|
||||
"website": "https://www.cedarfair.com/",
|
||||
"headquarters": "Sandusky, Ohio",
|
||||
"description": "One of North America's largest operators of regional amusement parks.",
|
||||
},
|
||||
{
|
||||
'name': 'Herschend Family Entertainment',
|
||||
'website': 'https://www.hfecorp.com/',
|
||||
'headquarters': 'Atlanta, Georgia',
|
||||
'description': 'The largest family-owned themed attractions corporation in the United States.'
|
||||
"name": "Herschend Family Entertainment",
|
||||
"website": "https://www.hfecorp.com/",
|
||||
"headquarters": "Atlanta, Georgia",
|
||||
"description": "The largest family-owned themed attractions corporation in the United States.",
|
||||
},
|
||||
{
|
||||
'name': 'SeaWorld Parks & Entertainment',
|
||||
'website': 'https://www.seaworldentertainment.com/',
|
||||
'headquarters': 'Orlando, Florida',
|
||||
'description': 'Theme park and entertainment company focusing on nature-based themes.'
|
||||
}
|
||||
"name": "SeaWorld Parks & Entertainment",
|
||||
"website": "https://www.seaworldentertainment.com/",
|
||||
"headquarters": "Orlando, Florida",
|
||||
"description": "Theme park and entertainment company focusing on nature-based themes.",
|
||||
},
|
||||
]
|
||||
|
||||
companies = {}
|
||||
for company_data in companies_data:
|
||||
operator, created = Operator.objects.get_or_create(
|
||||
name=company_data['name'],
|
||||
defaults=company_data
|
||||
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 = [
|
||||
{
|
||||
'name': 'Magic Kingdom',
|
||||
'company': 'The Walt Disney Company',
|
||||
'description': 'The first theme park at Walt Disney World Resort in Florida, opened in 1971.',
|
||||
'opening_date': '1971-10-01',
|
||||
'size_acres': 142,
|
||||
'location': {
|
||||
'street_address': '1180 Seven Seas Dr',
|
||||
'city': 'Lake Buena Vista',
|
||||
'state': 'Florida',
|
||||
'country': 'United States',
|
||||
'postal_code': '32830',
|
||||
'latitude': 28.4177,
|
||||
'longitude': -81.5812
|
||||
"name": "Magic Kingdom",
|
||||
"company": "The Walt Disney Company",
|
||||
"description": "The first theme park at Walt Disney World Resort in Florida, opened in 1971.",
|
||||
"opening_date": "1971-10-01",
|
||||
"size_acres": 142,
|
||||
"location": {
|
||||
"street_address": "1180 Seven Seas Dr",
|
||||
"city": "Lake Buena Vista",
|
||||
"state": "Florida",
|
||||
"country": "United States",
|
||||
"postal_code": "32830",
|
||||
"latitude": 28.4177,
|
||||
"longitude": -81.5812,
|
||||
},
|
||||
'areas': [
|
||||
{'name': 'Main Street, U.S.A.', 'description': 'Victorian-era themed entrance corridor'},
|
||||
{'name': 'Adventureland', 'description': 'Exotic tropical places themed area'},
|
||||
{'name': 'Frontierland', 'description': 'American Old West themed area'},
|
||||
{'name': 'Liberty Square', 'description': 'Colonial America themed area'},
|
||||
{'name': 'Fantasyland', 'description': 'Fairy tale themed area'},
|
||||
{'name': 'Tomorrowland', 'description': 'Future themed area'}
|
||||
]
|
||||
"areas": [
|
||||
{
|
||||
"name": "Main Street, U.S.A.",
|
||||
"description": "Victorian-era themed entrance corridor",
|
||||
},
|
||||
{
|
||||
"name": "Adventureland",
|
||||
"description": "Exotic tropical places themed area",
|
||||
},
|
||||
{
|
||||
"name": "Frontierland",
|
||||
"description": "American Old West themed area",
|
||||
},
|
||||
{
|
||||
"name": "Liberty Square",
|
||||
"description": "Colonial America themed area",
|
||||
},
|
||||
{
|
||||
"name": "Fantasyland",
|
||||
"description": "Fairy tale themed area",
|
||||
},
|
||||
{
|
||||
"name": "Tomorrowland",
|
||||
"description": "Future themed area",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'Universal Studios Florida',
|
||||
'company': 'Universal Parks & Resorts',
|
||||
'description': 'Movie and television-based theme park in Orlando, Florida.',
|
||||
'opening_date': '1990-06-07',
|
||||
'size_acres': 108,
|
||||
'location': {
|
||||
'street_address': '6000 Universal Blvd',
|
||||
'city': 'Orlando',
|
||||
'state': 'Florida',
|
||||
'country': 'United States',
|
||||
'postal_code': '32819',
|
||||
'latitude': 28.4749,
|
||||
'longitude': -81.4687
|
||||
"name": "Universal Studios Florida",
|
||||
"company": "Universal Parks & Resorts",
|
||||
"description": "Movie and television-based theme park in Orlando, Florida.",
|
||||
"opening_date": "1990-06-07",
|
||||
"size_acres": 108,
|
||||
"location": {
|
||||
"street_address": "6000 Universal Blvd",
|
||||
"city": "Orlando",
|
||||
"state": "Florida",
|
||||
"country": "United States",
|
||||
"postal_code": "32819",
|
||||
"latitude": 28.4749,
|
||||
"longitude": -81.4687,
|
||||
},
|
||||
'areas': [
|
||||
{'name': 'Production Central', 'description': 'Main entrance area with movie-themed attractions'},
|
||||
{'name': 'New York', 'description': 'Themed after New York City streets'},
|
||||
{'name': 'San Francisco', 'description': 'Themed after San Francisco\'s waterfront'},
|
||||
{'name': 'The Wizarding World of Harry Potter - Diagon Alley', 'description': 'Themed after the Harry Potter series'},
|
||||
{'name': 'Springfield', 'description': 'Themed after The Simpsons hometown'}
|
||||
]
|
||||
"areas": [
|
||||
{
|
||||
"name": "Production Central",
|
||||
"description": "Main entrance area with movie-themed attractions",
|
||||
},
|
||||
{
|
||||
"name": "New York",
|
||||
"description": "Themed after New York City streets",
|
||||
},
|
||||
{
|
||||
"name": "San Francisco",
|
||||
"description": "Themed after San Francisco's waterfront",
|
||||
},
|
||||
{
|
||||
"name": "The Wizarding World of Harry Potter - Diagon Alley",
|
||||
"description": "Themed after the Harry Potter series",
|
||||
},
|
||||
{
|
||||
"name": "Springfield",
|
||||
"description": "Themed after The Simpsons hometown",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'Cedar Point',
|
||||
'company': 'Cedar Fair Entertainment Company',
|
||||
'description': 'Known as the "Roller Coaster Capital of the World".',
|
||||
'opening_date': '1870-06-01',
|
||||
'size_acres': 364,
|
||||
'location': {
|
||||
'street_address': '1 Cedar Point Dr',
|
||||
'city': 'Sandusky',
|
||||
'state': 'Ohio',
|
||||
'country': 'United States',
|
||||
'postal_code': '44870',
|
||||
'latitude': 41.4822,
|
||||
'longitude': -82.6835
|
||||
"name": "Cedar Point",
|
||||
"company": "Cedar Fair Entertainment Company",
|
||||
"description": 'Known as the "Roller Coaster Capital of the World".',
|
||||
"opening_date": "1870-06-01",
|
||||
"size_acres": 364,
|
||||
"location": {
|
||||
"street_address": "1 Cedar Point Dr",
|
||||
"city": "Sandusky",
|
||||
"state": "Ohio",
|
||||
"country": "United States",
|
||||
"postal_code": "44870",
|
||||
"latitude": 41.4822,
|
||||
"longitude": -82.6835,
|
||||
},
|
||||
'areas': [
|
||||
{'name': 'Frontiertown', 'description': 'Western-themed area with multiple roller coasters'},
|
||||
{'name': 'Millennium Island', 'description': 'Home to the Millennium Force roller coaster'},
|
||||
{'name': 'Cedar Point Shores', 'description': 'Waterpark area'},
|
||||
{'name': 'Top Thrill Dragster', 'description': 'Area surrounding the iconic launched coaster'}
|
||||
]
|
||||
"areas": [
|
||||
{
|
||||
"name": "Frontiertown",
|
||||
"description": "Western-themed area with multiple roller coasters",
|
||||
},
|
||||
{
|
||||
"name": "Millennium Island",
|
||||
"description": "Home to the Millennium Force roller coaster",
|
||||
},
|
||||
{
|
||||
"name": "Cedar Point Shores",
|
||||
"description": "Waterpark area",
|
||||
},
|
||||
{
|
||||
"name": "Top Thrill Dragster",
|
||||
"description": "Area surrounding the iconic launched coaster",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'Silver Dollar City',
|
||||
'company': 'Herschend Family Entertainment',
|
||||
'description': 'An 1880s-themed park featuring over 40 rides and attractions.',
|
||||
'opening_date': '1960-05-01',
|
||||
'size_acres': 61,
|
||||
'location': {
|
||||
'street_address': '399 Silver Dollar City Parkway',
|
||||
'city': 'Branson',
|
||||
'state': 'Missouri',
|
||||
'country': 'United States',
|
||||
'postal_code': '65616',
|
||||
'latitude': 36.668497,
|
||||
'longitude': -93.339074
|
||||
"name": "Silver Dollar City",
|
||||
"company": "Herschend Family Entertainment",
|
||||
"description": "An 1880s-themed park featuring over 40 rides and attractions.",
|
||||
"opening_date": "1960-05-01",
|
||||
"size_acres": 61,
|
||||
"location": {
|
||||
"street_address": "399 Silver Dollar City Parkway",
|
||||
"city": "Branson",
|
||||
"state": "Missouri",
|
||||
"country": "United States",
|
||||
"postal_code": "65616",
|
||||
"latitude": 36.668497,
|
||||
"longitude": -93.339074,
|
||||
},
|
||||
'areas': [
|
||||
{'name': 'Grand Exposition', 'description': 'Home to many family rides and attractions'},
|
||||
{'name': 'Wildfire', 'description': 'Named after the famous B&M coaster'},
|
||||
{'name': 'Wilson\'s Farm', 'description': 'Farm-themed attractions and dining'},
|
||||
{'name': 'Riverfront', 'description': 'Water-themed attractions area'},
|
||||
{'name': 'The Valley', 'description': 'Home to Time Traveler and other major attractions'}
|
||||
]
|
||||
"areas": [
|
||||
{
|
||||
"name": "Grand Exposition",
|
||||
"description": "Home to many family rides and attractions",
|
||||
},
|
||||
{
|
||||
"name": "Wildfire",
|
||||
"description": "Named after the famous B&M coaster",
|
||||
},
|
||||
{
|
||||
"name": "Wilson's Farm",
|
||||
"description": "Farm-themed attractions and dining",
|
||||
},
|
||||
{
|
||||
"name": "Riverfront",
|
||||
"description": "Water-themed attractions area",
|
||||
},
|
||||
{
|
||||
"name": "The Valley",
|
||||
"description": "Home to Time Traveler and other major attractions",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'Six Flags Magic Mountain',
|
||||
'company': 'Six Flags Entertainment Corporation',
|
||||
'description': 'Known for its world-record 19 roller coasters.',
|
||||
'opening_date': '1971-05-29',
|
||||
'size_acres': 262,
|
||||
'location': {
|
||||
'street_address': '26101 Magic Mountain Pkwy',
|
||||
'city': 'Valencia',
|
||||
'state': 'California',
|
||||
'country': 'United States',
|
||||
'postal_code': '91355',
|
||||
'latitude': 34.4253,
|
||||
'longitude': -118.5971
|
||||
"name": "Six Flags Magic Mountain",
|
||||
"company": "Six Flags Entertainment Corporation",
|
||||
"description": "Known for its world-record 19 roller coasters.",
|
||||
"opening_date": "1971-05-29",
|
||||
"size_acres": 262,
|
||||
"location": {
|
||||
"street_address": "26101 Magic Mountain Pkwy",
|
||||
"city": "Valencia",
|
||||
"state": "California",
|
||||
"country": "United States",
|
||||
"postal_code": "91355",
|
||||
"latitude": 34.4253,
|
||||
"longitude": -118.5971,
|
||||
},
|
||||
'areas': [
|
||||
{'name': 'Six Flags Plaza', 'description': 'Main entrance area'},
|
||||
{'name': 'DC Universe', 'description': 'DC Comics themed area'},
|
||||
{'name': 'Screampunk District', 'description': 'Steampunk themed area'},
|
||||
{'name': 'The Underground', 'description': 'Urban themed area'},
|
||||
{'name': 'Goliath Territory', 'description': 'Area surrounding the Goliath hypercoaster'}
|
||||
]
|
||||
"areas": [
|
||||
{
|
||||
"name": "Six Flags Plaza",
|
||||
"description": "Main entrance area",
|
||||
},
|
||||
{
|
||||
"name": "DC Universe",
|
||||
"description": "DC Comics themed area",
|
||||
},
|
||||
{
|
||||
"name": "Screampunk District",
|
||||
"description": "Steampunk themed area",
|
||||
},
|
||||
{
|
||||
"name": "The Underground",
|
||||
"description": "Urban themed area",
|
||||
},
|
||||
{
|
||||
"name": "Goliath Territory",
|
||||
"description": "Area surrounding the Goliath hypercoaster",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'SeaWorld Orlando',
|
||||
'company': 'SeaWorld Parks & Entertainment',
|
||||
'description': 'Marine zoological park combined with thrill rides and shows.',
|
||||
'opening_date': '1973-12-15',
|
||||
'size_acres': 200,
|
||||
'location': {
|
||||
'street_address': '7007 Sea World Dr',
|
||||
'city': 'Orlando',
|
||||
'state': 'Florida',
|
||||
'country': 'United States',
|
||||
'postal_code': '32821',
|
||||
'latitude': 28.4115,
|
||||
'longitude': -81.4617
|
||||
"name": "SeaWorld Orlando",
|
||||
"company": "SeaWorld Parks & Entertainment",
|
||||
"description": "Marine zoological park combined with thrill rides and shows.",
|
||||
"opening_date": "1973-12-15",
|
||||
"size_acres": 200,
|
||||
"location": {
|
||||
"street_address": "7007 Sea World Dr",
|
||||
"city": "Orlando",
|
||||
"state": "Florida",
|
||||
"country": "United States",
|
||||
"postal_code": "32821",
|
||||
"latitude": 28.4115,
|
||||
"longitude": -81.4617,
|
||||
},
|
||||
'areas': [
|
||||
{'name': 'Sea Harbor', 'description': 'Main entrance and shopping area'},
|
||||
{'name': 'Shark Encounter', 'description': 'Shark exhibit and themed area'},
|
||||
{'name': 'Antarctica: Empire of the Penguin', 'description': 'Penguin-themed area'},
|
||||
{'name': 'Manta', 'description': 'Area themed around the Manta flying roller coaster'},
|
||||
{'name': 'Sesame Street Land', 'description': 'Kid-friendly area based on Sesame Street'}
|
||||
]
|
||||
}
|
||||
"areas": [
|
||||
{
|
||||
"name": "Sea Harbor",
|
||||
"description": "Main entrance and shopping area",
|
||||
},
|
||||
{
|
||||
"name": "Shark Encounter",
|
||||
"description": "Shark exhibit and themed area",
|
||||
},
|
||||
{
|
||||
"name": "Antarctica: Empire of the Penguin",
|
||||
"description": "Penguin-themed area",
|
||||
},
|
||||
{
|
||||
"name": "Manta",
|
||||
"description": "Area themed around the Manta flying roller coaster",
|
||||
},
|
||||
{
|
||||
"name": "Sesame Street Land",
|
||||
"description": "Kid-friendly area based on Sesame Street",
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
# Create parks and their areas
|
||||
for park_data in parks_data:
|
||||
company = companies[park_data['company']]
|
||||
company = companies[park_data["company"]]
|
||||
park, created = Park.objects.get_or_create(
|
||||
name=park_data['name'],
|
||||
name=park_data["name"],
|
||||
defaults={
|
||||
'description': park_data['description'],
|
||||
'status': 'OPERATING',
|
||||
'opening_date': park_data['opening_date'],
|
||||
'size_acres': park_data['size_acres'],
|
||||
'owner': company
|
||||
}
|
||||
"description": park_data["description"],
|
||||
"status": "OPERATING",
|
||||
"opening_date": park_data["opening_date"],
|
||||
"size_acres": park_data["size_acres"],
|
||||
"owner": company,
|
||||
},
|
||||
)
|
||||
self.stdout.write(f'{"Created" if created else "Found"} park: {park.name}')
|
||||
|
||||
# Create location for park
|
||||
if created:
|
||||
loc_data = park_data['location']
|
||||
loc_data = park_data["location"]
|
||||
park_location = ParkLocation.objects.create(
|
||||
park=park,
|
||||
street_address=loc_data['street_address'],
|
||||
city=loc_data['city'],
|
||||
state=loc_data['state'],
|
||||
country=loc_data['country'],
|
||||
postal_code=loc_data['postal_code']
|
||||
street_address=loc_data["street_address"],
|
||||
city=loc_data["city"],
|
||||
state=loc_data["state"],
|
||||
country=loc_data["country"],
|
||||
postal_code=loc_data["postal_code"],
|
||||
)
|
||||
# Set coordinates using the helper method
|
||||
park_location.set_coordinates(
|
||||
loc_data['latitude'],
|
||||
loc_data['longitude']
|
||||
loc_data["latitude"], loc_data["longitude"]
|
||||
)
|
||||
park_location.save()
|
||||
|
||||
# Create areas for park
|
||||
for area_data in park_data['areas']:
|
||||
for area_data in park_data["areas"]:
|
||||
area, created = ParkArea.objects.get_or_create(
|
||||
name=area_data['name'],
|
||||
name=area_data["name"],
|
||||
park=park,
|
||||
defaults={
|
||||
'description': area_data['description']
|
||||
}
|
||||
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'))
|
||||
self.stdout.write(self.style.SUCCESS("Successfully seeded initial park data"))
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,96 +1,97 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from parks.models import Park, ParkLocation
|
||||
from parks.models.companies import Company
|
||||
from parks.models import Park, ParkLocation, Company
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Test ParkLocation model functionality'
|
||||
help = "Test ParkLocation model functionality"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.stdout.write("🧪 Testing ParkLocation Model Functionality")
|
||||
self.stdout.write("=" * 50)
|
||||
|
||||
|
||||
# Create a test company (operator)
|
||||
operator, created = Company.objects.get_or_create(
|
||||
name="Test Theme Parks Inc",
|
||||
defaults={
|
||||
'slug': 'test-theme-parks-inc',
|
||||
'roles': ['OPERATOR']
|
||||
}
|
||||
defaults={"slug": "test-theme-parks-inc", "roles": ["OPERATOR"]},
|
||||
)
|
||||
self.stdout.write(f"✅ Created operator: {operator.name}")
|
||||
|
||||
|
||||
# Create a test park
|
||||
park, created = Park.objects.get_or_create(
|
||||
name="Test Magic Kingdom",
|
||||
defaults={
|
||||
'slug': 'test-magic-kingdom',
|
||||
'description': 'A test theme park for location testing',
|
||||
'operator': operator
|
||||
}
|
||||
"slug": "test-magic-kingdom",
|
||||
"description": "A test theme park for location testing",
|
||||
"operator": operator,
|
||||
},
|
||||
)
|
||||
self.stdout.write(f"✅ Created park: {park.name}")
|
||||
|
||||
|
||||
# Create a park location
|
||||
location, created = ParkLocation.objects.get_or_create(
|
||||
park=park,
|
||||
defaults={
|
||||
'street_address': '1313 Disneyland Dr',
|
||||
'city': 'Anaheim',
|
||||
'state': 'California',
|
||||
'country': 'USA',
|
||||
'postal_code': '92802',
|
||||
'highway_exit': 'I-5 Exit 110B',
|
||||
'parking_notes': 'Large parking structure available',
|
||||
'seasonal_notes': 'Open year-round'
|
||||
}
|
||||
"street_address": "1313 Disneyland Dr",
|
||||
"city": "Anaheim",
|
||||
"state": "California",
|
||||
"country": "USA",
|
||||
"postal_code": "92802",
|
||||
"highway_exit": "I-5 Exit 110B",
|
||||
"parking_notes": "Large parking structure available",
|
||||
"seasonal_notes": "Open year-round",
|
||||
},
|
||||
)
|
||||
self.stdout.write(f"✅ Created location: {location}")
|
||||
|
||||
|
||||
# Test coordinate setting
|
||||
self.stdout.write("\n🔍 Testing coordinate functionality:")
|
||||
location.set_coordinates(33.8121, -117.9190) # Disneyland coordinates
|
||||
location.save()
|
||||
|
||||
|
||||
self.stdout.write(f" Latitude: {location.latitude}")
|
||||
self.stdout.write(f" Longitude: {location.longitude}")
|
||||
self.stdout.write(f" Coordinates: {location.coordinates}")
|
||||
self.stdout.write(f" Formatted Address: {location.formatted_address}")
|
||||
|
||||
|
||||
# Test Park model integration
|
||||
self.stdout.write("\n🔍 Testing Park model integration:")
|
||||
self.stdout.write(f" Park formatted location: {park.formatted_location}")
|
||||
self.stdout.write(
|
||||
f" Park formatted location: {
|
||||
park.formatted_location}"
|
||||
)
|
||||
self.stdout.write(f" Park coordinates: {park.coordinates}")
|
||||
|
||||
|
||||
# Create another location for distance testing
|
||||
operator2, created = Company.objects.get_or_create(
|
||||
name="Six Flags Entertainment",
|
||||
defaults={
|
||||
'slug': 'six-flags-entertainment',
|
||||
'roles': ['OPERATOR']
|
||||
}
|
||||
"slug": "six-flags-entertainment",
|
||||
"roles": ["OPERATOR"],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
park2, created = Park.objects.get_or_create(
|
||||
name="Six Flags Magic Mountain",
|
||||
defaults={
|
||||
'slug': 'six-flags-magic-mountain',
|
||||
'description': 'Another test theme park',
|
||||
'operator': operator2
|
||||
}
|
||||
"slug": "six-flags-magic-mountain",
|
||||
"description": "Another test theme park",
|
||||
"operator": operator2,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
location2, created = ParkLocation.objects.get_or_create(
|
||||
park=park2,
|
||||
defaults={
|
||||
'city': 'Valencia',
|
||||
'state': 'California',
|
||||
'country': 'USA'
|
||||
}
|
||||
"city": "Valencia",
|
||||
"state": "California",
|
||||
"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
|
||||
self.stdout.write("\n🔍 Testing distance calculation:")
|
||||
distance = location.distance_to(location2)
|
||||
@@ -98,22 +99,26 @@ class Command(BaseCommand):
|
||||
self.stdout.write(f" Distance between parks: {distance:.2f} km")
|
||||
else:
|
||||
self.stdout.write(" ❌ Distance calculation failed")
|
||||
|
||||
|
||||
# Test spatial indexing
|
||||
self.stdout.write("\n🔍 Testing spatial queries:")
|
||||
try:
|
||||
from django.contrib.gis.measure import D
|
||||
from django.contrib.gis.geos import Point
|
||||
|
||||
|
||||
# Find parks within 100km of a point
|
||||
search_point = Point(-117.9190, 33.8121, srid=4326) # Same as Disneyland
|
||||
# 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))
|
||||
)
|
||||
self.stdout.write(f" Found {nearby_locations.count()} parks within 100km")
|
||||
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}")
|
||||
except Exception as e:
|
||||
self.stdout.write(f" ⚠️ Spatial queries not fully functional: {e}")
|
||||
|
||||
self.stdout.write("\n✅ ParkLocation model tests completed successfully!")
|
||||
|
||||
self.stdout.write("\n✅ ParkLocation model tests completed successfully!")
|
||||
|
||||
@@ -1,34 +1,29 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db.models import Count, Q
|
||||
from django.db.models import Q
|
||||
from parks.models import Park
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Update total_rides and total_roller_coasters counts for all parks'
|
||||
help = "Update total_rides and total_roller_coasters counts for all parks"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
parks = Park.objects.all()
|
||||
operating_rides = Q(status='OPERATING')
|
||||
operating_rides = Q(status="OPERATING")
|
||||
updated = 0
|
||||
|
||||
for park in parks:
|
||||
# Count total operating rides
|
||||
total_rides = park.rides.filter(operating_rides).count()
|
||||
|
||||
|
||||
# Count total operating roller coasters
|
||||
total_coasters = park.rides.filter(
|
||||
operating_rides,
|
||||
category='RC'
|
||||
).count()
|
||||
|
||||
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
|
||||
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.style.SUCCESS(f"Successfully updated counts for {updated} parks")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user