mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 16:31:13 -05:00
87 lines
3.0 KiB
Python
87 lines
3.0 KiB
Python
"""
|
|
Company submission service for ThrillWiki.
|
|
|
|
Handles Company entity creation and updates through the Sacred Pipeline.
|
|
"""
|
|
|
|
import logging
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from apps.entities.models import Company
|
|
from apps.entities.services import BaseEntitySubmissionService
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class CompanySubmissionService(BaseEntitySubmissionService):
|
|
"""
|
|
Service for creating Company submissions through the Sacred Pipeline.
|
|
|
|
Companies represent manufacturers, operators, designers, and other entities
|
|
in the amusement industry.
|
|
|
|
Required fields:
|
|
- name: Company name
|
|
|
|
Known Issue:
|
|
- company_types is currently a JSONField but should be M2M relationship
|
|
TODO: Convert company_types from JSONField to Many-to-Many relationship
|
|
This violates the project rule: "NEVER use JSON/JSONB in SQL"
|
|
|
|
Example:
|
|
from apps.entities.services.company_submission import CompanySubmissionService
|
|
|
|
submission, company = CompanySubmissionService.create_entity_submission(
|
|
user=request.user,
|
|
data={
|
|
'name': 'Bolliger & Mabillard',
|
|
'company_types': ['manufacturer', 'designer'],
|
|
'description': 'Swiss roller coaster manufacturer...',
|
|
'website': 'https://www.bolliger-mabillard.com',
|
|
},
|
|
source='api'
|
|
)
|
|
"""
|
|
|
|
entity_model = Company
|
|
entity_type_name = 'Company'
|
|
required_fields = ['name']
|
|
|
|
@classmethod
|
|
def create_entity_submission(cls, user, data, **kwargs):
|
|
"""
|
|
Create a Company submission.
|
|
|
|
Note: The company_types field currently uses JSONField which violates
|
|
project standards. This should be converted to a proper M2M relationship.
|
|
|
|
Args:
|
|
user: User creating the company
|
|
data: Company field data (must include name)
|
|
**kwargs: Additional metadata (source, ip_address, user_agent)
|
|
|
|
Returns:
|
|
tuple: (ContentSubmission, Company or None)
|
|
"""
|
|
# TODO: Remove this warning once company_types is converted to M2M
|
|
if 'company_types' in data:
|
|
logger.warning(
|
|
"Company.company_types uses JSONField which violates project rules. "
|
|
"This should be converted to Many-to-Many relationship."
|
|
)
|
|
|
|
# Validate and normalize location FK if provided
|
|
location = data.get('location')
|
|
if location and isinstance(location, str):
|
|
try:
|
|
from apps.core.models import Locality
|
|
location = Locality.objects.get(id=location)
|
|
data['location'] = location
|
|
except:
|
|
raise ValidationError(f"Location not found: {location}")
|
|
|
|
# Create submission through base class
|
|
submission, company = super().create_entity_submission(user, data, **kwargs)
|
|
|
|
return submission, company
|