mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-22 03:11:08 -05:00
Revert "Add version control system functionality with branch management, history tracking, and merge operations"
This reverts commit 939eaed201.
This commit is contained in:
129
parks/models.py
129
parks/models.py
@@ -1,26 +1,21 @@
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.text import slugify
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
from django.core.exceptions import ValidationError
|
||||
from decimal import Decimal, ROUND_DOWN, InvalidOperation
|
||||
from typing import Tuple, Optional, Any, TYPE_CHECKING
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
|
||||
from companies.models import Company
|
||||
from history_tracking.signals import get_current_branch
|
||||
from media.models import Photo
|
||||
from history_tracking.models import HistoricalModel
|
||||
from location.models import Location
|
||||
from comments.mixins import CommentableMixin
|
||||
from media.mixins import PhotoableModel
|
||||
from location.mixins import LocationMixin
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from rides.models import Ride
|
||||
|
||||
|
||||
class Park(HistoricalModel, CommentableMixin, PhotoableModel, LocationMixin):
|
||||
comments = GenericRelation('comments.CommentThread') # Centralized reference
|
||||
class Park(HistoricalModel):
|
||||
id: int # Type hint for Django's automatic id field
|
||||
STATUS_CHOICES = [
|
||||
("OPERATING", "Operating"),
|
||||
@@ -38,6 +33,9 @@ class Park(HistoricalModel, CommentableMixin, PhotoableModel, LocationMixin):
|
||||
max_length=20, choices=STATUS_CHOICES, default="OPERATING"
|
||||
)
|
||||
|
||||
# Location fields using GenericRelation
|
||||
location = GenericRelation(Location, related_query_name='park')
|
||||
|
||||
# Details
|
||||
opening_date = models.DateField(null=True, blank=True)
|
||||
closing_date = models.DateField(null=True, blank=True)
|
||||
@@ -58,8 +56,8 @@ class Park(HistoricalModel, CommentableMixin, PhotoableModel, LocationMixin):
|
||||
owner = models.ForeignKey(
|
||||
Company, on_delete=models.SET_NULL, null=True, blank=True, related_name="parks"
|
||||
)
|
||||
photos = GenericRelation(Photo, related_query_name="park")
|
||||
areas: models.Manager['ParkArea'] # Type hint for reverse relation
|
||||
|
||||
rides: models.Manager['Ride'] # Type hint for reverse relation from rides app
|
||||
|
||||
# Metadata
|
||||
@@ -68,7 +66,6 @@ class Park(HistoricalModel, CommentableMixin, PhotoableModel, LocationMixin):
|
||||
|
||||
class Meta:
|
||||
ordering = ["name"]
|
||||
excluded_fields = ['comments'] # Exclude from historical tracking
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
@@ -76,54 +73,28 @@ class Park(HistoricalModel, CommentableMixin, PhotoableModel, LocationMixin):
|
||||
def save(self, *args: Any, **kwargs: Any) -> None:
|
||||
if not self.slug:
|
||||
self.slug = slugify(self.name)
|
||||
|
||||
# Get the branch from context or use default
|
||||
from history_tracking.signals import get_current_branch
|
||||
current_branch = get_current_branch()
|
||||
|
||||
if current_branch:
|
||||
# Save in the context of the current branch
|
||||
super().save(*args, **kwargs)
|
||||
else:
|
||||
# If no branch context, save in main branch
|
||||
from history_tracking.models import VersionBranch
|
||||
main_branch, _ = VersionBranch.objects.get_or_create(
|
||||
name='main',
|
||||
defaults={'metadata': {'type': 'default_branch'}}
|
||||
)
|
||||
|
||||
from history_tracking.signals import ChangesetContextManager
|
||||
with ChangesetContextManager(branch=main_branch):
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def get_version_info(self) -> dict:
|
||||
"""Get version control information for this park"""
|
||||
from history_tracking.models import VersionBranch, ChangeSet
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
content_type = ContentType.objects.get_for_model(self)
|
||||
latest_changes = ChangeSet.objects.filter(
|
||||
content_type=content_type,
|
||||
object_id=self.pk,
|
||||
status='applied'
|
||||
).order_by('-created_at')[:5]
|
||||
|
||||
active_branches = VersionBranch.objects.filter(
|
||||
changesets__content_type=content_type,
|
||||
changesets__object_id=self.pk,
|
||||
is_active=True
|
||||
).distinct()
|
||||
|
||||
return {
|
||||
'latest_changes': latest_changes,
|
||||
'active_branches': active_branches,
|
||||
'current_branch': get_current_branch(),
|
||||
'total_changes': latest_changes.count()
|
||||
}
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def get_absolute_url(self) -> str:
|
||||
return reverse("parks:park_detail", kwargs={"slug": self.slug})
|
||||
|
||||
@property
|
||||
def formatted_location(self) -> str:
|
||||
if self.location.exists():
|
||||
location = self.location.first()
|
||||
if location:
|
||||
return location.get_formatted_address()
|
||||
return ""
|
||||
|
||||
@property
|
||||
def coordinates(self) -> Optional[Tuple[float, float]]:
|
||||
"""Returns coordinates as a tuple (latitude, longitude)"""
|
||||
if self.location.exists():
|
||||
location = self.location.first()
|
||||
if location:
|
||||
return location.coordinates
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_by_slug(cls, slug: str) -> Tuple['Park', bool]:
|
||||
"""Get park by current or historical slug"""
|
||||
@@ -140,8 +111,7 @@ class Park(HistoricalModel, CommentableMixin, PhotoableModel, LocationMixin):
|
||||
raise cls.DoesNotExist("No park found with this slug")
|
||||
|
||||
|
||||
class ParkArea(HistoricalModel, CommentableMixin, PhotoableModel):
|
||||
comments = GenericRelation('comments.CommentThread') # Centralized reference
|
||||
class ParkArea(HistoricalModel):
|
||||
id: int # Type hint for Django's automatic id field
|
||||
park = models.ForeignKey(Park, on_delete=models.CASCADE, related_name="areas")
|
||||
name = models.CharField(max_length=255)
|
||||
@@ -150,8 +120,6 @@ class ParkArea(HistoricalModel, CommentableMixin, PhotoableModel):
|
||||
opening_date = models.DateField(null=True, blank=True)
|
||||
closing_date = models.DateField(null=True, blank=True)
|
||||
|
||||
# Relationships
|
||||
|
||||
# Metadata
|
||||
created_at = models.DateTimeField(auto_now_add=True, null=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
@@ -159,7 +127,6 @@ class ParkArea(HistoricalModel, CommentableMixin, PhotoableModel):
|
||||
class Meta:
|
||||
ordering = ["name"]
|
||||
unique_together = ["park", "slug"]
|
||||
excluded_fields = ['comments'] # Exclude from historical tracking
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name} at {self.park.name}"
|
||||
@@ -167,51 +134,7 @@ class ParkArea(HistoricalModel, CommentableMixin, PhotoableModel):
|
||||
def save(self, *args: Any, **kwargs: Any) -> None:
|
||||
if not self.slug:
|
||||
self.slug = slugify(self.name)
|
||||
|
||||
# Get the branch from context or use default
|
||||
from history_tracking.signals import get_current_branch
|
||||
current_branch = get_current_branch()
|
||||
|
||||
if current_branch:
|
||||
# Save in the context of the current branch
|
||||
super().save(*args, **kwargs)
|
||||
else:
|
||||
# If no branch context, save in main branch
|
||||
from history_tracking.models import VersionBranch
|
||||
main_branch, _ = VersionBranch.objects.get_or_create(
|
||||
name='main',
|
||||
defaults={'metadata': {'type': 'default_branch'}}
|
||||
)
|
||||
|
||||
from history_tracking.signals import ChangesetContextManager
|
||||
with ChangesetContextManager(branch=main_branch):
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def get_version_info(self) -> dict:
|
||||
"""Get version control information for this park area"""
|
||||
from history_tracking.models import VersionBranch, ChangeSet
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
content_type = ContentType.objects.get_for_model(self)
|
||||
latest_changes = ChangeSet.objects.filter(
|
||||
content_type=content_type,
|
||||
object_id=self.pk,
|
||||
status='applied'
|
||||
).order_by('-created_at')[:5]
|
||||
|
||||
active_branches = VersionBranch.objects.filter(
|
||||
changesets__content_type=content_type,
|
||||
changesets__object_id=self.pk,
|
||||
is_active=True
|
||||
).distinct()
|
||||
|
||||
return {
|
||||
'latest_changes': latest_changes,
|
||||
'active_branches': active_branches,
|
||||
'current_branch': get_current_branch(),
|
||||
'total_changes': latest_changes.count(),
|
||||
'parent_park_branch': self.park.get_version_info()['current_branch']
|
||||
}
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def get_absolute_url(self) -> str:
|
||||
return reverse(
|
||||
|
||||
@@ -1,200 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}{{ park.name }} - ThrillWiki{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container mx-auto px-4 py-8">
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
||||
<!-- Main Content Column -->
|
||||
<div class="lg:col-span-2">
|
||||
<!-- Version Control UI -->
|
||||
{% include "history_tracking/includes/version_control_ui.html" %}
|
||||
|
||||
<!-- Park Information -->
|
||||
<div class="bg-white rounded-lg shadow-sm p-6">
|
||||
<div class="flex justify-between items-start">
|
||||
<h1 class="text-3xl font-bold text-gray-900">{{ park.name }}</h1>
|
||||
<span class="px-3 py-1 rounded text-sm
|
||||
{% if park.status == 'OPERATING' %}
|
||||
bg-green-100 text-green-800
|
||||
{% elif park.status == 'CLOSED_TEMP' %}
|
||||
bg-yellow-100 text-yellow-800
|
||||
{% elif park.status == 'UNDER_CONSTRUCTION' %}
|
||||
bg-blue-100 text-blue-800
|
||||
{% else %}
|
||||
bg-red-100 text-red-800
|
||||
{% endif %}">
|
||||
{{ park.get_status_display }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{% if park.description %}
|
||||
<div class="mt-4 prose">
|
||||
{{ park.description|linebreaks }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Park Details -->
|
||||
<div class="mt-6 grid grid-cols-2 gap-4">
|
||||
{% if park.opening_date %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Opening Date</h3>
|
||||
<p class="mt-1">{{ park.opening_date }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if park.size_acres %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Size</h3>
|
||||
<p class="mt-1">{{ park.size_acres }} acres</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if park.operating_season %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Operating Season</h3>
|
||||
<p class="mt-1">{{ park.operating_season }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if park.owner %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Owner</h3>
|
||||
<p class="mt-1">
|
||||
<a href="{{ park.owner.get_absolute_url }}" class="text-blue-600 hover:underline">
|
||||
{{ park.owner.name }}
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Rides Section -->
|
||||
<div class="mt-8">
|
||||
<h2 class="text-2xl font-bold text-gray-900 mb-4">Rides</h2>
|
||||
{% if park.rides.all %}
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{% for ride in park.rides.all %}
|
||||
<div class="bg-white rounded-lg shadow-sm p-4">
|
||||
<h3 class="text-lg font-semibold">
|
||||
<a href="{{ ride.get_absolute_url }}" class="text-blue-600 hover:underline">
|
||||
{{ ride.name }}
|
||||
</a>
|
||||
</h3>
|
||||
<p class="text-sm text-gray-600 mt-1">{{ ride.type }}</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="text-gray-600">No rides listed yet.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Areas Section -->
|
||||
{% if park.areas.exists %}
|
||||
<div class="mt-8">
|
||||
<h2 class="text-2xl font-bold text-gray-900 mb-4">Areas</h2>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{% for area in park.areas.all %}
|
||||
<div class="bg-white rounded-lg shadow-sm p-4">
|
||||
<h3 class="text-lg font-semibold">
|
||||
<a href="{{ area.get_absolute_url }}" class="text-blue-600 hover:underline">
|
||||
{{ area.name }}
|
||||
</a>
|
||||
</h3>
|
||||
{% if area.description %}
|
||||
<p class="text-sm text-gray-600 mt-1">{{ area.description|truncatewords:20 }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<div class="lg:col-span-1">
|
||||
<!-- Location -->
|
||||
{% if park.formatted_location %}
|
||||
<div class="bg-white rounded-lg shadow-sm p-6 mb-6">
|
||||
<h2 class="text-lg font-semibold mb-3">Location</h2>
|
||||
<p>{{ park.formatted_location }}</p>
|
||||
{% if park.coordinates %}
|
||||
<div id="map"
|
||||
class="h-64 mt-4 rounded-lg"
|
||||
data-lat="{{ park.coordinates.0|stringformat:'f' }}"
|
||||
data-lng="{{ park.coordinates.1|stringformat:'f' }}"
|
||||
data-name="{{ park.name|escapejs }}">
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Statistics -->
|
||||
<div class="bg-white rounded-lg shadow-sm p-6 mb-6">
|
||||
<h2 class="text-lg font-semibold mb-3">Statistics</h2>
|
||||
<div class="space-y-3">
|
||||
{% if park.average_rating %}
|
||||
<div>
|
||||
<span class="text-gray-600">Average Rating:</span>
|
||||
<span class="font-medium">{{ park.average_rating }}/5</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if park.ride_count %}
|
||||
<div>
|
||||
<span class="text-gray-600">Total Rides:</span>
|
||||
<span class="font-medium">{{ park.ride_count }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if park.coaster_count %}
|
||||
<div>
|
||||
<span class="text-gray-600">Roller Coasters:</span>
|
||||
<span class="font-medium">{{ park.coaster_count }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Photo Gallery -->
|
||||
{% if park.photos.exists %}
|
||||
<div class="bg-white rounded-lg shadow-sm p-6">
|
||||
<h2 class="text-lg font-semibold mb-3" id="photo-gallery">Photo Gallery</h2>
|
||||
<ul class="grid grid-cols-2 gap-2 list-none p-0"
|
||||
aria-labelledby="photo-gallery">
|
||||
{% for photo in park.photos.all|slice:":4" %}
|
||||
<li class="aspect-w-1 aspect-h-1">
|
||||
<img src="{{ photo.image.url }}"
|
||||
alt="{% if photo.title %}{{ photo.title }} at {% endif %}{{ park.name }}"
|
||||
class="object-cover rounded"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
fetchpriority="low"
|
||||
width="300"
|
||||
height="300">
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% if park.photos.count > 4 %}
|
||||
<a href="{% url 'photos:park-gallery' park.slug %}"
|
||||
class="text-blue-600 hover:underline text-sm block mt-3"
|
||||
aria-label="View full photo gallery of {{ park.name }}">
|
||||
View all {{ park.photos.count }} photos
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
{{ block.super }}
|
||||
{% if park.coordinates %}
|
||||
<script src="{% static 'js/map-init.js' %}"></script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user