Files
thrillwiki_django_no_react/apps/rides/events.py
2025-09-21 20:19:12 -04:00

82 lines
2.7 KiB
Python

from typing import Dict
def get_ride_display_changes(changes: Dict) -> Dict:
"""Returns a human-readable version of the ride changes"""
field_names = {
"name": "Name",
"description": "Description",
"status": "Status",
"post_closing_status": "Post-Closing Status",
"opening_date": "Opening Date",
"closing_date": "Closing Date",
"status_since": "Status Since",
"capacity_per_hour": "Hourly Capacity",
"min_height_in": "Minimum Height",
"max_height_in": "Maximum Height",
"ride_duration_seconds": "Ride Duration",
}
display_changes = {}
for field, change in changes.items():
if field in field_names:
old_value = change.get("old", "")
new_value = change.get("new", "")
# Format specific fields
if field == "status":
from .choices import RIDE_STATUSES
choices = {choice.value: choice.label for choice in RIDE_STATUSES}
if old_value in choices:
old_value = choices[old_value]
if new_value in choices:
new_value = choices[new_value]
elif field == "post_closing_status":
from .choices import POST_CLOSING_STATUSES
choices = {choice.value: choice.label for choice in POST_CLOSING_STATUSES}
if old_value in choices:
old_value = choices[old_value]
if new_value in choices:
new_value = choices[new_value]
display_changes[field_names[field]] = {
"old": old_value,
"new": new_value,
}
return display_changes
def get_ride_model_display_changes(changes: Dict) -> Dict:
"""Returns a human-readable version of the ride model changes"""
field_names = {
"name": "Name",
"description": "Description",
"category": "Category",
}
display_changes = {}
for field, change in changes.items():
if field in field_names:
old_value = change.get("old", "")
new_value = change.get("new", "")
# Format category field
if field == "category":
from .choices import RIDE_CATEGORIES
choices = {choice.value: choice.label for choice in RIDE_CATEGORIES}
if old_value in choices:
old_value = choices[old_value]
if new_value in choices:
new_value = choices[new_value]
display_changes[field_names[field]] = {
"old": old_value,
"new": new_value,
}
return display_changes