1
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -1010,19 +1010,22 @@ class ContentIdeasViewSet(SiteSectorModelViewSet):
|
||||
from igny8_core.modules.writer.models import Tasks
|
||||
|
||||
created_tasks = []
|
||||
errors = []
|
||||
for idea in ideas:
|
||||
try:
|
||||
# STAGE 3: Map idea fields to final Task schema
|
||||
# Map site_entity_type → content_type
|
||||
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
|
||||
role_to_structure = {
|
||||
'hub': 'article',
|
||||
'supporting': 'guide',
|
||||
'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
|
||||
task = Tasks.objects.create(
|
||||
@@ -1047,6 +1050,16 @@ class ContentIdeasViewSet(SiteSectorModelViewSet):
|
||||
# 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
|
||||
)
|
||||
|
||||
return success_response(
|
||||
data={
|
||||
|
||||
Reference in New Issue
Block a user