last fix form master imp part 6
This commit is contained in:
@@ -1279,7 +1279,7 @@ class AutomationService:
|
||||
self.run.run_id, self.account.id, self.site.id,
|
||||
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(
|
||||
site=self.site,
|
||||
status='completed',
|
||||
@@ -1295,12 +1295,14 @@ class AutomationService:
|
||||
from django.utils import timezone
|
||||
self.run.stage_6_result = {
|
||||
'images_processed': images_processed,
|
||||
'images_total': total_images, # FIXED: Preserve total for progress calculation
|
||||
'images_generated': images_generated,
|
||||
'content_moved_to_review': content_moved,
|
||||
'credits_used': credits_used,
|
||||
'time_elapsed': time_elapsed,
|
||||
'partial': True,
|
||||
'stopped_reason': reason
|
||||
'stopped_reason': reason,
|
||||
'in_progress': False
|
||||
}
|
||||
self.run.total_credits_used += credits_used
|
||||
self.run.save()
|
||||
@@ -1342,6 +1344,27 @@ class AutomationService:
|
||||
self.run.run_id, self.account.id, self.site.id,
|
||||
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:
|
||||
# FIXED: Log error but continue processing remaining images
|
||||
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
|
||||
self.run.stage_6_result = {
|
||||
'images_processed': images_processed,
|
||||
'images_total': total_images, # ADDED: Include total for consistency
|
||||
'images_generated': images_generated,
|
||||
'content_moved_to_review': content_moved_to_review,
|
||||
'credits_used': credits_used,
|
||||
'started_at': self.run.started_at.isoformat(),
|
||||
'completed_at': timezone.now().isoformat(),
|
||||
'time_elapsed': time_elapsed
|
||||
'time_elapsed': time_elapsed,
|
||||
'in_progress': False
|
||||
}
|
||||
self.run.current_stage = 7
|
||||
self.run.total_credits_used += credits_used
|
||||
|
||||
@@ -192,23 +192,19 @@ class BillingViewSet(viewsets.GenericViewSet):
|
||||
@action(detail=False, methods=['get'], url_path='payment-methods', permission_classes=[AllowAny])
|
||||
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.
|
||||
Does not expose sensitive configuration details.
|
||||
|
||||
Query params:
|
||||
country: ISO 2-letter country code (optional, defaults to global '*')
|
||||
|
||||
Returns payment methods - prioritizes global methods (country_code='*').
|
||||
Note: Country-specific filtering has been removed per Phase 1.1.2.
|
||||
The country_code field is retained for future use but currently ignored.
|
||||
All enabled payment methods are returned regardless of country_code value.
|
||||
"""
|
||||
country = request.GET.get('country', '*').upper()
|
||||
|
||||
# Get global methods first (country_code='*'), then country-specific as fallback
|
||||
# Return all enabled payment methods (global approach - no country filtering)
|
||||
# Country-specific filtering removed per Task 1.1.2 of Master Implementation Plan
|
||||
methods = PaymentMethodConfig.objects.filter(
|
||||
is_enabled=True
|
||||
).filter(
|
||||
Q(country_code='*') | Q(country_code=country)
|
||||
).order_by('sort_order').distinct()
|
||||
).order_by('sort_order')
|
||||
|
||||
# Serialize using the proper serializer
|
||||
serializer = PaymentMethodConfigSerializer(methods, many=True)
|
||||
|
||||
Reference in New Issue
Block a user