Stage 1 migration and docs complete
This commit is contained in:
@@ -16,9 +16,8 @@ from .serializers import (
|
||||
ImagesSerializer,
|
||||
ContentSerializer,
|
||||
ContentTaxonomySerializer,
|
||||
# ContentAttributeSerializer removed in Stage 1 - model no longer exists
|
||||
)
|
||||
from igny8_core.business.content.models import ContentTaxonomy # ContentAttribute removed in Stage 1
|
||||
from igny8_core.business.content.models import ContentTaxonomy # ContentAttribute model exists but serializer removed in Stage 1
|
||||
from igny8_core.business.content.services.content_generation_service import ContentGenerationService
|
||||
from igny8_core.business.content.services.validation_service import ContentValidationService
|
||||
from igny8_core.business.content.services.metadata_mapping_service import MetadataMappingService
|
||||
@@ -544,49 +543,19 @@ class ImagesViewSet(SiteSectorModelViewSet):
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
# Also get content from images linked via task
|
||||
task_linked_images = Images.objects.filter(task__isnull=False, content__isnull=True)
|
||||
if account:
|
||||
task_linked_images = task_linked_images.filter(account=account)
|
||||
|
||||
# Apply site/sector filtering to task-linked images
|
||||
if site_id:
|
||||
try:
|
||||
task_linked_images = task_linked_images.filter(site_id=int(site_id))
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
if sector_id:
|
||||
try:
|
||||
task_linked_images = task_linked_images.filter(sector_id=int(sector_id))
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
# Get content IDs from task-linked images
|
||||
task_content_ids = set()
|
||||
for image in task_linked_images:
|
||||
if image.task and hasattr(image.task, 'content_record'):
|
||||
try:
|
||||
content = image.task.content_record
|
||||
if content:
|
||||
task_content_ids.add(content.id)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Combine both sets of content IDs
|
||||
content_ids = set(queryset.values_list('id', flat=True).distinct())
|
||||
content_ids.update(task_content_ids)
|
||||
# Task field removed in Stage 1 - images are now only linked to content directly
|
||||
# All images must be linked via content, not task
|
||||
|
||||
# Build grouped response
|
||||
grouped_data = []
|
||||
content_ids = set(queryset.values_list('id', flat=True).distinct())
|
||||
|
||||
for content_id in content_ids:
|
||||
try:
|
||||
content = Content.objects.get(id=content_id)
|
||||
|
||||
# Get images linked directly to content OR via task
|
||||
content_images = Images.objects.filter(
|
||||
Q(content=content) | Q(task=content.task)
|
||||
).order_by('position')
|
||||
# Get images linked directly to content
|
||||
content_images = Images.objects.filter(content=content).order_by('position')
|
||||
|
||||
# Get featured image
|
||||
featured_image = content_images.filter(image_type='featured').first()
|
||||
@@ -1585,82 +1554,7 @@ class ContentTaxonomyViewSet(SiteSectorModelViewSet):
|
||||
)
|
||||
|
||||
|
||||
@extend_schema_view(
|
||||
list=extend_schema(tags=['Writer - Attributes']),
|
||||
create=extend_schema(tags=['Writer - Attributes']),
|
||||
retrieve=extend_schema(tags=['Writer - Attributes']),
|
||||
update=extend_schema(tags=['Writer - Attributes']),
|
||||
partial_update=extend_schema(tags=['Writer - Attributes']),
|
||||
destroy=extend_schema(tags=['Writer - Attributes']),
|
||||
)
|
||||
class ContentAttributeViewSet(SiteSectorModelViewSet):
|
||||
"""
|
||||
ViewSet for managing content attributes (product specs, service modifiers, semantic facets)
|
||||
Unified API Standard v1.0 compliant
|
||||
"""
|
||||
queryset = ContentAttribute.objects.select_related('content', 'cluster', 'site', 'sector')
|
||||
serializer_class = ContentAttributeSerializer
|
||||
permission_classes = [IsAuthenticatedAndActive, IsViewerOrAbove]
|
||||
pagination_class = CustomPageNumberPagination
|
||||
throttle_scope = 'writer'
|
||||
throttle_classes = [DebugScopedRateThrottle]
|
||||
|
||||
# DRF filtering configuration
|
||||
filter_backends = [DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter]
|
||||
|
||||
# Search configuration
|
||||
search_fields = ['name', 'value', 'external_attribute_name', 'content__title']
|
||||
|
||||
# Ordering configuration
|
||||
ordering_fields = ['name', 'attribute_type', 'created_at']
|
||||
ordering = ['attribute_type', 'name']
|
||||
|
||||
# Filter configuration
|
||||
filterset_fields = ['attribute_type', 'source', 'content', 'cluster', 'external_id']
|
||||
|
||||
def perform_create(self, serializer):
|
||||
"""Create attribute with site/sector context"""
|
||||
user = getattr(self.request, 'user', None)
|
||||
|
||||
try:
|
||||
query_params = getattr(self.request, 'query_params', None)
|
||||
if query_params is None:
|
||||
query_params = getattr(self.request, 'GET', {})
|
||||
except AttributeError:
|
||||
query_params = {}
|
||||
|
||||
site_id = serializer.validated_data.get('site_id') or query_params.get('site_id')
|
||||
sector_id = serializer.validated_data.get('sector_id') or query_params.get('sector_id')
|
||||
|
||||
from igny8_core.auth.models import Site, Sector
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
if not site_id:
|
||||
raise ValidationError("site_id is required")
|
||||
|
||||
try:
|
||||
site = Site.objects.get(id=site_id)
|
||||
except Site.DoesNotExist:
|
||||
raise ValidationError(f"Site with id {site_id} does not exist")
|
||||
|
||||
if not sector_id:
|
||||
raise ValidationError("sector_id is required")
|
||||
|
||||
try:
|
||||
sector = Sector.objects.get(id=sector_id)
|
||||
if sector.site_id != site_id:
|
||||
raise ValidationError(f"Sector does not belong to the selected site")
|
||||
except Sector.DoesNotExist:
|
||||
raise ValidationError(f"Sector with id {sector_id} does not exist")
|
||||
|
||||
serializer.validated_data.pop('site_id', None)
|
||||
serializer.validated_data.pop('sector_id', None)
|
||||
|
||||
account = getattr(self.request, 'account', None)
|
||||
if not account and user and user.is_authenticated and user.account:
|
||||
account = user.account
|
||||
if not account:
|
||||
account = site.account
|
||||
|
||||
serializer.save(account=account, site=site, sector=sector)
|
||||
# ContentAttributeViewSet temporarily disabled - ContentAttributeSerializer was removed in Stage 1
|
||||
# TODO: Re-implement or remove completely based on Stage 1 architecture decisions
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user