Files
igny8/backend/igny8_core/business/automation/admin.py
IGNY8 VPS (Salman) f637f700eb sadasda
2025-12-14 22:21:17 +00:00

36 lines
1.5 KiB
Python

"""
Admin registration for Automation models
"""
from django.contrib import admin
from django.contrib import messages
from unfold.admin import ModelAdmin
from igny8_core.admin.base import AccountAdminMixin
from .models import AutomationConfig, AutomationRun
@admin.register(AutomationConfig)
class AutomationConfigAdmin(AccountAdminMixin, ModelAdmin):
list_display = ('site', 'is_enabled', 'frequency', 'scheduled_time', 'within_stage_delay', 'between_stage_delay', 'last_run_at')
list_filter = ('is_enabled', 'frequency')
search_fields = ('site__domain',)
actions = ['bulk_enable', 'bulk_disable']
def bulk_enable(self, request, queryset):
"""Enable selected automation configs"""
updated = queryset.update(is_enabled=True)
self.message_user(request, f'{updated} automation config(s) enabled.', messages.SUCCESS)
bulk_enable.short_description = 'Enable selected automations'
def bulk_disable(self, request, queryset):
"""Disable selected automation configs"""
updated = queryset.update(is_enabled=False)
self.message_user(request, f'{updated} automation config(s) disabled.', messages.SUCCESS)
bulk_disable.short_description = 'Disable selected automations'
@admin.register(AutomationRun)
class AutomationRunAdmin(AccountAdminMixin, ModelAdmin):
list_display = ('run_id', 'site', 'status', 'current_stage', 'started_at', 'completed_at')
list_filter = ('status', 'current_stage')
search_fields = ('run_id', 'site__domain')