1
This commit is contained in:
@@ -1010,43 +1010,56 @@ 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 (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
|
||||
# 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')
|
||||
|
||||
# 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={
|
||||
|
||||
Reference in New Issue
Block a user