sd
This commit is contained in:
@@ -598,4 +598,137 @@ class IntegrationViewSet(SiteSectorModelViewSet):
|
||||
'logs': logs,
|
||||
'count': len(logs)
|
||||
}, request=request)
|
||||
|
||||
@action(detail=True, methods=['get'], url_path='debug-status')
|
||||
def debug_status(self, request, pk=None):
|
||||
"""
|
||||
Get comprehensive debug status for WordPress integration.
|
||||
Includes health, recent events, and data validation.
|
||||
|
||||
GET /api/v1/integration/integrations/{id}/debug-status/
|
||||
|
||||
Query params:
|
||||
- include_events: Include recent sync events (default: false)
|
||||
- include_validation: Include data validation matrix (default: false)
|
||||
- event_limit: Number of events to return (default: 20)
|
||||
"""
|
||||
integration = self.get_object()
|
||||
|
||||
include_events = request.query_params.get('include_events', 'false').lower() == 'true'
|
||||
include_validation = request.query_params.get('include_validation', 'false').lower() == 'true'
|
||||
event_limit = int(request.query_params.get('event_limit', 20))
|
||||
|
||||
# Get integration health
|
||||
health_data = {
|
||||
'api_status': 'healthy' if integration.is_active else 'error',
|
||||
'api_message': 'Integration is active' if integration.is_active else 'Integration is inactive',
|
||||
'last_api_check': integration.updated_at.isoformat() if integration.updated_at else None,
|
||||
'plugin_active': integration.is_active,
|
||||
'plugin_version': integration.credentials_json.get('plugin_version', 'Unknown') if integration.credentials_json else 'Unknown',
|
||||
'debug_mode': integration.credentials_json.get('debug_enabled', False) if integration.credentials_json else False,
|
||||
'sync_healthy': integration.last_sync_at is not None,
|
||||
'pending_syncs': 0, # TODO: Calculate from actual sync queue
|
||||
'last_sync': integration.last_sync_at.isoformat() if integration.last_sync_at else None,
|
||||
}
|
||||
|
||||
response_data = {
|
||||
'health': health_data,
|
||||
}
|
||||
|
||||
# Include sync events if requested
|
||||
if include_events:
|
||||
sync_health_service = SyncHealthService()
|
||||
logs = sync_health_service.get_sync_logs(
|
||||
integration.site_id,
|
||||
integration_id=integration.id,
|
||||
limit=event_limit
|
||||
)
|
||||
|
||||
# Format logs as events
|
||||
events = []
|
||||
for log in logs:
|
||||
events.append({
|
||||
'type': 'sync' if log.get('success') else 'error',
|
||||
'action': log.get('operation', 'sync'),
|
||||
'description': log.get('message', 'Sync operation'),
|
||||
'timestamp': log.get('timestamp', timezone.now().isoformat()),
|
||||
'details': log.get('details', {}),
|
||||
})
|
||||
|
||||
response_data['events'] = events
|
||||
|
||||
# Include data validation if requested
|
||||
if include_validation:
|
||||
# TODO: Implement actual data validation check
|
||||
# For now, return placeholder data
|
||||
response_data['validation'] = [
|
||||
{
|
||||
'field_name': 'content_title',
|
||||
'igny8_value': 'Sample Title',
|
||||
'wp_value': 'Sample Title',
|
||||
'matches': True,
|
||||
},
|
||||
{
|
||||
'field_name': 'content_html',
|
||||
'igny8_value': '<p>Content</p>',
|
||||
'wp_value': '<p>Content</p>',
|
||||
'matches': True,
|
||||
},
|
||||
]
|
||||
|
||||
return success_response(response_data, request=request)
|
||||
|
||||
@action(detail=True, methods=['post'], url_path='trigger-debug')
|
||||
def trigger_debug(self, request, pk=None):
|
||||
"""
|
||||
Enable/disable debug mode for WordPress integration.
|
||||
|
||||
POST /api/v1/integration/integrations/{id}/trigger-debug/
|
||||
|
||||
Body:
|
||||
{
|
||||
"debug_enabled": true
|
||||
}
|
||||
"""
|
||||
integration = self.get_object()
|
||||
debug_enabled = request.data.get('debug_enabled', False)
|
||||
|
||||
# Update credentials with debug flag
|
||||
credentials = integration.credentials_json or {}
|
||||
credentials['debug_enabled'] = debug_enabled
|
||||
integration.credentials_json = credentials
|
||||
integration.save()
|
||||
|
||||
logger.info(
|
||||
f"WordPress debug mode {'enabled' if debug_enabled else 'disabled'} "
|
||||
f"for integration {integration.id} (site: {integration.site.name})"
|
||||
)
|
||||
|
||||
return success_response({
|
||||
'debug_enabled': debug_enabled,
|
||||
'message': f"Debug mode {'enabled' if debug_enabled else 'disabled'} successfully",
|
||||
}, request=request)
|
||||
|
||||
@action(detail=True, methods=['post'], url_path='test-connection')
|
||||
def test_connection_detail(self, request, pk=None):
|
||||
"""
|
||||
Test connection to WordPress site.
|
||||
|
||||
POST /api/v1/integration/integrations/{id}/test-connection/
|
||||
"""
|
||||
integration = self.get_object()
|
||||
|
||||
service = IntegrationService()
|
||||
result = service.test_connection(integration)
|
||||
|
||||
if result.get('success'):
|
||||
return success_response(result, request=request)
|
||||
else:
|
||||
return error_response(
|
||||
result.get('message', 'Connection test failed'),
|
||||
result.get('details'),
|
||||
status.HTTP_400_BAD_REQUEST,
|
||||
request
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ class ContentAdmin(SiteSectorAdminMixin, admin.ModelAdmin):
|
||||
search_fields = ['title', 'content_html', 'external_url']
|
||||
ordering = ['-created_at']
|
||||
readonly_fields = ['created_at', 'updated_at', 'word_count']
|
||||
filter_horizontal = ['taxonomy_terms'] # Add many-to-many widget for taxonomy terms
|
||||
# Note: taxonomy_terms removed from filter_horizontal because it uses a through model
|
||||
|
||||
fieldsets = (
|
||||
('Basic Info', {
|
||||
@@ -100,10 +100,8 @@ class ContentAdmin(SiteSectorAdminMixin, admin.ModelAdmin):
|
||||
('Content Classification', {
|
||||
'fields': ('content_type', 'content_structure', 'source')
|
||||
}),
|
||||
('Taxonomy Terms (Tags & Categories)', {
|
||||
'fields': ('taxonomy_terms',),
|
||||
'description': 'Select tags and categories for this content'
|
||||
}),
|
||||
# Note: taxonomy_terms field removed from fieldsets because it uses ContentTaxonomyAssociation through model
|
||||
# Taxonomy associations can be managed via the inline admin or separately
|
||||
('Content', {
|
||||
'fields': ('content_html', 'word_count')
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user