diff --git a/social_ads_generator/processor.py b/social_ads_generator/processor.py index bb24ca7..b93c7f8 100644 --- a/social_ads_generator/processor.py +++ b/social_ads_generator/processor.py @@ -51,6 +51,7 @@ Please create platform-optimized ad copy that: request_obj.status = 'processing' request_obj.save() + # Handle array response from N8N (extract first item) if isinstance(response_data, list) and len(response_data) > 0: response_data = response_data[0] diff --git a/social_ads_generator/templates/social_ads_generator/detail.html b/social_ads_generator/templates/social_ads_generator/detail.html index ebce096..65effbf 100644 --- a/social_ads_generator/templates/social_ads_generator/detail.html +++ b/social_ads_generator/templates/social_ads_generator/detail.html @@ -102,7 +102,7 @@
@@ -201,6 +201,7 @@ // Display social ads results with engaging ad copy formatting function displayResults(result) { + const resultsContainer = document.getElementById('adResults'); const contentElement = document.getElementById('adContent'); @@ -211,7 +212,7 @@ // Update wallet balance if provided if (result.wallet_balance !== undefined) { - updateWalletBalance(result.wallet_balance); + AgentUtils.updateWalletBalance(result.wallet_balance); } // Handle errors diff --git a/social_ads_generator/views.py b/social_ads_generator/views.py index 6ec7d1d..e266353 100644 --- a/social_ads_generator/views.py +++ b/social_ads_generator/views.py @@ -138,19 +138,25 @@ def social_ads_generator_status(request, request_id): # Refresh user to get current wallet balance request.user.refresh_from_db() - return JsonResponse({ + ad_copy = getattr(response, 'ad_copy', None) + raw_response = getattr(response, 'raw_response', None) + + + json_response = { 'success': response.success, 'status': agent_request.status, - 'content': getattr(response, 'ad_copy', None), - 'ad_copy_content': getattr(response, 'ad_copy', None), + 'content': ad_copy, + 'ad_copy_content': ad_copy, 'hashtags': getattr(response, 'hashtags', None), 'targeting_suggestions': getattr(response, 'targeting_suggestions', None), 'formatted_ad': getattr(response, 'formatted_ad', None), - 'raw_response': getattr(response, 'raw_response', None), + 'raw_response': raw_response, 'processing_time': float(response.processing_time) if response.processing_time else None, 'error_message': response.error_message, 'wallet_balance': float(request.user.wallet_balance) - }) + } + + return JsonResponse(json_response) else: return JsonResponse({ 'success': False, diff --git a/weather_reporter/templates/weather_reporter/detail.html b/weather_reporter/templates/weather_reporter/detail.html index 0c926a5..ddae13d 100644 --- a/weather_reporter/templates/weather_reporter/detail.html +++ b/weather_reporter/templates/weather_reporter/detail.html @@ -271,7 +271,7 @@ // Update wallet balance if provided if (result.wallet_balance !== undefined) { - updateWalletBalance(result.wallet_balance); + AgentUtils.updateWalletBalance(result.wallet_balance); } // Handle errors @@ -481,7 +481,7 @@ // Submit form via AJAX const formData = new FormData(this); - fetch(window.location.href, { + fetch('/agents/weather-reporter/process/', { method: 'POST', body: formData, headers: { diff --git a/weather_reporter/urls.py b/weather_reporter/urls.py index 75f5c32..0b535b9 100644 --- a/weather_reporter/urls.py +++ b/weather_reporter/urls.py @@ -6,5 +6,6 @@ app_name = 'weather_reporter' urlpatterns = [ path('', views.weather_reporter_detail, name='detail'), path('process/', views.WeatherReporterProcessView.as_view(), name='process'), + path('status/