Skip to content

Commit

Permalink
隧道信息在后台管理编辑时加密展示
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyo committed Oct 20, 2020
1 parent 8943537 commit 9ac89f2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions sql/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: UTF-8 -*-
from django.contrib import admin
from django import forms
from django.contrib.auth.admin import UserAdmin

# Register your models here.
from django.db import models
from django.forms import PasswordInput

from .models import Users, Instance, SqlWorkflow, SqlWorkflowContent, QueryLog, DataMaskingColumns, DataMaskingRules, \
Expand Down Expand Up @@ -60,7 +58,6 @@ def get_readonly_fields(self, request, obj=None):


# 实例管理

@admin.register(Instance)
class InstanceAdmin(admin.ModelAdmin):
list_display = ('id', 'instance_name', 'db_type', 'type', 'host', 'port', 'user', 'create_time')
Expand All @@ -81,24 +78,33 @@ class AliRdsConfigInline(admin.TabularInline):

inlines = [AliRdsConfigInline]


# SSH隧道
@admin.register(Tunnel)
class TunnelAdmin(admin.ModelAdmin):
list_display = ('id', 'tunnel_name', 'host', 'port', 'create_time')
list_display_links = ('id', 'tunnel_name',)
search_fields = ('id', 'tunnel_name')
fieldsets = (None, {'fields': ('tunnel_name', 'host', 'port', 'user', 'password', 'pkey_path', 'pkey_password',), }),
fieldsets = (
None,
{'fields': ('tunnel_name', 'host', 'port', 'user', 'password', 'pkey_path', 'pkey_password',), }),
ordering = ('id',)
# 添加页显示内容
add_fieldsets = (
('隧道信息', {'fields': ('tunnel_name', 'host', 'port')}),
('连接信息', {'fields': ('user', 'password', 'pkey_path', 'pkey_password')}),
)

def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name in ['password', 'pkey_password']:
kwargs['widget'] = PasswordInput(render_value=True)
return super(TunnelAdmin, self).formfield_for_dbfield(db_field, **kwargs)

# 不支持修改标签代码
def get_readonly_fields(self, request, obj=None):
return ('id',) if obj else ()


# SQL工单内容
class SqlWorkflowContentInline(admin.TabularInline):
model = SqlWorkflowContent
Expand Down

0 comments on commit 9ac89f2

Please sign in to comment.