1
This commit is contained in:
@@ -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:
|
||||||
|
|||||||
@@ -1010,44 +1010,57 @@ 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
|
# Map cluster_role → content_structure (with fallback)
|
||||||
# hub → article, supporting → guide, attribute → comparison
|
# hub → article, supporting → guide, attribute → comparison
|
||||||
role_to_structure = {
|
role_to_structure = {
|
||||||
'hub': 'article',
|
'hub': 'article',
|
||||||
'supporting': 'guide',
|
'supporting': 'guide',
|
||||||
'attribute': 'comparison',
|
'attribute': 'comparison',
|
||||||
}
|
}
|
||||||
content_structure = role_to_structure.get(idea.cluster_role, 'article')
|
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
|
# Create task with Stage 1 final fields
|
||||||
task = Tasks.objects.create(
|
task = Tasks.objects.create(
|
||||||
title=idea.idea_title,
|
title=idea.idea_title,
|
||||||
description=idea.description or '',
|
description=idea.description or '',
|
||||||
cluster=idea.keyword_cluster,
|
cluster=idea.keyword_cluster,
|
||||||
content_type=content_type,
|
content_type=content_type,
|
||||||
content_structure=content_structure,
|
content_structure=content_structure,
|
||||||
taxonomy_term=None, # Can be set later if taxonomy is available
|
taxonomy_term=None, # Can be set later if taxonomy is available
|
||||||
status='queued',
|
status='queued',
|
||||||
account=idea.account,
|
account=idea.account,
|
||||||
site=idea.site,
|
site=idea.site,
|
||||||
sector=idea.sector,
|
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(
|
return success_response(
|
||||||
data={
|
data={
|
||||||
'created_count': len(created_tasks),
|
'created_count': len(created_tasks),
|
||||||
|
|||||||
Reference in New Issue
Block a user