Revert "Add version control system functionality with branch management, history tracking, and merge operations"

This reverts commit f3d28817a5.
This commit is contained in:
pacnpal
2025-02-08 17:37:30 -05:00
parent 03f9df4bab
commit 71b73522ae
125 changed files with 617 additions and 15830 deletions

View File

@@ -1,13 +1,7 @@
from django.db import models
from django.urls import reverse
from django.utils.text import slugify
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericRelation
from history_tracking.models import HistoricalModel, VersionBranch, ChangeSet
from history_tracking.signals import get_current_branch, ChangesetContextManager
from comments.mixins import CommentableMixin
from media.mixins import PhotoableModel
from reviews.mixins import ReviewableMixin
from history_tracking.models import HistoricalModel
# Shared choices that will be used by multiple models
@@ -22,8 +16,7 @@ CATEGORY_CHOICES = [
]
class RideModel(HistoricalModel, CommentableMixin, PhotoableModel):
comments = GenericRelation('comments.CommentThread') # Centralized reference
class RideModel(HistoricalModel):
"""
Represents a specific model/type of ride that can be manufactured by different companies.
For example: B&M Dive Coaster, Vekoma Boomerang, etc.
@@ -46,60 +39,15 @@ class RideModel(HistoricalModel, CommentableMixin, PhotoableModel):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ['manufacturer', 'name']
unique_together = ['manufacturer', 'name']
excluded_fields = ['comments'] # Exclude from historical tracking
def __str__(self) -> str:
return self.name if not self.manufacturer else f"{self.manufacturer.name} {self.name}"
def save(self, *args, **kwargs) -> None:
# Get the branch from context or use default
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
main_branch, _ = VersionBranch.objects.get_or_create(
name='main',
defaults={'metadata': {'type': 'default_branch'}}
)
with ChangesetContextManager(branch=main_branch):
super().save(*args, **kwargs)
def get_version_info(self) -> dict:
"""Get version control information for this ride model"""
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()
}
def get_absolute_url(self) -> str:
return reverse("rides:model_detail", kwargs={"pk": self.pk})
def __str__(self) -> str:
return self.name if not self.manufacturer else f"{self.manufacturer.name} {self.name}"
class Ride(HistoricalModel, CommentableMixin, PhotoableModel, ReviewableMixin):
comments = GenericRelation('comments.CommentThread') # Centralized reference
class Ride(HistoricalModel):
STATUS_CHOICES = [
('OPERATING', 'Operating'),
('SBNO', 'Standing But Not Operating'),
@@ -184,11 +132,12 @@ class Ride(HistoricalModel, CommentableMixin, PhotoableModel, ReviewableMixin):
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
photos = GenericRelation('media.Photo')
reviews = GenericRelation('reviews.Review')
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}"
@@ -196,66 +145,7 @@ class Ride(HistoricalModel, CommentableMixin, PhotoableModel, ReviewableMixin):
def save(self, *args, **kwargs) -> None:
if not self.slug:
self.slug = slugify(self.name)
# Get the branch from context or use default
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
main_branch, _ = VersionBranch.objects.get_or_create(
name='main',
defaults={'metadata': {'type': 'default_branch'}}
)
with ChangesetContextManager(branch=main_branch):
super().save(*args, **kwargs)
def get_version_info(self) -> dict:
"""Get version control information for this ride"""
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']
}
def get_absolute_url(self) -> str:
return reverse("rides:ride_detail", kwargs={
"park_slug": self.park.slug,
"ride_slug": self.slug
})
@classmethod
def get_by_slug(cls, slug: str) -> tuple['Ride', bool]:
"""Get ride by current or historical slug"""
try:
return cls.objects.get(slug=slug), False
except cls.DoesNotExist:
# Check historical slugs
history = cls.history.filter(slug=slug).order_by("-history_date").first()
if history:
try:
return cls.objects.get(pk=history.instance.pk), True
except cls.DoesNotExist as e:
raise cls.DoesNotExist("No ride found with this slug") from e
raise cls.DoesNotExist("No ride found with this slug")
super().save(*args, **kwargs)
class RollerCoasterStats(models.Model):