mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-01-02 00:07:02 -05:00
feat: Implement initial schema and add various API, service, and management command enhancements across the application.
This commit is contained in:
@@ -52,9 +52,7 @@ class Command(BaseCommand):
|
||||
park.name}: {
|
||||
photo.image.name}"
|
||||
)
|
||||
self.stdout.write(
|
||||
f"Database record created with ID: {photo.id}"
|
||||
)
|
||||
self.stdout.write(f"Database record created with ID: {photo.id}")
|
||||
else:
|
||||
self.stdout.write(
|
||||
f"Error downloading image. Status code: {
|
||||
@@ -112,9 +110,7 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
self.stdout.write(
|
||||
f"Error downloading ride photo: {str(e)}"
|
||||
)
|
||||
self.stdout.write(f"Error downloading ride photo: {str(e)}")
|
||||
|
||||
except Ride.DoesNotExist:
|
||||
self.stdout.write(
|
||||
|
||||
@@ -49,9 +49,7 @@ class Command(BaseCommand):
|
||||
if files:
|
||||
# Get the first file and update the database
|
||||
# record
|
||||
file_path = os.path.join(
|
||||
content_type, identifier, files[0]
|
||||
)
|
||||
file_path = os.path.join(content_type, identifier, files[0])
|
||||
if os.path.exists(os.path.join("media", file_path)):
|
||||
photo.image.name = file_path
|
||||
photo.save()
|
||||
@@ -111,9 +109,7 @@ class Command(BaseCommand):
|
||||
if files:
|
||||
# Get the first file and update the database
|
||||
# record
|
||||
file_path = os.path.join(
|
||||
content_type, identifier, files[0]
|
||||
)
|
||||
file_path = os.path.join(content_type, identifier, files[0])
|
||||
if os.path.exists(os.path.join("media", file_path)):
|
||||
photo.image.name = file_path
|
||||
photo.save()
|
||||
|
||||
@@ -37,9 +37,7 @@ class Command(BaseCommand):
|
||||
identifier = photo.park.slug
|
||||
|
||||
# Look for any files in that directory
|
||||
old_dir = os.path.join(
|
||||
settings.MEDIA_ROOT, content_type, identifier
|
||||
)
|
||||
old_dir = os.path.join(settings.MEDIA_ROOT, content_type, identifier)
|
||||
if os.path.exists(old_dir):
|
||||
files = [
|
||||
f
|
||||
@@ -83,9 +81,7 @@ class Command(BaseCommand):
|
||||
|
||||
# Move the file
|
||||
if current_path != new_full_path:
|
||||
shutil.copy2(
|
||||
current_path, new_full_path
|
||||
) # Use copy2 to preserve metadata
|
||||
shutil.copy2(current_path, new_full_path) # Use copy2 to preserve metadata
|
||||
processed_files.add(current_path)
|
||||
else:
|
||||
processed_files.add(current_path)
|
||||
@@ -116,9 +112,7 @@ class Command(BaseCommand):
|
||||
identifier = parts[1] # e.g., 'alton-towers'
|
||||
|
||||
# Look for any files in that directory
|
||||
old_dir = os.path.join(
|
||||
settings.MEDIA_ROOT, content_type, identifier
|
||||
)
|
||||
old_dir = os.path.join(settings.MEDIA_ROOT, content_type, identifier)
|
||||
if os.path.exists(old_dir):
|
||||
files = [
|
||||
f
|
||||
@@ -162,9 +156,7 @@ class Command(BaseCommand):
|
||||
|
||||
# Move the file
|
||||
if current_path != new_full_path:
|
||||
shutil.copy2(
|
||||
current_path, new_full_path
|
||||
) # Use copy2 to preserve metadata
|
||||
shutil.copy2(current_path, new_full_path) # Use copy2 to preserve metadata
|
||||
processed_files.add(current_path)
|
||||
else:
|
||||
processed_files.add(current_path)
|
||||
@@ -192,8 +184,6 @@ class Command(BaseCommand):
|
||||
os.remove(file_path)
|
||||
self.stdout.write(f"Removed old file: {file_path}")
|
||||
except Exception as e:
|
||||
self.stdout.write(
|
||||
f"Error removing {file_path}: {str(e)}"
|
||||
)
|
||||
self.stdout.write(f"Error removing {file_path}: {str(e)}")
|
||||
|
||||
self.stdout.write("Finished moving photo files and cleaning up")
|
||||
|
||||
@@ -23,10 +23,7 @@ class Photo(TrackedModel):
|
||||
|
||||
# The actual image
|
||||
image = models.ForeignKey(
|
||||
CloudflareImage,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="photos_usage",
|
||||
help_text="Cloudflare Image reference"
|
||||
CloudflareImage, on_delete=models.CASCADE, related_name="photos_usage", help_text="Cloudflare Image reference"
|
||||
)
|
||||
|
||||
# Generic relation to target object (Park, Ride, etc.)
|
||||
@@ -40,10 +37,7 @@ class Photo(TrackedModel):
|
||||
|
||||
# Metadata
|
||||
caption = models.CharField(max_length=255, blank=True, help_text="Photo caption")
|
||||
is_public = models.BooleanField(
|
||||
default=True,
|
||||
help_text="Whether this photo is visible to others"
|
||||
)
|
||||
is_public = models.BooleanField(default=True, help_text="Whether this photo is visible to others")
|
||||
|
||||
# We might want credit/source info if not taken by user
|
||||
source = models.CharField(max_length=100, blank=True, help_text="Source/Credit if applicable")
|
||||
|
||||
@@ -14,6 +14,7 @@ class CloudflareImageSerializer(serializers.ModelSerializer):
|
||||
model = CloudflareImage
|
||||
fields = ["id", "cloudflare_id", "variants"]
|
||||
|
||||
|
||||
class PhotoSerializer(serializers.ModelSerializer):
|
||||
user = UserSerializer(read_only=True)
|
||||
image = CloudflareImageSerializer(read_only=True)
|
||||
@@ -56,10 +57,10 @@ class PhotoSerializer(serializers.ModelSerializer):
|
||||
# Return public variant or default
|
||||
if obj.image:
|
||||
# Check if get_url method exists or we construct strictly
|
||||
return getattr(obj.image, 'get_url', lambda x: None)('public')
|
||||
return getattr(obj.image, "get_url", lambda x: None)("public")
|
||||
return None
|
||||
|
||||
def get_thumbnail(self, obj):
|
||||
if obj.image:
|
||||
return getattr(obj.image, 'get_url', lambda x: None)('thumbnail')
|
||||
return getattr(obj.image, "get_url", lambda x: None)("thumbnail")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user