Refactor site building workflow and context handling; update API response structure for improved clarity and consistency. Adjust frontend components to align with new data structure, including error handling and loading states.

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-20 21:50:16 +00:00
parent 781052c719
commit 1b4cd59e5b
24 changed files with 386 additions and 164 deletions

View File

@@ -1,3 +1,4 @@
import logging
from django.conf import settings
from rest_framework import status
from rest_framework.decorators import action
@@ -6,6 +7,8 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.exceptions import ValidationError
logger = logging.getLogger(__name__)
from igny8_core.api.base import SiteSectorModelViewSet
from igny8_core.api.permissions import IsAuthenticatedAndActive, IsEditorOrAbove
from igny8_core.api.response import success_response, error_response
@@ -308,8 +311,16 @@ class SiteBlueprintViewSet(SiteSectorModelViewSet):
"""Return aggregated wizard context (steps, clusters, taxonomies, coverage)."""
blueprint = self.get_object()
if not self.workflow_service.enabled:
# Return empty context structure matching frontend expectations
return success_response(
data={'workflow': None, 'clusters': {}, 'taxonomies': {}, 'coverage': {}},
data={
'workflow': None,
'cluster_summary': {'attached_count': 0, 'coverage_counts': {}, 'clusters': []},
'taxonomy_summary': {'total_taxonomies': 0, 'counts_by_type': {}, 'taxonomies': []},
'sitemap_summary': {'pages_total': 0, 'pages_by_status': {}, 'pages_by_type': {}},
'coverage': {'pages_total': 0, 'pages_by_status': {}, 'pages_by_type': {}},
'next_actions': None,
},
request=request,
)
@@ -362,27 +373,35 @@ class SiteBlueprintViewSet(SiteSectorModelViewSet):
request
)
updated_state = self.workflow_service.update_step(
blueprint,
step,
status_value,
metadata
)
if not updated_state:
try:
updated_state = self.workflow_service.update_step(
blueprint,
step,
status_value,
metadata
)
if not updated_state:
return error_response(
'Failed to update workflow step',
status.HTTP_500_INTERNAL_SERVER_ERROR,
request
)
# Serialize state
serialized = self.workflow_service.serialize_state(updated_state)
return success_response(
data=serialized,
request=request
)
except Exception as e:
logger.exception(f"Error updating workflow step for blueprint {blueprint.id}: {str(e)}")
return error_response(
'Failed to update workflow step',
f'Internal server error: {str(e)}',
status.HTTP_500_INTERNAL_SERVER_ERROR,
request
)
# Serialize state
serialized = self.workflow_service.serialize_state(updated_state)
return success_response(
data=serialized,
request=request
)
@action(detail=True, methods=['post'], url_path='clusters/attach')
def attach_clusters(self, request, pk=None):