diff --git a/social_ads_generator/templates/social_ads_generator/detail.html b/social_ads_generator/templates/social_ads_generator/detail.html index 2da3cf9..ebce096 100644 --- a/social_ads_generator/templates/social_ads_generator/detail.html +++ b/social_ads_generator/templates/social_ads_generator/detail.html @@ -233,8 +233,12 @@ content = result.ad_copy_content; } else if (result.content && typeof result.content === 'string') { content = result.content; - } else if (result.formatted_report && typeof result.formatted_report === 'string') { - content = result.formatted_report; + } else if (result.ad_copy && typeof result.ad_copy === 'string') { + content = result.ad_copy; + } else if (result.raw_response && result.raw_response.output && typeof result.raw_response.output === 'string') { + content = result.raw_response.output; + } else if (result.formatted_ad && typeof result.formatted_ad === 'string') { + content = result.formatted_ad; } else if (result.output_text && typeof result.output_text === 'string') { content = result.output_text; } else { diff --git a/social_ads_generator/urls.py b/social_ads_generator/urls.py index a272331..1ab8c9d 100644 --- a/social_ads_generator/urls.py +++ b/social_ads_generator/urls.py @@ -5,5 +5,6 @@ app_name = 'social_ads_generator' urlpatterns = [ path('', views.social_ads_generator_detail, name='detail'), - path('status//', views.social_ads_generator_result, name='status'), + path('status//', views.social_ads_generator_status, name='status'), + path('result//', views.social_ads_generator_result, name='result'), ] \ No newline at end of file diff --git a/social_ads_generator/views.py b/social_ads_generator/views.py index de39b7c..6ec7d1d 100644 --- a/social_ads_generator/views.py +++ b/social_ads_generator/views.py @@ -37,7 +37,7 @@ def social_ads_generator_detail(request): cost=agent.price, description=request.POST.get('description'), social_platform=request.POST.get('social_platform', 'facebook'), - include_emoji=request.POST.get('include_emoji') == 'on', + include_emoji=request.POST.get('include_emoji') == 'yes', language=request.POST.get('language', 'English'), ) @@ -124,6 +124,46 @@ class SocialAdsGeneratorProcessView(View): return JsonResponse({'error': str(e)}, status=500) +@login_required +def social_ads_generator_status(request, request_id): + """Get status for a specific request (for polling)""" + try: + agent_request = SocialAdsGeneratorRequest.objects.get( + id=request_id, + user=request.user + ) + + if hasattr(agent_request, 'response'): + response = agent_request.response + # Refresh user to get current wallet balance + request.user.refresh_from_db() + + return JsonResponse({ + 'success': response.success, + 'status': agent_request.status, + 'content': getattr(response, 'ad_copy', None), + 'ad_copy_content': getattr(response, 'ad_copy', None), + '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), + 'processing_time': float(response.processing_time) if response.processing_time else None, + 'error_message': response.error_message, + 'wallet_balance': float(request.user.wallet_balance) + }) + else: + return JsonResponse({ + 'success': False, + 'status': agent_request.status, + 'message': 'Processing in progress...' + }) + + except SocialAdsGeneratorRequest.DoesNotExist: + return JsonResponse({'error': 'Request not found'}, status=404) + except Exception as e: + return JsonResponse({'error': str(e)}, status=500) + + @login_required def social_ads_generator_result(request, request_id): """Get result for a specific request""" @@ -142,7 +182,7 @@ def social_ads_generator_result(request, request_id): 'success': response.success, 'status': agent_request.status, 'content': getattr(response, 'ad_copy', None), - 'ad_copy': getattr(response, 'ad_copy', None), + 'ad_copy_content': getattr(response, 'ad_copy', None), 'hashtags': getattr(response, 'hashtags', None), 'targeting_suggestions': getattr(response, 'targeting_suggestions', None), 'formatted_ad': getattr(response, 'formatted_ad', None),