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']
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):
"""Get cluster name from Clusters model"""
if obj.keyword_cluster_id:

View File

@@ -1010,44 +1010,57 @@ class ContentIdeasViewSet(SiteSectorModelViewSet):
from igny8_core.modules.writer.models import Tasks
created_tasks = []
errors = []
for idea in ideas:
# STAGE 3: Map idea fields to final Task schema
# Map site_entity_type → content_type
content_type = idea.site_entity_type or 'post'
try:
# STAGE 3: Map idea fields to final Task schema
# 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
# hub → article, supporting → guide, attribute → comparison
role_to_structure = {
'hub': 'article',
'supporting': 'guide',
'attribute': 'comparison',
}
content_structure = role_to_structure.get(idea.cluster_role, 'article')
# 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,
# 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,
)
# 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()
except Exception as e:
errors.append({'idea_id': idea.id, 'error': str(e)})
if errors:
return error_response(
error=f'Failed to create {len(errors)} tasks',
details=errors,
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
request=request
)
# 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(
data={
'created_count': len(created_tasks),