mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-25 21:11:14 -05:00
Implement entity submission services for ThrillWiki
- Added BaseEntitySubmissionService as an abstract base for entity submissions. - Created specific submission services for entities: Park, Ride, Company, RideModel. - Implemented create, update, and delete functionalities with moderation workflow. - Enhanced logging and validation for required fields. - Addressed foreign key handling and special field processing for each entity type. - Noted existing issues with JSONField usage in Company submissions.
This commit is contained in:
89
django/apps/entities/services/park_submission.py
Normal file
89
django/apps/entities/services/park_submission.py
Normal file
@@ -0,0 +1,89 @@
|
||||
"""
|
||||
Park submission service for ThrillWiki.
|
||||
|
||||
Handles Park entity creation and updates through the Sacred Pipeline.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from decimal import Decimal
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from apps.entities.models import Park
|
||||
from apps.entities.services import BaseEntitySubmissionService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ParkSubmissionService(BaseEntitySubmissionService):
|
||||
"""
|
||||
Service for creating Park submissions through the Sacred Pipeline.
|
||||
|
||||
Parks require special handling for:
|
||||
- Geographic coordinates (latitude/longitude)
|
||||
- Location point (PostGIS in production)
|
||||
- Park type and status fields
|
||||
|
||||
Required fields:
|
||||
- name: Park name
|
||||
- park_type: Type of park (theme_park, amusement_park, etc.)
|
||||
|
||||
Example:
|
||||
from apps.entities.services.park_submission import ParkSubmissionService
|
||||
|
||||
submission, park = ParkSubmissionService.create_entity_submission(
|
||||
user=request.user,
|
||||
data={
|
||||
'name': 'Cedar Point',
|
||||
'park_type': 'theme_park',
|
||||
'status': 'operating',
|
||||
'latitude': Decimal('41.4792'),
|
||||
'longitude': Decimal('-82.6839'),
|
||||
'description': 'Legendary amusement park...',
|
||||
},
|
||||
source='api',
|
||||
ip_address=request.META.get('REMOTE_ADDR')
|
||||
)
|
||||
"""
|
||||
|
||||
entity_model = Park
|
||||
entity_type_name = 'Park'
|
||||
required_fields = ['name', 'park_type']
|
||||
|
||||
@classmethod
|
||||
def create_entity_submission(cls, user, data, **kwargs):
|
||||
"""
|
||||
Create a Park submission with special coordinate handling.
|
||||
|
||||
Coordinates (latitude/longitude) are processed using the Park model's
|
||||
set_location() method which handles both SQLite and PostGIS modes.
|
||||
|
||||
Args:
|
||||
user: User creating the park
|
||||
data: Park field data (must include name and park_type)
|
||||
**kwargs: Additional metadata (source, ip_address, user_agent)
|
||||
|
||||
Returns:
|
||||
tuple: (ContentSubmission, Park or None)
|
||||
"""
|
||||
# Extract coordinates for special handling
|
||||
latitude = data.get('latitude')
|
||||
longitude = data.get('longitude')
|
||||
|
||||
# Create submission through base class
|
||||
submission, park = super().create_entity_submission(user, data, **kwargs)
|
||||
|
||||
# If park was created (moderator bypass), set location using helper method
|
||||
if park and latitude is not None and longitude is not None:
|
||||
try:
|
||||
park.set_location(float(longitude), float(latitude))
|
||||
park.save()
|
||||
logger.info(
|
||||
f"Park {park.id} location set: "
|
||||
f"({latitude}, {longitude})"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Failed to set location for Park {park.id}: {str(e)}"
|
||||
)
|
||||
|
||||
return submission, park
|
||||
Reference in New Issue
Block a user