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

@@ -9,7 +9,7 @@ while maintaining backward compatibility through the Company alias.
"""
# Import choices to trigger registration
from ..choices import *
from ..choices import * # noqa: F403
from .areas import ParkArea
from .companies import Company, CompanyHeadquarters
from .location import ParkLocation

View File

@@ -21,16 +21,10 @@ class ParkArea(TrackedModel):
help_text="Park this area belongs to",
)
name = models.CharField(max_length=255, help_text="Name of the park area")
slug = models.SlugField(
max_length=255, help_text="URL-friendly identifier (unique within park)"
)
slug = models.SlugField(max_length=255, help_text="URL-friendly identifier (unique within park)")
description = models.TextField(blank=True, help_text="Detailed description of the area")
opening_date = models.DateField(
null=True, blank=True, help_text="Date this area opened"
)
closing_date = models.DateField(
null=True, blank=True, help_text="Date this area closed (if applicable)"
)
opening_date = models.DateField(null=True, blank=True, help_text="Date this area opened")
closing_date = models.DateField(null=True, blank=True, help_text="Date this area closed (if applicable)")
def save(self, *args, **kwargs):
if not self.slug:

View File

@@ -26,15 +26,9 @@ class Company(TrackedModel):
website = models.URLField(blank=True, help_text="Company website URL")
# Operator-specific fields
founded_year = models.PositiveIntegerField(
blank=True, null=True, help_text="Year the company was founded"
)
parks_count = models.IntegerField(
default=0, help_text="Number of parks operated (auto-calculated)"
)
rides_count = models.IntegerField(
default=0, help_text="Number of rides manufactured (auto-calculated)"
)
founded_year = models.PositiveIntegerField(blank=True, null=True, help_text="Year the company was founded")
parks_count = models.IntegerField(default=0, help_text="Number of parks operated (auto-calculated)")
rides_count = models.IntegerField(default=0, help_text="Number of rides manufactured (auto-calculated)")
def save(self, *args, **kwargs):
if not self.slug:
@@ -72,9 +66,7 @@ class CompanyHeadquarters(models.Model):
blank=True,
help_text="Mailing address if publicly available",
)
city = models.CharField(
max_length=100, db_index=True, help_text="Headquarters city"
)
city = models.CharField(max_length=100, db_index=True, help_text="Headquarters city")
state_province = models.CharField(
max_length=100,
blank=True,
@@ -87,9 +79,7 @@ class CompanyHeadquarters(models.Model):
db_index=True,
help_text="Country where headquarters is located",
)
postal_code = models.CharField(
max_length=20, blank=True, help_text="ZIP or postal code"
)
postal_code = models.CharField(max_length=20, blank=True, help_text="ZIP or postal code")
# Optional mailing address if different or more complete
mailing_address = models.TextField(

View File

@@ -9,9 +9,7 @@ class ParkLocation(models.Model):
Represents the geographic location and address of a park, with PostGIS support.
"""
park = models.OneToOneField(
"parks.Park", on_delete=models.CASCADE, related_name="location"
)
park = models.OneToOneField("parks.Park", on_delete=models.CASCADE, related_name="location")
# Spatial Data
point = models.PointField(
@@ -27,10 +25,7 @@ class ParkLocation(models.Model):
state = models.CharField(max_length=100, db_index=True)
country = models.CharField(max_length=100, default="USA")
continent = models.CharField(
max_length=50,
blank=True,
db_index=True,
help_text="Continent where the park is located"
max_length=50, blank=True, db_index=True, help_text="Continent where the park is located"
)
postal_code = models.CharField(max_length=20, blank=True)

View File

@@ -22,9 +22,7 @@ def park_photo_upload_path(instance: models.Model, filename: str) -> str:
if park is None:
raise ValueError("Park cannot be None")
return MediaService.generate_upload_path(
domain="park", identifier=park.slug, filename=filename
)
return MediaService.generate_upload_path(domain="park", identifier=park.slug, filename=filename)
@pghistory.track()
@@ -39,23 +37,15 @@ class ParkPhoto(TrackedModel):
)
image = models.ForeignKey(
'django_cloudflareimages_toolkit.CloudflareImage',
"django_cloudflareimages_toolkit.CloudflareImage",
on_delete=models.CASCADE,
help_text="Park photo stored on Cloudflare Images"
help_text="Park photo stored on Cloudflare Images",
)
caption = models.CharField(
max_length=255, blank=True, help_text="Photo caption or description"
)
alt_text = models.CharField(
max_length=255, blank=True, help_text="Alternative text for accessibility"
)
is_primary = models.BooleanField(
default=False, help_text="Whether this is the primary photo for the park"
)
is_approved = models.BooleanField(
default=False, help_text="Whether this photo has been approved by moderators"
)
caption = models.CharField(max_length=255, blank=True, help_text="Photo caption or description")
alt_text = models.CharField(max_length=255, blank=True, help_text="Alternative text for accessibility")
is_primary = models.BooleanField(default=False, help_text="Whether this is the primary photo for the park")
is_approved = models.BooleanField(default=False, help_text="Whether this photo has been approved by moderators")
# Metadata
created_at = models.DateTimeField(auto_now_add=True)
@@ -100,9 +90,7 @@ class ParkPhoto(TrackedModel):
# Set default caption if not provided
if not self.caption and self.uploaded_by:
self.caption = MediaService.generate_default_caption(
self.uploaded_by.username
)
self.caption = MediaService.generate_default_caption(self.uploaded_by.username)
# If this is marked as primary, unmark other primary photos for this park
if self.is_primary:

