36 lines
1.5 KiB
Python
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, Igny8ModelAdmin
|
|
from .models import AutomationConfig, AutomationRun
|
|
|
|
|
|
@admin.register(AutomationConfig)
|
|
class AutomationConfigAdmin(AccountAdminMixin, Igny8ModelAdmin):
|
|
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, Igny8ModelAdmin):
|
|
list_display = ('run_id', 'site', 'status', 'current_stage', 'started_at', 'completed_at')
|
|
list_filter = ('status', 'current_stage')
|
|
search_fields = ('run_id', 'site__domain')
|