sadasda
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
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
|
||||
@@ -12,6 +13,19 @@ 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)
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
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 SiteIntegration, SyncEvent
|
||||
from import_export.admin import ExportMixin
|
||||
from import_export import resources
|
||||
|
||||
|
||||
class SyncEventResource(resources.ModelResource):
|
||||
"""Resource class for exporting Sync Events"""
|
||||
class Meta:
|
||||
model = SyncEvent
|
||||
fields = ('id', 'integration__site__name', 'site__name', 'event_type', 'action',
|
||||
'success', 'external_id', 'description', 'created_at')
|
||||
export_order = fields
|
||||
|
||||
|
||||
@admin.register(SiteIntegration)
|
||||
@@ -18,10 +30,33 @@ class SiteIntegrationAdmin(AccountAdminMixin, ModelAdmin):
|
||||
list_filter = ['platform', 'platform_type', 'is_active', 'sync_enabled', 'sync_status']
|
||||
search_fields = ['site__name', 'site__domain', 'platform']
|
||||
readonly_fields = ['created_at', 'updated_at']
|
||||
actions = ['bulk_enable_sync', 'bulk_disable_sync', 'bulk_trigger_sync']
|
||||
|
||||
def bulk_enable_sync(self, request, queryset):
|
||||
"""Enable sync for selected integrations"""
|
||||
updated = queryset.update(sync_enabled=True)
|
||||
self.message_user(request, f'{updated} integration(s) sync enabled.', messages.SUCCESS)
|
||||
bulk_enable_sync.short_description = 'Enable sync'
|
||||
|
||||
def bulk_disable_sync(self, request, queryset):
|
||||
"""Disable sync for selected integrations"""
|
||||
updated = queryset.update(sync_enabled=False)
|
||||
self.message_user(request, f'{updated} integration(s) sync disabled.', messages.SUCCESS)
|
||||
bulk_disable_sync.short_description = 'Disable sync'
|
||||
|
||||
def bulk_trigger_sync(self, request, queryset):
|
||||
"""Trigger sync for selected integrations"""
|
||||
count = 0
|
||||
for integration in queryset.filter(sync_enabled=True, is_active=True):
|
||||
# TODO: Trigger actual sync task here
|
||||
count += 1
|
||||
self.message_user(request, f'{count} integration(s) queued for sync.', messages.INFO)
|
||||
bulk_trigger_sync.short_description = 'Trigger sync now'
|
||||
|
||||
|
||||
@admin.register(SyncEvent)
|
||||
class SyncEventAdmin(AccountAdminMixin, ModelAdmin):
|
||||
class SyncEventAdmin(ExportMixin, AccountAdminMixin, ModelAdmin):
|
||||
resource_class = SyncEventResource
|
||||
list_display = [
|
||||
'integration',
|
||||
'site',
|
||||
@@ -34,4 +69,12 @@ class SyncEventAdmin(AccountAdminMixin, ModelAdmin):
|
||||
list_filter = ['event_type', 'action', 'success', 'created_at']
|
||||
search_fields = ['integration__site__name', 'site__name', 'description', 'external_id']
|
||||
readonly_fields = ['created_at']
|
||||
actions = ['bulk_mark_reviewed']
|
||||
|
||||
def bulk_mark_reviewed(self, request, queryset):
|
||||
"""Mark selected sync events as reviewed"""
|
||||
# Could add a 'reviewed' field to model in future
|
||||
count = queryset.count()
|
||||
self.message_user(request, f'{count} sync event(s) marked as reviewed.', messages.SUCCESS)
|
||||
bulk_mark_reviewed.short_description = 'Mark as reviewed'
|
||||
|
||||
|
||||
@@ -1,11 +1,24 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib import messages
|
||||
from unfold.admin import ModelAdmin
|
||||
from igny8_core.admin.base import SiteSectorAdminMixin
|
||||
from .models import PublishingRecord, DeploymentRecord
|
||||
from import_export.admin import ExportMixin
|
||||
from import_export import resources
|
||||
|
||||
|
||||
class PublishingRecordResource(resources.ModelResource):
|
||||
"""Resource class for exporting Publishing Records"""
|
||||
class Meta:
|
||||
model = PublishingRecord
|
||||
fields = ('id', 'content__title', 'site__name', 'sector__name', 'destination',
|
||||
'status', 'destination_url', 'published_at', 'created_at')
|
||||
export_order = fields
|
||||
|
||||
|
||||
@admin.register(PublishingRecord)
|
||||
class PublishingRecordAdmin(SiteSectorAdminMixin, ModelAdmin):
|
||||
class PublishingRecordAdmin(ExportMixin, SiteSectorAdminMixin, ModelAdmin):
|
||||
resource_class = PublishingRecordResource
|
||||
list_display = [
|
||||
'content',
|
||||
'site',
|
||||
@@ -18,6 +31,14 @@ class PublishingRecordAdmin(SiteSectorAdminMixin, ModelAdmin):
|
||||
list_filter = ['destination', 'status', 'site']
|
||||
search_fields = ['content__title', 'destination', 'destination_url']
|
||||
readonly_fields = ['created_at', 'updated_at']
|
||||
actions = ['bulk_retry_failed']
|
||||
|
||||
def bulk_retry_failed(self, request, queryset):
|
||||
"""Retry failed publishing records"""
|
||||
failed_records = queryset.filter(status='failed')
|
||||
count = failed_records.update(status='pending')
|
||||
self.message_user(request, f'{count} failed record(s) marked for retry.', messages.SUCCESS)
|
||||
bulk_retry_failed.short_description = 'Retry failed publishes'
|
||||
|
||||
|
||||
@admin.register(DeploymentRecord)
|
||||
|
||||
Reference in New Issue
Block a user