diff --git a/apps/proxy/admin.py b/apps/proxy/admin.py index 00708d466c..03d0dfb821 100644 --- a/apps/proxy/admin.py +++ b/apps/proxy/admin.py @@ -1,6 +1,9 @@ from django.contrib import admin, messages +from django.db import models +from django.db.models import F from django.utils.safestring import mark_safe +from apps import utils from apps.proxy import models from apps.sspanel.models import User from apps.utils import traffic_format @@ -257,16 +260,38 @@ def get_form(self, request, obj=None, **kwargs): class UserProxyNodeOccupancyAdmin(admin.ModelAdmin): + class StatusFilter(admin.SimpleListFilter): + title = "状态" + parameter_name = "status" + + def lookups(self, request, model_admin): + return ( + ("valid", "正常"), + ("invalid", "失效"), + ) + + def queryset(self, request, queryset): + value = self.value() + if value == "valid": + return queryset.filter( + end_time__gt=utils.get_current_datetime() + ).filter(used_traffic__lt=F("total_traffic")) + elif value == "invalid": + return queryset.exclude( + end_time__gt=utils.get_current_datetime() + ).filter(used_traffic__lt=F("total_traffic")) + return queryset + list_display = [ "proxy_node", "user", "start_time", "end_time", "traffic_info", - "out_of_usage", + "status", ] search_fields = ["user__username"] - list_filter = ["proxy_node", "user"] + list_filter = ["proxy_node", "user", StatusFilter] list_per_page = 10 show_full_result_count = False @@ -274,9 +299,12 @@ class UserProxyNodeOccupancyAdmin(admin.ModelAdmin): def traffic_info(self, instance): return f"{traffic_format(instance.used_traffic)}/{traffic_format(instance.total_traffic)}" - @admin.display(description="是否超出") - def out_of_usage(self, instance): - return instance.out_of_usage() + @admin.display(description="状态") + def status(self, instance): + if instance.out_of_usage(): + return "失效" + else: + return "正常" def get_form(self, request, obj=None, **kwargs): if obj: diff --git a/apps/sspanel/admin.py b/apps/sspanel/admin.py index b00356747e..3a7e4cb2b8 100644 --- a/apps/sspanel/admin.py +++ b/apps/sspanel/admin.py @@ -124,6 +124,11 @@ class TicketMessageInline(admin.TabularInline): "created_at", ] extra = 0 + raw_id_fields = ["user"] + + def get_queryset(self, request): + qs = super().get_queryset(request) + return qs.prefetch_related("user") class TicketAdmin(admin.ModelAdmin): @@ -139,7 +144,12 @@ def status_info(self, instance): return instance.status_with_message_count def get_queryset(self, request: HttpRequest) -> QuerySet[Any]: - qs = super().get_queryset(request).prefetch_related("messages") + qs = ( + super() + .get_queryset(request) + .prefetch_related("user") + .prefetch_related("messages__user") + ) return qs diff --git a/configs/default/sites.py b/configs/default/sites.py index 97bbc63e64..910e1efed6 100644 --- a/configs/default/sites.py +++ b/configs/default/sites.py @@ -59,6 +59,8 @@ # FOR SIMPLE UI SIMPLEUI_ANALYSIS = False +SIMPLEUI_HOME_ACTION = False +SIMPLEUI_HOME_QUICK = True SIMPLEUI_HOME_INFO = bool(os.getenv("SIMPLEUI_HOME_INFO", False)) SIMPLEUI_DEFAULT_ICON = bool(os.getenv("SIMPLEUI_DEFAULT_ICON", True)) SIMPLEUI_ICON = { @@ -86,7 +88,6 @@ "开放API": "fas fa-server", } - # TG 相关配置 TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME") TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")