mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-01-02 03:27:02 -05:00
feat: Implement initial schema and add various API, service, and management command enhancements across the application.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user