chore: интерфесы бота

This commit is contained in:
protokey committed 2026-09-24 17:33:10 +04:00
1 parent 5f53cadf89
commit 6d322f36a9
42 files changed
+1731 -111

No files matched your search

+41 -1
View File
@@ -3,7 +3,7 @@ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.forms import AdminUserCreationForm, UserChangeForm
from django.utils.translation import gettext_lazy as _
from .models import User
from .models import Point, Server, User
class UserCreationForm(AdminUserCreationForm):
@@ -28,3 +28,43 @@ class UserAdmin(BaseUserAdmin):
)
list_display = ('username', 'first_name', 'last_name', 'is_staff')
search_fields = ('username', 'first_name', 'last_name')
class ServerInline(admin.StackedInline):
model = Server
extra = 0
fields = ('role', 'address', 'ssh_port', 'root_password', 'public_key', 'known_hosts', 'uname')
readonly_fields = fields
can_delete = False
def has_add_permission(self, request, obj=None):
return False
@admin.register(Point)
class PointAdmin(admin.ModelAdmin):
list_display = ('name', 'owner', 'status', 'domain', 'created_at')
list_filter = ('status',)
search_fields = ('name', 'servers__address')
readonly_fields = ('owner', 'name', 'status', 'error', 'created_at')
inlines = [ServerInline]
@admin.register(Server)
class ServerAdmin(admin.ModelAdmin):
list_display = ('address', 'role', 'point', 'ssh_port', 'has_fingerprint')
list_filter = ('role',)
search_fields = ('address', 'point__name')
exclude = ('private_key',)
readonly_fields = ('point', 'role', 'public_key', 'uname')
actions = ('reset_fingerprint',)
@admin.display(boolean=True, description='отпечаток')
def has_fingerprint(self, server):
return bool(server.known_hosts)
@admin.action(description='Сбросить отпечаток ssh (после переустановки ОС)')
def reset_fingerprint(self, request, queryset):
for server in queryset:
server.reset_fingerprint()
self.message_user(request, f'Сброшено отпечатков: {len(queryset)}')