mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 02:11:08 -05:00
- Implemented PrimeProgress component with support for labels, helper text, and various styles (size, variant, color). - Created PrimeSelect component with dropdown functionality, custom templates, and validation states. - Developed PrimeSkeleton component for loading placeholders with different shapes and animations. - Updated index.ts to export new components for easy import. - Enhanced PrimeVueTest.vue to include tests for new components and their functionalities. - Introduced a custom ThrillWiki theme for PrimeVue with tailored color schemes and component styles. - Added ambient type declarations for various components to improve TypeScript support.
176 lines
4.6 KiB
Python
176 lines
4.6 KiB
Python
"""
|
|
Park media serializers for ThrillWiki API v1.
|
|
|
|
This module contains serializers for park-specific media functionality.
|
|
Enhanced from rogue implementation to maintain full feature parity.
|
|
"""
|
|
|
|
from rest_framework import serializers
|
|
from drf_spectacular.utils import extend_schema_field
|
|
from apps.parks.models import Park, ParkPhoto
|
|
|
|
|
|
class ParkPhotoOutputSerializer(serializers.ModelSerializer):
|
|
"""Enhanced output serializer for park photos with rich field structure."""
|
|
|
|
uploaded_by_username = serializers.CharField(
|
|
source="uploaded_by.username", read_only=True
|
|
)
|
|
|
|
file_size = serializers.SerializerMethodField()
|
|
dimensions = serializers.SerializerMethodField()
|
|
|
|
@extend_schema_field(
|
|
serializers.IntegerField(allow_null=True, help_text="File size in bytes")
|
|
)
|
|
def get_file_size(self, obj):
|
|
"""Get file size in bytes."""
|
|
return obj.file_size
|
|
|
|
@extend_schema_field(
|
|
serializers.ListField(
|
|
child=serializers.IntegerField(),
|
|
min_length=2,
|
|
max_length=2,
|
|
allow_null=True,
|
|
help_text="Image dimensions as [width, height] in pixels",
|
|
)
|
|
)
|
|
def get_dimensions(self, obj):
|
|
"""Get image dimensions as [width, height]."""
|
|
return obj.dimensions
|
|
|
|
park_slug = serializers.CharField(source="park.slug", read_only=True)
|
|
park_name = serializers.CharField(source="park.name", read_only=True)
|
|
|
|
class Meta:
|
|
model = ParkPhoto
|
|
fields = [
|
|
"id",
|
|
"image",
|
|
"caption",
|
|
"alt_text",
|
|
"is_primary",
|
|
"is_approved",
|
|
"created_at",
|
|
"updated_at",
|
|
"date_taken",
|
|
"uploaded_by_username",
|
|
"file_size",
|
|
"dimensions",
|
|
"park_slug",
|
|
"park_name",
|
|
]
|
|
read_only_fields = [
|
|
"id",
|
|
"created_at",
|
|
"updated_at",
|
|
"uploaded_by_username",
|
|
"file_size",
|
|
"dimensions",
|
|
"park_slug",
|
|
"park_name",
|
|
]
|
|
|
|
|
|
class ParkPhotoCreateInputSerializer(serializers.ModelSerializer):
|
|
"""Input serializer for creating park photos."""
|
|
|
|
class Meta:
|
|
model = ParkPhoto
|
|
fields = [
|
|
"image",
|
|
"caption",
|
|
"alt_text",
|
|
"is_primary",
|
|
]
|
|
|
|
|
|
class ParkPhotoUpdateInputSerializer(serializers.ModelSerializer):
|
|
"""Input serializer for updating park photos."""
|
|
|
|
class Meta:
|
|
model = ParkPhoto
|
|
fields = [
|
|
"caption",
|
|
"alt_text",
|
|
"is_primary",
|
|
]
|
|
|
|
|
|
class ParkPhotoListOutputSerializer(serializers.ModelSerializer):
|
|
"""Optimized output serializer for park photo lists."""
|
|
|
|
uploaded_by_username = serializers.CharField(
|
|
source="uploaded_by.username", read_only=True
|
|
)
|
|
|
|
class Meta:
|
|
model = ParkPhoto
|
|
fields = [
|
|
"id",
|
|
"image",
|
|
"caption",
|
|
"is_primary",
|
|
"is_approved",
|
|
"created_at",
|
|
"uploaded_by_username",
|
|
]
|
|
read_only_fields = fields
|
|
|
|
|
|
class ParkPhotoApprovalInputSerializer(serializers.Serializer):
|
|
"""Input serializer for bulk photo approval operations."""
|
|
|
|
photo_ids = serializers.ListField(
|
|
child=serializers.IntegerField(), help_text="List of photo IDs to approve"
|
|
)
|
|
approve = serializers.BooleanField(
|
|
default=True, help_text="Whether to approve (True) or reject (False) the photos"
|
|
)
|
|
|
|
|
|
class ParkPhotoStatsOutputSerializer(serializers.Serializer):
|
|
"""Output serializer for park photo statistics."""
|
|
|
|
total_photos = serializers.IntegerField()
|
|
approved_photos = serializers.IntegerField()
|
|
pending_photos = serializers.IntegerField()
|
|
has_primary = serializers.BooleanField()
|
|
recent_uploads = serializers.IntegerField()
|
|
|
|
|
|
# Legacy serializers for backwards compatibility
|
|
class ParkPhotoSerializer(serializers.ModelSerializer):
|
|
"""Legacy serializer for the ParkPhoto model - maintained for compatibility."""
|
|
|
|
class Meta:
|
|
model = ParkPhoto
|
|
fields = (
|
|
"id",
|
|
"image",
|
|
"caption",
|
|
"alt_text",
|
|
"is_primary",
|
|
"uploaded_at",
|
|
"uploaded_by",
|
|
)
|
|
|
|
|
|
class ParkSerializer(serializers.ModelSerializer):
|
|
"""Serializer for the Park model."""
|
|
|
|
class Meta:
|
|
model = Park
|
|
fields = (
|
|
"id",
|
|
"name",
|
|
"slug",
|
|
"country",
|
|
"continent",
|
|
"latitude",
|
|
"longitude",
|
|
"website",
|
|
"status",
|
|
)
|