last fix form master imp part 6

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-31 20:50:47 +00:00
parent 6953343026
commit b61bd6e64d
2 changed files with 38 additions and 17 deletions

View File

@@ -1279,7 +1279,7 @@ class AutomationService:
self.run.run_id, self.account.id, self.site.id, self.run.run_id, self.account.id, self.site.id,
stage_number, f"Stage {reason} - saving progress ({images_processed} images processed)" stage_number, f"Stage {reason} - saving progress ({images_processed} images processed)"
) )
# Save current progress # Save current progress - FIXED: preserve images_total for accurate frontend display
images_generated = Images.objects.filter( images_generated = Images.objects.filter(
site=self.site, site=self.site,
status='completed', status='completed',
@@ -1295,12 +1295,14 @@ class AutomationService:
from django.utils import timezone from django.utils import timezone
self.run.stage_6_result = { self.run.stage_6_result = {
'images_processed': images_processed, 'images_processed': images_processed,
'images_total': total_images, # FIXED: Preserve total for progress calculation
'images_generated': images_generated, 'images_generated': images_generated,
'content_moved_to_review': content_moved, 'content_moved_to_review': content_moved,
'credits_used': credits_used, 'credits_used': credits_used,
'time_elapsed': time_elapsed, 'time_elapsed': time_elapsed,
'partial': True, 'partial': True,
'stopped_reason': reason 'stopped_reason': reason,
'in_progress': False
} }
self.run.total_credits_used += credits_used self.run.total_credits_used += credits_used
self.run.save() self.run.save()
@@ -1342,6 +1344,27 @@ class AutomationService:
self.run.run_id, self.account.id, self.site.id, self.run.run_id, self.account.id, self.site.id,
stage_number, f"Image generated for '{content_title}' ({images_processed}/{total_images})" stage_number, f"Image generated for '{content_title}' ({images_processed}/{total_images})"
) )
# ADDED: Incremental save after each image for real-time frontend progress
# This allows the frontend to show accurate progress during Stage 6
current_images_generated = Images.objects.filter(
site=self.site,
status__in=['generated', 'completed'],
updated_at__gte=self.run.started_at
).count()
current_credits_used = self._get_credits_used() - credits_before
current_time_elapsed = self._format_time_elapsed(start_time)
self.run.stage_6_result = {
'images_processed': images_processed,
'images_total': total_images,
'images_generated': current_images_generated,
'content_moved_to_review': 0, # Updated at end
'credits_used': current_credits_used,
'time_elapsed': current_time_elapsed,
'in_progress': True
}
self.run.save(update_fields=['stage_6_result'])
except Exception as e: except Exception as e:
# FIXED: Log error but continue processing remaining images # FIXED: Log error but continue processing remaining images
content_title = image.content.title if image.content else 'Unknown' content_title = image.content.title if image.content else 'Unknown'
@@ -1394,12 +1417,14 @@ class AutomationService:
stage_6_start = start_time # Capture stage start time stage_6_start = start_time # Capture stage start time
self.run.stage_6_result = { self.run.stage_6_result = {
'images_processed': images_processed, 'images_processed': images_processed,
'images_total': total_images, # ADDED: Include total for consistency
'images_generated': images_generated, 'images_generated': images_generated,
'content_moved_to_review': content_moved_to_review, 'content_moved_to_review': content_moved_to_review,
'credits_used': credits_used, 'credits_used': credits_used,
'started_at': self.run.started_at.isoformat(), 'started_at': self.run.started_at.isoformat(),
'completed_at': timezone.now().isoformat(), 'completed_at': timezone.now().isoformat(),
'time_elapsed': time_elapsed 'time_elapsed': time_elapsed,
'in_progress': False
} }
self.run.current_stage = 7 self.run.current_stage = 7
self.run.total_credits_used += credits_used self.run.total_credits_used += credits_used

View File

@@ -192,23 +192,19 @@ class BillingViewSet(viewsets.GenericViewSet):
@action(detail=False, methods=['get'], url_path='payment-methods', permission_classes=[AllowAny]) @action(detail=False, methods=['get'], url_path='payment-methods', permission_classes=[AllowAny])
def list_payment_methods(self, request): def list_payment_methods(self, request):
""" """
Get available payment methods for a specific country. Get available payment methods (global only).
Public endpoint - only returns enabled payment methods. Public endpoint - only returns enabled payment methods.
Does not expose sensitive configuration details. Does not expose sensitive configuration details.
Query params: Note: Country-specific filtering has been removed per Phase 1.1.2.
country: ISO 2-letter country code (optional, defaults to global '*') The country_code field is retained for future use but currently ignored.
All enabled payment methods are returned regardless of country_code value.
Returns payment methods - prioritizes global methods (country_code='*').
""" """
country = request.GET.get('country', '*').upper() # Return all enabled payment methods (global approach - no country filtering)
# Country-specific filtering removed per Task 1.1.2 of Master Implementation Plan
# Get global methods first (country_code='*'), then country-specific as fallback
methods = PaymentMethodConfig.objects.filter( methods = PaymentMethodConfig.objects.filter(
is_enabled=True is_enabled=True
).filter( ).order_by('sort_order')
Q(country_code='*') | Q(country_code=country)
).order_by('sort_order').distinct()
# Serialize using the proper serializer # Serialize using the proper serializer
serializer = PaymentMethodConfigSerializer(methods, many=True) serializer = PaymentMethodConfigSerializer(methods, many=True)