From f73bc135ad1ef3922ad4c4949b567ba89cc7f9dc Mon Sep 17 00:00:00 2001 From: Ehco1996 Date: Sun, 17 Dec 2023 13:00:08 +0800 Subject: [PATCH] feat: add more action for proxy node admin --- apps/proxy/admin.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/proxy/admin.py b/apps/proxy/admin.py index f4ab38b68c..d5f908ab80 100644 --- a/apps/proxy/admin.py +++ b/apps/proxy/admin.py @@ -84,7 +84,7 @@ class ProxyNodeAdmin(admin.ModelAdmin): all_inlines = [TrojanConfigInline, SSConfigInline, RelayRuleInline] list_editable = ["sequence"] list_filter = ["node_type", "country", "provider_remark"] - actions = ["reset_port"] + actions = ["reset_port", "clear_traffic_logs", "toggle_enable"] def get_inlines(self, request, instance): if not instance: @@ -129,6 +129,33 @@ def reset_port(self, request, queryset): reset_port.short_description = "重置端口" reset_port.type = "warning" + def clear_traffic_logs(self, request, queryset): + for node in queryset: + query = models.UserTrafficLog.objects.filter(proxy_node=node) + query.delete() + count = query._raw_delete(query.db) + messages.add_message( + request, + messages.SUCCESS, + f"{node}:'s traffic logs cleared count={count}", + ) + + clear_traffic_logs.short_description = "清除流量记录" + clear_traffic_logs.type = "danger" + + def toggle_enable(self, request, queryset): + for node in queryset: + node.enable = not node.enable + node.save() + messages.add_message( + request, + messages.SUCCESS, + f"{node}:'s enable is {node.enable}", + ) + + toggle_enable.short_description = "启用/禁用" + toggle_enable.type = "danger" + class RelayNodeAdmin(admin.ModelAdmin): list_display = [