Refactor code structure and remove redundant changes

This commit is contained in:
pacnpal
2025-08-26 13:19:04 -04:00
parent bf7e0c0f40
commit 831be6a2ee
151 changed files with 16260 additions and 9137 deletions

View File

@@ -3,26 +3,46 @@ from django.db.models.signals import post_migrate
def create_photo_permissions(sender, **kwargs):
"""Create custom permissions for photos"""
"""Create custom permissions for domain-specific photo models"""
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from media.models import Photo
from parks.models import ParkPhoto
from rides.models import RidePhoto
content_type = ContentType.objects.get_for_model(Photo)
# Create permissions for ParkPhoto
park_photo_content_type = ContentType.objects.get_for_model(ParkPhoto)
Permission.objects.get_or_create(
codename="add_photo",
name="Can add photo",
content_type=content_type,
codename="add_parkphoto",
name="Can add park photo",
content_type=park_photo_content_type,
)
Permission.objects.get_or_create(
codename="change_photo",
name="Can change photo",
content_type=content_type,
codename="change_parkphoto",
name="Can change park photo",
content_type=park_photo_content_type,
)
Permission.objects.get_or_create(
codename="delete_photo",
name="Can delete photo",
content_type=content_type,
codename="delete_parkphoto",
name="Can delete park photo",
content_type=park_photo_content_type,
)
# Create permissions for RidePhoto
ride_photo_content_type = ContentType.objects.get_for_model(RidePhoto)
Permission.objects.get_or_create(
codename="add_ridephoto",
name="Can add ride photo",
content_type=ride_photo_content_type,
)
Permission.objects.get_or_create(
codename="change_ridephoto",
name="Can change ride photo",
content_type=ride_photo_content_type,
)
Permission.objects.get_or_create(
codename="delete_ridephoto",
name="Can delete ride photo",
content_type=ride_photo_content_type,
)

View File

@@ -1,15 +1,13 @@
import requests
from django.core.management.base import BaseCommand
from media.models import Photo
from parks.models import Park
from rides.models import Ride
from django.contrib.contenttypes.models import ContentType
from apps.parks.models import Park, ParkPhoto
from apps.rides.models import Ride, RidePhoto
import json
from django.core.files.base import ContentFile
class Command(BaseCommand):
help = "Download photos from seed data URLs"
help = "Download photos from seed data URLs for domain-specific photo models"
def handle(self, *args, **kwargs):
self.stdout.write("Downloading photos from seed data...")
@@ -18,9 +16,6 @@ class Command(BaseCommand):
with open("parks/management/commands/seed_data.json", "r") as f:
seed_data = json.load(f)
park_content_type = ContentType.objects.get_for_model(Park)
ride_content_type = ContentType.objects.get_for_model(Ride)
# Process parks and their photos
for park_data in seed_data["parks"]:
try:
@@ -34,15 +29,11 @@ class Command(BaseCommand):
response = requests.get(photo_url, timeout=60)
if response.status_code == 200:
# Delete any existing photos for this park
Photo.objects.filter(
content_type=park_content_type,
object_id=park.id,
).delete()
ParkPhoto.objects.filter(park=park).delete()
# Create new photo record
photo = Photo(
content_type=park_content_type,
object_id=park.id,
photo = ParkPhoto(
park=park,
is_primary=idx == 1,
)
@@ -87,15 +78,11 @@ class Command(BaseCommand):
response = requests.get(photo_url, timeout=60)
if response.status_code == 200:
# Delete any existing photos for this ride
Photo.objects.filter(
content_type=ride_content_type,
object_id=ride.id,
).delete()
RidePhoto.objects.filter(ride=ride).delete()
# Create new photo record
photo = Photo(
content_type=ride_content_type,
object_id=ride.id,
photo = RidePhoto(
ride=ride,
is_primary=idx == 1,
)

View File

@@ -1,17 +1,20 @@
import os
from django.core.management.base import BaseCommand
from media.models import Photo
from apps.parks.models import ParkPhoto
from apps.rides.models import RidePhoto
from django.db import transaction
class Command(BaseCommand):
help = "Fix photo paths in database to match actual file locations"
help = "Fix photo paths in database to match actual file locations for domain-specific photos"
def handle(self, *args, **kwargs):
self.stdout.write("Fixing photo paths in database...")
# Get all photos
photos = Photo.objects.all()
# Get all domain-specific photos
park_photos = ParkPhoto.objects.all()
ride_photos = RidePhoto.objects.all()
photos = list(park_photos) + list(ride_photos)
for photo in photos:
try:

View File

@@ -1,18 +1,21 @@
import os
from django.core.management.base import BaseCommand
from media.models import Photo
from apps.parks.models import ParkPhoto
from apps.rides.models import RidePhoto
from django.conf import settings
import shutil
class Command(BaseCommand):
help = "Move photo files to their normalized locations"
help = "Move photo files to their normalized locations for domain-specific photos"
def handle(self, *args, **kwargs):
self.stdout.write("Moving photo files to normalized locations...")
# Get all photos
photos = Photo.objects.all()
# Get all domain-specific photos
park_photos = ParkPhoto.objects.all()
ride_photos = RidePhoto.objects.all()
photos = list(park_photos) + list(ride_photos)
# Track processed files to clean up later
processed_files = set()
@@ -56,12 +59,17 @@ class Command(BaseCommand):
obj = photo.content_object
identifier = getattr(obj, "slug", obj.id)
# Get photo number
photo_number = Photo.objects.filter(
content_type=photo.content_type,
object_id=photo.object_id,
created_at__lte=photo.created_at,
).count()
# Get photo number based on photo type
if isinstance(photo, ParkPhoto):
photo_number = ParkPhoto.objects.filter(
park=photo.park,
created_at__lte=photo.created_at,
).count()
else: # RidePhoto
photo_number = RidePhoto.objects.filter(
ride=photo.ride,
created_at__lte=photo.created_at,
).count()
# Create new filename
_, ext = os.path.splitext(current_path)