blurpritn adn site builde cleanup
This commit is contained in:
@@ -11,15 +11,11 @@ class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('igny8_core_auth', '0001_initial'),
|
||||
('planner', '0001_initial'),
|
||||
('site_building', '0001_initial'),
|
||||
# ('site_building', '0001_initial'), # REMOVED: SiteBuilder deprecated
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='contentideas',
|
||||
name='taxonomy',
|
||||
field=models.ForeignKey(blank=True, help_text='Optional taxonomy association when derived from blueprint planning', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='content_ideas', to='site_building.siteblueprinttaxonomy'),
|
||||
),
|
||||
# REMOVED: ContentIdeas.taxonomy FK to SiteBlueprintTaxonomy (legacy blueprint)
|
||||
migrations.AddField(
|
||||
model_name='keywords',
|
||||
name='account',
|
||||
|
||||
@@ -8,7 +8,7 @@ class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('igny8_core_auth', '0002_add_wp_api_key_to_site'),
|
||||
('planner', '0004_remove_clusters_igny8_clust_context_0d6bd7_idx_and_more'),
|
||||
('site_building', '0001_initial'),
|
||||
# ('site_building', '0001_initial'), # REMOVED: SiteBuilder deprecated
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
||||
@@ -4,7 +4,7 @@ from django.conf import settings
|
||||
from .models import Keywords, Clusters, ContentIdeas
|
||||
from igny8_core.auth.models import SeedKeyword
|
||||
from igny8_core.auth.serializers import SeedKeywordSerializer
|
||||
from igny8_core.business.site_building.models import SiteBlueprintTaxonomy
|
||||
# Removed: from igny8_core.business.site_building.models import SiteBlueprintTaxonomy
|
||||
|
||||
|
||||
class KeywordSerializer(serializers.ModelSerializer):
|
||||
@@ -209,10 +209,13 @@ class ContentIdeasSerializer(serializers.ModelSerializer):
|
||||
return None
|
||||
|
||||
def get_taxonomy_name(self, obj):
|
||||
"""Legacy: SiteBlueprintTaxonomy removed - taxonomy now in ContentTaxonomy"""
|
||||
if obj.taxonomy_id:
|
||||
try:
|
||||
taxonomy = SiteBlueprintTaxonomy.objects.get(id=obj.taxonomy_id)
|
||||
from igny8_core.business.content.models import ContentTaxonomy
|
||||
taxonomy = ContentTaxonomy.objects.get(id=obj.taxonomy_id)
|
||||
return taxonomy.name
|
||||
except SiteBlueprintTaxonomy.DoesNotExist:
|
||||
except ContentTaxonomy.DoesNotExist:
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
@@ -18,27 +18,25 @@ from igny8_core.api.response import success_response, error_response
|
||||
from igny8_core.api.throttles import DebugScopedRateThrottle
|
||||
from igny8_core.business.publishing.models import PublishingRecord, DeploymentRecord
|
||||
from igny8_core.business.publishing.services.publisher_service import PublisherService
|
||||
from igny8_core.business.publishing.services.deployment_readiness_service import DeploymentReadinessService
|
||||
from igny8_core.business.site_building.models import SiteBlueprint
|
||||
|
||||
|
||||
class PublishingRecordViewSet(SiteSectorModelViewSet):
|
||||
"""
|
||||
ViewSet for PublishingRecord model.
|
||||
"""
|
||||
queryset = PublishingRecord.objects.select_related('content', 'site_blueprint')
|
||||
queryset = PublishingRecord.objects.select_related('content')
|
||||
permission_classes = [IsAuthenticatedAndActive, IsEditorOrAbove]
|
||||
throttle_scope = 'publisher'
|
||||
throttle_classes = [DebugScopedRateThrottle]
|
||||
|
||||
def get_serializer_class(self):
|
||||
# Will be created in next step
|
||||
# Dynamically create serializer
|
||||
from rest_framework import serializers
|
||||
|
||||
class PublishingRecordSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = PublishingRecord
|
||||
fields = '__all__'
|
||||
exclude = [] # Legacy: site_blueprint field removed from model
|
||||
|
||||
return PublishingRecordSerializer
|
||||
|
||||
@@ -46,27 +44,29 @@ class PublishingRecordViewSet(SiteSectorModelViewSet):
|
||||
class DeploymentRecordViewSet(SiteSectorModelViewSet):
|
||||
"""
|
||||
ViewSet for DeploymentRecord model.
|
||||
Legacy: SiteBlueprint functionality removed.
|
||||
"""
|
||||
queryset = DeploymentRecord.objects.select_related('site_blueprint')
|
||||
queryset = DeploymentRecord.objects.all()
|
||||
permission_classes = [IsAuthenticatedAndActive, IsEditorOrAbove]
|
||||
throttle_scope = 'publisher'
|
||||
throttle_classes = [DebugScopedRateThrottle]
|
||||
|
||||
def get_serializer_class(self):
|
||||
# Will be created in next step
|
||||
# Dynamically create serializer
|
||||
from rest_framework import serializers
|
||||
|
||||
class DeploymentRecordSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = DeploymentRecord
|
||||
fields = '__all__'
|
||||
exclude = [] # Legacy: site_blueprint field removed from model
|
||||
|
||||
return DeploymentRecordSerializer
|
||||
|
||||
|
||||
class PublisherViewSet(viewsets.ViewSet):
|
||||
"""
|
||||
Publisher actions for publishing content and sites.
|
||||
Publisher actions for publishing content.
|
||||
Legacy SiteBlueprint publishing removed - only content publishing supported.
|
||||
"""
|
||||
permission_classes = [IsAuthenticatedAndActive, IsEditorOrAbove]
|
||||
throttle_scope = 'publisher'
|
||||
@@ -75,29 +75,33 @@ class PublisherViewSet(viewsets.ViewSet):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.publisher_service = PublisherService()
|
||||
self.readiness_service = DeploymentReadinessService()
|
||||
|
||||
@action(detail=False, methods=['post'], url_path='publish')
|
||||
def publish(self, request):
|
||||
"""
|
||||
Publish content or site to destinations.
|
||||
Publish content to destinations.
|
||||
|
||||
Request body:
|
||||
{
|
||||
"content_id": 123, # Optional: content to publish
|
||||
"site_blueprint_id": 456, # Optional: site to publish
|
||||
"destinations": ["wordpress", "sites"] # Required: list of destinations
|
||||
"content_id": 123, # Required: content to publish
|
||||
"destinations": ["wordpress"] # Required: list of destinations
|
||||
}
|
||||
"""
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
content_id = request.data.get('content_id')
|
||||
site_blueprint_id = request.data.get('site_blueprint_id')
|
||||
destinations = request.data.get('destinations', [])
|
||||
|
||||
logger.info(f"[PublisherViewSet.publish] 🚀 Publish request received: content_id={content_id}, destinations={destinations}")
|
||||
|
||||
if not content_id:
|
||||
return error_response(
|
||||
'content_id is required',
|
||||
status.HTTP_400_BAD_REQUEST,
|
||||
request
|
||||
)
|
||||
|
||||
if not destinations:
|
||||
return error_response(
|
||||
'destinations is required',
|
||||
@@ -107,136 +111,26 @@ class PublisherViewSet(viewsets.ViewSet):
|
||||
|
||||
account = request.account
|
||||
|
||||
if site_blueprint_id:
|
||||
# Publish site
|
||||
try:
|
||||
blueprint = SiteBlueprint.objects.get(id=site_blueprint_id, account=account)
|
||||
except SiteBlueprint.DoesNotExist:
|
||||
return error_response(
|
||||
f'Site blueprint {site_blueprint_id} not found',
|
||||
status.HTTP_404_NOT_FOUND,
|
||||
request
|
||||
)
|
||||
|
||||
if 'sites' in destinations:
|
||||
result = self.publisher_service.publish_to_sites(blueprint)
|
||||
return success_response(result, request=request)
|
||||
else:
|
||||
return error_response(
|
||||
'Site publishing only supports "sites" destination',
|
||||
status.HTTP_400_BAD_REQUEST,
|
||||
request
|
||||
)
|
||||
|
||||
elif content_id:
|
||||
# Publish content
|
||||
logger.info(f"[PublisherViewSet.publish] 📝 Publishing content {content_id} to {destinations}")
|
||||
result = self.publisher_service.publish_content(
|
||||
content_id,
|
||||
destinations,
|
||||
account
|
||||
)
|
||||
logger.info(f"[PublisherViewSet.publish] {'✅' if result.get('success') else '❌'} Publish result: {result}")
|
||||
return success_response(result, request=request)
|
||||
|
||||
else:
|
||||
return error_response(
|
||||
'Either content_id or site_blueprint_id is required',
|
||||
status.HTTP_400_BAD_REQUEST,
|
||||
request
|
||||
)
|
||||
|
||||
@action(detail=False, methods=['get'], url_path='blueprints/(?P<blueprint_id>[^/.]+)/readiness')
|
||||
def deployment_readiness(self, request, blueprint_id):
|
||||
"""
|
||||
Check deployment readiness for a site blueprint.
|
||||
Stage 4: Pre-deployment validation checks.
|
||||
|
||||
GET /api/v1/publisher/blueprints/{blueprint_id}/readiness/
|
||||
"""
|
||||
account = request.account
|
||||
|
||||
try:
|
||||
blueprint = SiteBlueprint.objects.get(id=blueprint_id, account=account)
|
||||
except SiteBlueprint.DoesNotExist:
|
||||
return error_response(
|
||||
f'Site blueprint {blueprint_id} not found',
|
||||
status.HTTP_404_NOT_FOUND,
|
||||
request
|
||||
)
|
||||
|
||||
readiness = self.readiness_service.check_readiness(blueprint_id)
|
||||
|
||||
return success_response(readiness, request=request)
|
||||
|
||||
@action(detail=False, methods=['post'], url_path='deploy/(?P<blueprint_id>[^/.]+)')
|
||||
def deploy(self, request, blueprint_id):
|
||||
"""
|
||||
Deploy site blueprint to Sites renderer.
|
||||
Stage 4: Enhanced with readiness check (optional).
|
||||
|
||||
POST /api/v1/publisher/deploy/{blueprint_id}/
|
||||
|
||||
Request body (optional):
|
||||
{
|
||||
"skip_readiness_check": false # Set to true to skip readiness validation
|
||||
}
|
||||
"""
|
||||
account = request.account
|
||||
|
||||
try:
|
||||
blueprint = SiteBlueprint.objects.get(id=blueprint_id, account=account)
|
||||
except SiteBlueprint.DoesNotExist:
|
||||
return error_response(
|
||||
f'Site blueprint {blueprint_id} not found',
|
||||
status.HTTP_404_NOT_FOUND,
|
||||
request
|
||||
)
|
||||
|
||||
# Stage 4: Optional readiness check
|
||||
skip_check = request.data.get('skip_readiness_check', False)
|
||||
if not skip_check:
|
||||
readiness = self.readiness_service.check_readiness(blueprint_id)
|
||||
if not readiness.get('ready'):
|
||||
return error_response(
|
||||
{
|
||||
'message': 'Site is not ready for deployment',
|
||||
'readiness': readiness
|
||||
},
|
||||
status.HTTP_400_BAD_REQUEST,
|
||||
request
|
||||
)
|
||||
|
||||
result = self.publisher_service.publish_to_sites(blueprint)
|
||||
|
||||
response_status = status.HTTP_202_ACCEPTED if result.get('success') else status.HTTP_400_BAD_REQUEST
|
||||
return success_response(result, request=request, status_code=response_status)
|
||||
# Publish content
|
||||
logger.info(f"[PublisherViewSet.publish] 📝 Publishing content {content_id} to {destinations}")
|
||||
result = self.publisher_service.publish_content(
|
||||
content_id,
|
||||
destinations,
|
||||
account
|
||||
)
|
||||
logger.info(f"[PublisherViewSet.publish] {'✅' if result.get('success') else '❌'} Publish result: {result}")
|
||||
return success_response(result, request=request)
|
||||
|
||||
@action(detail=False, methods=['get'], url_path='status/(?P<id>[^/.]+)')
|
||||
def get_status(self, request, id):
|
||||
"""
|
||||
Get publishing/deployment status.
|
||||
Get publishing status.
|
||||
|
||||
GET /api/v1/publisher/status/{id}/
|
||||
"""
|
||||
account = request.account
|
||||
|
||||
# Try deployment record first
|
||||
try:
|
||||
deployment = DeploymentRecord.objects.get(id=id, account=account)
|
||||
return success_response({
|
||||
'type': 'deployment',
|
||||
'status': deployment.status,
|
||||
'version': deployment.version,
|
||||
'deployed_version': deployment.deployed_version,
|
||||
'deployment_url': deployment.deployment_url,
|
||||
'deployed_at': deployment.deployed_at,
|
||||
'error_message': deployment.error_message,
|
||||
}, request=request)
|
||||
except DeploymentRecord.DoesNotExist:
|
||||
pass
|
||||
|
||||
# Try publishing record
|
||||
# Get publishing record
|
||||
try:
|
||||
publishing = PublishingRecord.objects.get(id=id, account=account)
|
||||
return success_response({
|
||||
|
||||
@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('igny8_core_auth', '0001_initial'),
|
||||
('planner', '0001_initial'),
|
||||
('site_building', '0001_initial'),
|
||||
# ('site_building', '0001_initial'), # REMOVED: SiteBuilder deprecated
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
||||
Reference in New Issue
Block a user