autmation final reaftocrs and setitgns dafautls
This commit is contained in:
@@ -9,6 +9,7 @@ import logging
|
||||
from rest_framework import viewsets, status
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.views import APIView
|
||||
from django.shortcuts import get_object_or_404
|
||||
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiParameter
|
||||
|
||||
@@ -16,7 +17,7 @@ from igny8_core.api.permissions import IsAuthenticatedAndActive, IsEditorOrAbove
|
||||
from igny8_core.api.response import success_response, error_response
|
||||
from igny8_core.api.throttles import DebugScopedRateThrottle
|
||||
from igny8_core.auth.models import Site
|
||||
from igny8_core.business.automation.models import AutomationConfig
|
||||
from igny8_core.business.automation.models import AutomationConfig, DefaultAutomationConfig
|
||||
from igny8_core.business.integration.models import PublishingSettings
|
||||
from igny8_core.business.billing.models import AIModelConfig
|
||||
|
||||
@@ -452,3 +453,101 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
|
||||
automation_config.max_approvals_per_run = stage['per_run_limit']
|
||||
|
||||
logger.info(f"[UnifiedSettings] After update - stage_1_batch_size={automation_config.stage_1_batch_size}, max_keywords_per_run={automation_config.max_keywords_per_run}")
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
# DEFAULT SETTINGS API
|
||||
# ═══════════════════════════════════════════════════════════
|
||||
|
||||
class DefaultSettingsAPIView(APIView):
|
||||
"""
|
||||
API endpoint to fetch default settings for reset functionality.
|
||||
Reads from DefaultAutomationConfig singleton in backend.
|
||||
|
||||
GET /api/v1/settings/defaults/
|
||||
"""
|
||||
permission_classes = [IsAuthenticatedAndActive]
|
||||
|
||||
@extend_schema(
|
||||
tags=['Site Settings'],
|
||||
summary='Get default settings',
|
||||
description='Fetch default automation, publishing, and stage settings from backend configuration. Used by frontend reset functionality.',
|
||||
)
|
||||
def get(self, request):
|
||||
"""Return default settings from DefaultAutomationConfig"""
|
||||
try:
|
||||
defaults = DefaultAutomationConfig.get_instance()
|
||||
|
||||
# Build stage defaults from the model
|
||||
stage_defaults = []
|
||||
for i in range(1, 8):
|
||||
stage_config = {
|
||||
'number': i,
|
||||
'enabled': getattr(defaults, f'stage_{i}_enabled', True),
|
||||
}
|
||||
|
||||
# Batch size (stages 1-6)
|
||||
if i <= 6:
|
||||
stage_config['batch_size'] = getattr(defaults, f'stage_{i}_batch_size', 1)
|
||||
|
||||
# Per-run limits
|
||||
limit_map = {
|
||||
1: 'max_keywords_per_run',
|
||||
2: 'max_clusters_per_run',
|
||||
3: 'max_ideas_per_run',
|
||||
4: 'max_tasks_per_run',
|
||||
5: 'max_content_per_run',
|
||||
6: 'max_images_per_run',
|
||||
7: 'max_approvals_per_run',
|
||||
}
|
||||
stage_config['per_run_limit'] = getattr(defaults, limit_map[i], 0)
|
||||
|
||||
# Use testing (AI stages only: 1, 2, 4, 5, 6)
|
||||
if i in [1, 2, 4, 5, 6]:
|
||||
stage_config['use_testing'] = getattr(defaults, f'stage_{i}_use_testing', False)
|
||||
stage_config['budget_pct'] = getattr(defaults, f'stage_{i}_budget_pct', 0)
|
||||
|
||||
stage_defaults.append(stage_config)
|
||||
|
||||
# Build publish days - ensure it's a list
|
||||
publish_days = defaults.publish_days
|
||||
if not publish_days:
|
||||
publish_days = ['mon', 'tue', 'wed', 'thu', 'fri']
|
||||
|
||||
# Build time slots - ensure it's a list
|
||||
time_slots = defaults.publish_time_slots
|
||||
if not time_slots:
|
||||
time_slots = ['09:00', '14:00', '18:00']
|
||||
|
||||
# Format scheduled_time from hour
|
||||
scheduled_hour = defaults.next_scheduled_hour
|
||||
scheduled_time = f"{scheduled_hour:02d}:00"
|
||||
|
||||
return success_response({
|
||||
'automation': {
|
||||
'enabled': defaults.is_enabled,
|
||||
'frequency': defaults.frequency,
|
||||
'time': scheduled_time,
|
||||
},
|
||||
'stages': stage_defaults,
|
||||
'delays': {
|
||||
'within_stage': defaults.within_stage_delay,
|
||||
'between_stage': defaults.between_stage_delay,
|
||||
},
|
||||
'publishing': {
|
||||
'auto_approval_enabled': defaults.auto_approval_enabled,
|
||||
'auto_publish_enabled': defaults.auto_publish_enabled,
|
||||
'daily_publish_limit': defaults.daily_publish_limit,
|
||||
'weekly_publish_limit': defaults.weekly_publish_limit,
|
||||
'monthly_publish_limit': defaults.monthly_publish_limit,
|
||||
'publish_days': publish_days,
|
||||
'time_slots': time_slots,
|
||||
},
|
||||
'images': {
|
||||
'style': defaults.image_style,
|
||||
'max_images': defaults.max_images_per_article,
|
||||
},
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"[DefaultSettings] Error fetching defaults: {e}")
|
||||
return error_response(str(e), status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
Reference in New Issue
Block a user