mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-24 05:51:11 -05:00
- Introduced a comprehensive Secret Management Guide detailing best practices, secret classification, development setup, production management, rotation procedures, and emergency protocols. - Implemented a client-side performance monitoring script to track various metrics including page load performance, paint metrics, layout shifts, and memory usage. - Enhanced search accessibility with keyboard navigation support for search results, ensuring compliance with WCAG standards and improving user experience.
105 lines
3.9 KiB
Python
105 lines
3.9 KiB
Python
import pghistory
|
|
from django.contrib.postgres.fields import ArrayField
|
|
from django.db import models
|
|
from django.urls import reverse
|
|
from django.utils.text import slugify
|
|
from django.conf import settings
|
|
|
|
from apps.core.history import HistoricalSlug
|
|
from apps.core.models import TrackedModel
|
|
from apps.core.choices.fields import RichChoiceField
|
|
|
|
|
|
@pghistory.track()
|
|
class Company(TrackedModel):
|
|
name = models.CharField(max_length=255, help_text="Company name")
|
|
slug = models.SlugField(max_length=255, unique=True, help_text="URL-friendly identifier")
|
|
roles = ArrayField(
|
|
RichChoiceField(choice_group="company_roles", domain="rides", max_length=20),
|
|
default=list,
|
|
blank=True,
|
|
help_text="Company roles (manufacturer, designer, etc.)",
|
|
)
|
|
description = models.TextField(blank=True, help_text="Detailed company description")
|
|
website = models.URLField(blank=True, help_text="Company website URL")
|
|
|
|
# General company info
|
|
founded_date = models.DateField(
|
|
null=True, blank=True, help_text="Date the company was founded"
|
|
)
|
|
|
|
# Manufacturer-specific fields
|
|
rides_count = models.IntegerField(
|
|
default=0, help_text="Number of rides manufactured (auto-calculated)"
|
|
)
|
|
coasters_count = models.IntegerField(
|
|
default=0, help_text="Number of coasters manufactured (auto-calculated)"
|
|
)
|
|
|
|
# Frontend URL
|
|
url = models.URLField(blank=True, help_text="Frontend URL for this company")
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
def save(self, *args, **kwargs):
|
|
if not self.slug:
|
|
self.slug = slugify(self.name)
|
|
|
|
# Generate frontend URL based on primary role
|
|
# CRITICAL: Only MANUFACTURER and DESIGNER are for rides domain
|
|
# OPERATOR and PROPERTY_OWNER are for parks domain and handled separately
|
|
if self.roles:
|
|
frontend_domain = getattr(
|
|
settings, "FRONTEND_DOMAIN", "https://thrillwiki.com"
|
|
)
|
|
primary_role = self.roles[0] # Use first role as primary
|
|
|
|
if primary_role == "MANUFACTURER":
|
|
self.url = f"{frontend_domain}/rides/manufacturers/{self.slug}/"
|
|
elif primary_role == "DESIGNER":
|
|
self.url = f"{frontend_domain}/rides/designers/{self.slug}/"
|
|
# OPERATOR and PROPERTY_OWNER URLs are handled by parks domain, not here
|
|
|
|
super().save(*args, **kwargs)
|
|
|
|
def get_absolute_url(self):
|
|
# This will need to be updated to handle different roles
|
|
return reverse("companies:detail", kwargs={"slug": self.slug})
|
|
|
|
@classmethod
|
|
def get_by_slug(cls, slug):
|
|
"""Get company by current or historical slug"""
|
|
try:
|
|
return cls.objects.get(slug=slug), False
|
|
except cls.DoesNotExist:
|
|
# Check pghistory first
|
|
try:
|
|
from django.apps import apps
|
|
history_model = apps.get_model('rides', f'{cls.__name__}Event')
|
|
history_entry = (
|
|
history_model.objects.filter(slug=slug)
|
|
.order_by("-pgh_created_at")
|
|
.first()
|
|
)
|
|
if history_entry:
|
|
return cls.objects.get(id=history_entry.pgh_obj_id), True
|
|
except LookupError:
|
|
# History model doesn't exist, skip pghistory check
|
|
pass
|
|
|
|
# Check manual slug history as fallback
|
|
try:
|
|
historical = HistoricalSlug.objects.get(
|
|
content_type__model="company", slug=slug
|
|
)
|
|
return cls.objects.get(pk=historical.object_id), True
|
|
except (HistoricalSlug.DoesNotExist, cls.DoesNotExist):
|
|
raise cls.DoesNotExist("No company found with this slug")
|
|
|
|
class Meta(TrackedModel.Meta):
|
|
app_label = "rides"
|
|
verbose_name = "Company"
|
|
verbose_name_plural = "Companies"
|
|
ordering = ["name"]
|