This commit is contained in:
IGNY8 VPS (Salman)
2025-11-26 13:08:37 +00:00
parent 403432770b
commit 2ef98b5113
2 changed files with 47 additions and 43 deletions

View File

@@ -187,15 +187,6 @@ class ContentIdeasSerializer(serializers.ModelSerializer):
] ]
read_only_fields = ['id', 'created_at', 'updated_at', 'account_id'] read_only_fields = ['id', 'created_at', 'updated_at', 'account_id']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Only include Stage 1 fields when feature flag is enabled
if getattr(settings, 'USE_SITE_BUILDER_REFACTOR', False):
self.fields['taxonomy_id'] = serializers.IntegerField(read_only=True, allow_null=True)
self.fields['taxonomy_name'] = serializers.SerializerMethodField()
self.fields['site_entity_type'] = serializers.CharField(read_only=True)
self.fields['cluster_role'] = serializers.CharField(read_only=True)
def get_keyword_cluster_name(self, obj): def get_keyword_cluster_name(self, obj):
"""Get cluster name from Clusters model""" """Get cluster name from Clusters model"""
if obj.keyword_cluster_id: if obj.keyword_cluster_id:

View File

@@ -1010,43 +1010,56 @@ class ContentIdeasViewSet(SiteSectorModelViewSet):
from igny8_core.modules.writer.models import Tasks from igny8_core.modules.writer.models import Tasks
created_tasks = [] created_tasks = []
errors = []
for idea in ideas: for idea in ideas:
# STAGE 3: Map idea fields to final Task schema try:
# Map site_entity_type → content_type # STAGE 3: Map idea fields to final Task schema
content_type = idea.site_entity_type or 'post' # Map site_entity_type → content_type (with fallback)
content_type = idea.site_entity_type if idea.site_entity_type else 'post'
# Map cluster_role → content_structure (with fallback)
# hub → article, supporting → guide, attribute → comparison
role_to_structure = {
'hub': 'article',
'supporting': 'guide',
'attribute': 'comparison',
}
cluster_role = idea.cluster_role if idea.cluster_role else 'hub'
content_structure = role_to_structure.get(cluster_role, 'article')
# Create task with Stage 1 final fields
task = Tasks.objects.create(
title=idea.idea_title,
description=idea.description or '',
cluster=idea.keyword_cluster,
content_type=content_type,
content_structure=content_structure,
taxonomy_term=None, # Can be set later if taxonomy is available
status='queued',
account=idea.account,
site=idea.site,
sector=idea.sector,
)
# Map cluster_role → content_structure # Link keywords from idea to task
# hub → article, supporting → guide, attribute → comparison if idea.keyword_objects.exists():
role_to_structure = { task.keywords.set(idea.keyword_objects.all())
'hub': 'article',
'supporting': 'guide', created_tasks.append(task.id)
'attribute': 'comparison',
} # Update idea status
content_structure = role_to_structure.get(idea.cluster_role, 'article') idea.status = 'scheduled'
idea.save()
# Create task with Stage 1 final fields except Exception as e:
task = Tasks.objects.create( errors.append({'idea_id': idea.id, 'error': str(e)})
title=idea.idea_title,
description=idea.description or '', if errors:
cluster=idea.keyword_cluster, return error_response(
content_type=content_type, error=f'Failed to create {len(errors)} tasks',
content_structure=content_structure, details=errors,
taxonomy_term=None, # Can be set later if taxonomy is available status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
status='queued', request=request
account=idea.account,
site=idea.site,
sector=idea.sector,
) )
# Link keywords from idea to task
if idea.keyword_objects.exists():
task.keywords.set(idea.keyword_objects.all())
created_tasks.append(task.id)
# Update idea status
idea.status = 'scheduled'
idea.save()
return success_response( return success_response(
data={ data={