mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-21 22:51:08 -05:00
Add OWASP compliance mapping and security test case templates, and document version control implementation phases
This commit is contained in:
112
rides/models.py
112
rides/models.py
@@ -1,7 +1,10 @@
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.text import slugify
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
from history_tracking.models import HistoricalModel
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from history_tracking.models import HistoricalModel, VersionBranch, ChangeSet
|
||||
from history_tracking.signals import get_current_branch, ChangesetContextManager
|
||||
|
||||
|
||||
# Shared choices that will be used by multiple models
|
||||
@@ -42,9 +45,51 @@ class RideModel(HistoricalModel):
|
||||
class Meta:
|
||||
ordering = ['manufacturer', 'name']
|
||||
unique_together = ['manufacturer', 'name']
|
||||
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):
|
||||
@@ -145,7 +190,66 @@ class Ride(HistoricalModel):
|
||||
def save(self, *args, **kwargs) -> None:
|
||||
if not self.slug:
|
||||
self.slug = slugify(self.name)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
# 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")
|
||||
|
||||
|
||||
class RollerCoasterStats(models.Model):
|
||||
|
||||
220
rides/templates/rides/ride_detail.html
Normal file
220
rides/templates/rides/ride_detail.html
Normal file
@@ -0,0 +1,220 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}{{ ride.name }} at {{ ride.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" %}
|
||||
|
||||
<!-- Ride 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">{{ ride.name }}</h1>
|
||||
<span class="px-3 py-1 rounded text-sm
|
||||
{% if ride.status == 'OPERATING' %}
|
||||
bg-green-100 text-green-800
|
||||
{% elif ride.status == 'SBNO' %}
|
||||
bg-yellow-100 text-yellow-800
|
||||
{% elif ride.status == 'UNDER_CONSTRUCTION' %}
|
||||
bg-blue-100 text-blue-800
|
||||
{% else %}
|
||||
bg-red-100 text-red-800
|
||||
{% endif %}">
|
||||
{{ ride.get_status_display }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{% if ride.description %}
|
||||
<div class="mt-4 prose">
|
||||
{{ ride.description|linebreaks }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Ride Details -->
|
||||
<div class="mt-6 grid grid-cols-2 gap-4">
|
||||
{% if ride.opening_date %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Opening Date</h3>
|
||||
<p class="mt-1">{{ ride.opening_date }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.manufacturer %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Manufacturer</h3>
|
||||
<p class="mt-1">
|
||||
<a href="{{ ride.manufacturer.get_absolute_url }}" class="text-blue-600 hover:underline">
|
||||
{{ ride.manufacturer.name }}
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.designer %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Designer</h3>
|
||||
<p class="mt-1">
|
||||
<a href="{{ ride.designer.get_absolute_url }}" class="text-blue-600 hover:underline">
|
||||
{{ ride.designer.name }}
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.ride_model %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Ride Model</h3>
|
||||
<p class="mt-1">{{ ride.ride_model.name }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.park_area %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Location</h3>
|
||||
<p class="mt-1">
|
||||
<a href="{{ ride.park_area.get_absolute_url }}" class="text-blue-600 hover:underline">
|
||||
{{ ride.park_area.name }}
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.capacity_per_hour %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Hourly Capacity</h3>
|
||||
<p class="mt-1">{{ ride.capacity_per_hour }} riders/hour</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.ride_duration_seconds %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Ride Duration</h3>
|
||||
<p class="mt-1">{{ ride.ride_duration_seconds }} seconds</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Roller Coaster Stats -->
|
||||
{% if ride.coaster_stats %}
|
||||
<div class="mt-8 bg-white rounded-lg shadow-sm p-6">
|
||||
<h2 class="text-2xl font-bold text-gray-900 mb-4">Coaster Statistics</h2>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{% if ride.coaster_stats.height_ft %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Height</h3>
|
||||
<p class="mt-1">{{ ride.coaster_stats.height_ft }} ft</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.coaster_stats.length_ft %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Length</h3>
|
||||
<p class="mt-1">{{ ride.coaster_stats.length_ft }} ft</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.coaster_stats.speed_mph %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Speed</h3>
|
||||
<p class="mt-1">{{ ride.coaster_stats.speed_mph }} mph</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.coaster_stats.inversions %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Inversions</h3>
|
||||
<p class="mt-1">{{ ride.coaster_stats.inversions }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.coaster_stats.track_material %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Track Material</h3>
|
||||
<p class="mt-1">{{ ride.coaster_stats.get_track_material_display }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.coaster_stats.roller_coaster_type %}
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-500">Type</h3>
|
||||
<p class="mt-1">{{ ride.coaster_stats.get_roller_coaster_type_display }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<div class="lg:col-span-1">
|
||||
<!-- Park Location -->
|
||||
<div class="bg-white rounded-lg shadow-sm p-6 mb-6">
|
||||
<h2 class="text-lg font-semibold mb-3">Location</h2>
|
||||
<p>
|
||||
<a href="{{ ride.park.get_absolute_url }}" class="text-blue-600 hover:underline">
|
||||
{{ ride.park.name }}
|
||||
</a>
|
||||
</p>
|
||||
{% if ride.park.formatted_location %}
|
||||
<p class="text-gray-600 mt-2">{{ ride.park.formatted_location }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- 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 ride.average_rating %}
|
||||
<div>
|
||||
<span class="text-gray-600">Average Rating:</span>
|
||||
<span class="font-medium">{{ ride.average_rating }}/5</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.reviews.count %}
|
||||
<div>
|
||||
<span class="text-gray-600">Reviews:</span>
|
||||
<span class="font-medium">{{ ride.reviews.count }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Photo Gallery -->
|
||||
{% if ride.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 ride.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 %}{{ ride.name }}"
|
||||
class="object-cover rounded"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
fetchpriority="low"
|
||||
width="300"
|
||||
height="300">
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% if ride.photos.count > 4 %}
|
||||
<a href="{% url 'photos:ride-gallery' ride.park.slug ride.slug %}"
|
||||
class="text-blue-600 hover:underline text-sm block mt-3"
|
||||
aria-label="View full photo gallery of {{ ride.name }}">
|
||||
View all {{ ride.photos.count }} photos
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
153
rides/templates/rides/ride_list.html
Normal file
153
rides/templates/rides/ride_list.html
Normal file
@@ -0,0 +1,153 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Rides - ThrillWiki{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container mx-auto px-4 py-8">
|
||||
<!-- Version Control UI -->
|
||||
{% include "history_tracking/includes/version_control_ui.html" %}
|
||||
|
||||
<div class="mb-8">
|
||||
<h1 class="text-3xl font-bold text-gray-900">Rides</h1>
|
||||
{% if park %}
|
||||
<p class="text-gray-600 mt-2">Rides at {{ park.name }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="bg-white rounded-lg shadow-sm p-4 mb-6">
|
||||
<form method="get" class="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label for="category" class="block text-sm font-medium text-gray-700">Category</label>
|
||||
<select name="category" id="category" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm">
|
||||
<option value="">All Categories</option>
|
||||
{% for code, name in category_choices %}
|
||||
<option value="{{ code }}" {% if category == code %}selected{% endif %}>{{ name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="status" class="block text-sm font-medium text-gray-700">Status</label>
|
||||
<select name="status" id="status" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm">
|
||||
<option value="">All Statuses</option>
|
||||
{% for code, name in status_choices %}
|
||||
<option value="{{ code }}" {% if status == code %}selected{% endif %}>{{ name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="manufacturer" class="block text-sm font-medium text-gray-700">Manufacturer</label>
|
||||
<select name="manufacturer" id="manufacturer" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm">
|
||||
<option value="">All Manufacturers</option>
|
||||
{% for m in manufacturers %}
|
||||
<option value="{{ m.id }}" {% if manufacturer == m.id %}selected{% endif %}>{{ m.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex items-end">
|
||||
<button type="submit" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded">
|
||||
Apply Filters
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Rides Grid -->
|
||||
{% if rides %}
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{% for ride in rides %}
|
||||
<div class="bg-white rounded-lg shadow-sm overflow-hidden">
|
||||
{% if ride.photos.exists %}
|
||||
<div class="aspect-w-16 aspect-h-9">
|
||||
<img src="{{ ride.photos.first.image.url }}"
|
||||
alt="{{ ride.name }}"
|
||||
class="object-cover w-full h-full"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
fetchpriority="low">
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="p-4">
|
||||
<div class="flex justify-between items-start mb-2">
|
||||
<h2 class="text-xl font-semibold">
|
||||
<a href="{{ ride.get_absolute_url }}" class="text-blue-600 hover:underline">
|
||||
{{ ride.name }}
|
||||
</a>
|
||||
</h2>
|
||||
<span class="px-2 py-1 text-xs rounded
|
||||
{% if ride.status == 'OPERATING' %}
|
||||
bg-green-100 text-green-800
|
||||
{% elif ride.status == 'SBNO' %}
|
||||
bg-yellow-100 text-yellow-800
|
||||
{% elif ride.status == 'UNDER_CONSTRUCTION' %}
|
||||
bg-blue-100 text-blue-800
|
||||
{% else %}
|
||||
bg-red-100 text-red-800
|
||||
{% endif %}">
|
||||
{{ ride.get_status_display }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{% if ride.park %}
|
||||
<p class="text-gray-600 text-sm mb-2">
|
||||
<a href="{{ ride.park.get_absolute_url }}" class="hover:underline">
|
||||
{{ ride.park.name }}
|
||||
</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.manufacturer %}
|
||||
<p class="text-gray-600 text-sm mb-2">
|
||||
{{ ride.manufacturer.name }}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if ride.description %}
|
||||
<p class="text-gray-600 text-sm">{{ ride.description|truncatewords:30 }}</p>
|
||||
{% endif %}
|
||||
|
||||
<!-- Version Control Status -->
|
||||
{% with version_info=ride.get_version_info %}
|
||||
{% if version_info.active_branches.count > 1 %}
|
||||
<div class="mt-3 text-sm">
|
||||
<span class="text-yellow-600">
|
||||
{{ version_info.active_branches.count }} active branches
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
{% if is_paginated %}
|
||||
<div class="mt-8 flex justify-center">
|
||||
<nav class="inline-flex rounded-md shadow">
|
||||
{% if page_obj.has_previous %}
|
||||
<a href="?page={{ page_obj.previous_page_number }}{% if request.GET.category %}&category={{ request.GET.category }}{% endif %}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.manufacturer %}&manufacturer={{ request.GET.manufacturer }}{% endif %}"
|
||||
class="px-3 py-2 rounded-l-md border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50">
|
||||
Previous
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% if page_obj.has_next %}
|
||||
<a href="?page={{ page_obj.next_page_number }}{% if request.GET.category %}&category={{ request.GET.category }}{% endif %}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.manufacturer %}&manufacturer={{ request.GET.manufacturer }}{% endif %}"
|
||||
class="px-3 py-2 rounded-r-md border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50">
|
||||
Next
|
||||
</a>
|
||||
{% endif %}
|
||||
</nav>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<div class="text-center py-12">
|
||||
<p class="text-gray-600">No rides found matching your criteria.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user