View File

@@ -45,7 +45,7 @@ class Park(StateMachineMixin, TrackedModel):
max_length=30,
default="THEME_PARK",
db_index=True,
help_text="Type/category of the park"
help_text="Type/category of the park",
)
# Location relationship - reverse relation from ParkLocation
@@ -118,23 +118,18 @@ class Park(StateMachineMixin, TrackedModel):
# Computed fields for hybrid filtering
opening_year = models.IntegerField(
null=True,
blank=True,
db_index=True,
help_text="Year the park opened (computed from opening_date)"
null=True, blank=True, db_index=True, help_text="Year the park opened (computed from opening_date)"
)
search_text = models.TextField(
blank=True,
db_index=True,
help_text="Searchable text combining name, description, location, and operator"
blank=True, db_index=True, help_text="Searchable text combining name, description, location, and operator"
)
# Timezone for park operations
timezone = models.CharField(
max_length=50,
default='UTC',
default="UTC",
blank=True,
help_text="Timezone identifier for park operations (e.g., 'America/New_York')"
help_text="Timezone identifier for park operations (e.g., 'America/New_York')",
)
class Meta:
@@ -171,8 +166,7 @@ class Park(StateMachineMixin, TrackedModel):
),
models.CheckConstraint(
name="park_coaster_count_non_negative",
check=models.Q(coaster_count__isnull=True)
| models.Q(coaster_count__gte=0),
check=models.Q(coaster_count__isnull=True) | models.Q(coaster_count__gte=0),
violation_error_message="Coaster count must be non-negative",
),
# Business rule: Coaster count cannot exceed ride count
@@ -204,9 +198,7 @@ class Park(StateMachineMixin, TrackedModel):
self.transition_to_under_construction(user=user)
self.save()
def close_permanently(
self, *, closing_date=None, user: Optional["AbstractBaseUser"] = None
) -> None:
def close_permanently(self, *, closing_date=None, user: Optional["AbstractBaseUser"] = None) -> None:
"""Transition park to CLOSED_PERM status."""
self.transition_to_closed_perm(user=user)
if closing_date:
@@ -279,7 +271,7 @@ class Park(StateMachineMixin, TrackedModel):
# Add location information if available
try:
if hasattr(self, 'location') and self.location:
if hasattr(self, "location") and self.location:
if self.location.city:
search_parts.append(self.location.city)
if self.location.state:
@@ -299,16 +291,14 @@ class Park(StateMachineMixin, TrackedModel):
search_parts.append(self.property_owner.name)
# Combine all parts into searchable text
self.search_text = ' '.join(filter(None, search_parts)).lower()
self.search_text = " ".join(filter(None, search_parts)).lower()
def clean(self):
super().clean()
if self.operator and "OPERATOR" not in self.operator.roles:
raise ValidationError({"operator": "Company must have the OPERATOR role."})
if self.property_owner and "PROPERTY_OWNER" not in self.property_owner.roles:
raise ValidationError(
{"property_owner": "Company must have the PROPERTY_OWNER role."}
)
raise ValidationError({"property_owner": "Company must have the PROPERTY_OWNER role."})
def get_absolute_url(self) -> str:
return reverse("parks:park_detail", kwargs={"slug": self.slug})
@@ -325,7 +315,7 @@ class Park(StateMachineMixin, TrackedModel):
"""Returns coordinates as a list [latitude, longitude]"""
if hasattr(self, "location") and self.location:
coords = self.location.coordinates
if coords and isinstance(coords, (tuple, list)):
if coords and isinstance(coords, tuple | list):
return list(coords)
return None
@@ -349,9 +339,7 @@ class Park(StateMachineMixin, TrackedModel):
content_type = ContentType.objects.get_for_model(cls)
print(f"Searching HistoricalSlug with content_type: {content_type}")
historical = (
HistoricalSlug.objects.filter(content_type=content_type, slug=slug)
.order_by("-created_at")
.first()
HistoricalSlug.objects.filter(content_type=content_type, slug=slug).order_by("-created_at").first()
)
if historical:
@@ -373,11 +361,7 @@ class Park(StateMachineMixin, TrackedModel):
print("Searching pghistory events")
event_model = getattr(cls, "event_model", None)
if event_model:
historical_event = (
event_model.objects.filter(slug=slug)
.order_by("-pgh_created_at")
.first()
)
historical_event = event_model.objects.filter(slug=slug).order_by("-pgh_created_at").first()
if historical_event:
print(
@@ -394,4 +378,4 @@ class Park(StateMachineMixin, TrackedModel):
else:
print("No pghistory event found")
raise cls.DoesNotExist("No park found with this slug")
raise cls.DoesNotExist("No park found with this slug") from None

View File

@@ -40,12 +40,8 @@ class ParkReview(TrackedModel):
updated_at = models.DateTimeField(auto_now=True)
# Moderation
is_published = models.BooleanField(
default=True, help_text="Whether this review is publicly visible"
)
moderation_notes = models.TextField(
blank=True, help_text="Internal notes from moderators"
)
is_published = models.BooleanField(default=True, help_text="Whether this review is publicly visible")
moderation_notes = models.TextField(blank=True, help_text="Internal notes from moderators")
moderated_by = models.ForeignKey(
"accounts.User",
on_delete=models.SET_NULL,
@@ -54,9 +50,7 @@ class ParkReview(TrackedModel):
related_name="moderated_park_reviews",
help_text="Moderator who reviewed this",
)
moderated_at = models.DateTimeField(
null=True, blank=True, help_text="When this review was moderated"
)
moderated_at = models.DateTimeField(null=True, blank=True, help_text="When this review was moderated")
class Meta(TrackedModel.Meta):
verbose_name = "Park Review"
@@ -82,10 +76,7 @@ class ParkReview(TrackedModel):
name="park_review_moderation_consistency",
check=models.Q(moderated_by__isnull=True, moderated_at__isnull=True)
| models.Q(moderated_by__isnull=False, moderated_at__isnull=False),
violation_error_message=(
"Moderated reviews must have both moderator and moderation "
"timestamp"
),
violation_error_message=("Moderated reviews must have both moderator and moderation " "timestamp"),
),
]