[Update] 修改database 表现

pull/828/merge
ibuler 2017-12-31 12:20:08 +08:00
parent 13b610c140
commit 0b299344a7
10 changed files with 60 additions and 43 deletions

View File

@ -216,6 +216,7 @@ class ClusterSerializer(BulkSerializerMixin, serializers.ModelSerializer):
assets_amount = serializers.SerializerMethodField()
admin_user_name = serializers.SerializerMethodField()
assets = serializers.PrimaryKeyRelatedField(many=True, queryset=Asset.objects.all())
system_users = serializers.SerializerMethodField()
class Meta:
model = Cluster
@ -232,6 +233,10 @@ class ClusterSerializer(BulkSerializerMixin, serializers.ModelSerializer):
except AttributeError:
return ''
@staticmethod
def get_system_users(obj):
return ', '.join(obj.name for obj in obj.systemuser_set.all())
class AssetGroupGrantedSerializer(BulkSerializerMixin, serializers.ModelSerializer):
"""

View File

@ -373,7 +373,7 @@ $(document).ready(function () {
url: the_url,
error: error,
method: 'GET',
success_message: "{% trans "Pong" %}"
success_message: "{% trans "Reachable" %}"
});
})

View File

@ -19,9 +19,7 @@
<th class="text-center"><a href="{% url 'assets:cluster-list' %}?sort=name">{% trans 'Name' %}</a></th>
<th class="text-center">{% trans 'Admin user' %}</th>
<th class="text-center">{% trans 'Asset num' %}</th>
<th class="text-center">{% trans 'Contact' %}</th>
<th class="text-center">{% trans 'Phone' %}</th>
<th class="text-center">{% trans 'Operator' %}</th>
<th class="text-center">{% trans 'System users' %}</th>
<th class="text-center">{% trans 'Action' %}</th>
</tr>
</thead>
@ -41,14 +39,16 @@ $(document).ready(function(){
$(td).html(detail_btn.replace('{{ DEFAULT_PK }}', rowData.id));
}},
{targets: 7, createdCell: function (td, cellData, rowData) {
{targets: 5, createdCell: function (td, cellData, rowData) {
var update_btn = '<a href="{% url "assets:cluster-update" pk=DEFAULT_PK %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'.replace('{{ DEFAULT_PK }}', cellData);
var del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_cluster_delete" data-uid="{{ DEFAULT_PK }}">{% trans "Delete" %}</a>'.replace('{{ DEFAULT_PK }}', cellData);
$(td).html(update_btn + del_btn)
}}],
ajax_url: '{% url "api-assets:cluster-list" %}',
columns: [{data: function(){return ""}}, {data: "name" }, {data: "admin_user_name"}, {data: "assets_amount" }, {data: "contact" }, {data: "phone" },
{data: "operator" }, {data: "id" }],
columns: [
{data: "id"}, {data: "name" }, {data: "admin_user_name"}, {data: "assets_amount" },
{data: "system_users" }, {data: "id" }
],
op_html: $('#actions').html()
};
jumpserver.initDataTable(options);

View File

@ -257,10 +257,13 @@ jumpserver.initDataTable = function (options) {
$(td).html('<input type="checkbox" class="text-center ipt_check" id=99991937>'.replace('99991937', cellData));
}
},
// className: 'select-checkbox'
{className: 'text-center', targets: '_all'}
];
columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs;
var select = {
style: 'multi',
selector: 'td:first-child'
};
var table = ele.DataTable({
pageLength: options.pageLength || 15,
dom: options.dom || '<"#uc.pull-left">flt<"row m-t"<"col-md-8"<"#op.col-md-6"><"col-md-6 text-center"i>><"col-md-4"p>>',
@ -273,9 +276,16 @@ jumpserver.initDataTable = function (options) {
dataSrc: ""
},
columns: options.columns || [],
select: {
style: 'multi',
selector: 'td:first-child'
select: options.select || select,
language: {
search: "搜索",
lengthMenu: "每页 _MENU_",
paginate: {
first: "第一页",
previous: "上一页",
next: "下一页",
last: "最后"
}
},
lengthMenu: [[15, 25, 50, -1], [15, 25, 50, "All"]]
});
@ -292,17 +302,17 @@ jumpserver.initDataTable = function (options) {
$('#op').html(options.op_html || '');
$('#uc').html(options.uc_html || '');
});
// $('.ipt_check_all').on('click', function() {
// if (!jumpserver.checked) {
// $(this).closest('table').find('.ipt_check').prop('checked', true);
// jumpserver.checked = true;
// table.rows().select();
// } else {
// $(this).closest('table').find('.ipt_check').prop('checked', false);
// jumpserver.checked = false;
// table.rows().deselect();
// }
// });
$('.ipt_check_all').on('click', function() {
if (!jumpserver.checked) {
$(this).closest('table').find('.ipt_check').prop('checked', true);
jumpserver.checked = true;
table.rows().select();
} else {
$(this).closest('table').find('.ipt_check').prop('checked', false);
jumpserver.checked = false;
table.rows().deselect();
}
});
return table;
};

View File

@ -91,7 +91,7 @@
<td class="text-center">{{ session.id | get_session_command_amount }}</td>
<td class="text-center">{{ session.date_start }}</td>
<td class="text-center">{{ session.date_end|default_if_none:now|timeuntil:session.date_start }}</td>
<td class="text-center">{{ session.date_end|timeuntil:session.date_start }}</td>
<td>
{% if session.is_finished %}
<a onclick="window.open('/luna/replay/{{ session.id }}','luna', 'height=600, width=800, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, location=no, status=no')" class="btn btn-xs btn-warning btn-replay" >{% trans "Replay" %}</a>

View File

@ -24,10 +24,10 @@
</div>
</div>
<div class="input-group">
<select class="select2 form-control" name="username">
<select class="select2 form-control" name="user">
<option value="">{% trans 'Select user' %}</option>
{% for u in user_list %}
<option value="{{ u }}" {% if u == username %} selected {% endif %}>{{ u }}</option>
<option value="{{ u }}" {% if u == user %} selected {% endif %}>{{ u }}</option>
{% endfor %}
</select>
</div>

View File

@ -88,8 +88,10 @@ function initTable() {
$(td).html(update_btn + del_btn)
}}],
ajax_url: '{% url "api-users:user-list" %}',
columns: [{data: "id"}, {data: "name" }, {data: "username" }, {data: "get_role_display" },
{data: "groups_display" }, {data: "is_valid" }, {data: "id" }],
columns: [
{data: "id"}, {data: "name" }, {data: "username" }, {data: "get_role_display" },
{data: "groups_display" }, {data: "is_valid" }, {data: "id" }
],
op_html: $('#actions').html()
};
table = jumpserver.initDataTable(options);

View File

@ -215,20 +215,20 @@ class LoginLogListView(DatetimeSearchMixin, ListView):
template_name = 'users/login_log_list.html'
model = LoginLog
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
username = keyword = ""
user = keyword = ""
date_to = date_from = None
date_format = '%m/%d/%Y'
def get_queryset(self):
self.username = self.request.GET.get('user', '')
self.user = self.request.GET.get('user', '')
self.keyword = self.request.GET.get("keyword", '')
queryset = super().get_queryset()
queryset = queryset.filter(
datetime__gt=self.date_from, datetime__lt=self.date_to
)
if self.username:
queryset = queryset.filter(username=self.username)
if self.user:
queryset = queryset.filter(username=self.user)
if self.keyword:
queryset = self.queryset.filter(
Q(ip__contains=self.keyword) |
@ -243,7 +243,7 @@ class LoginLogListView(DatetimeSearchMixin, ListView):
'action': _('Login log list'),
'date_from': self.date_from,
'date_to': self.date_to,
'username': self.username,
'user': self.user,
'keyword': self.keyword,
'user_list': set(LoginLog.objects.all().values_list('username', flat=True))
}

View File

@ -305,8 +305,8 @@ class UserGrantedAssetView(AdminUserRequiredMixin, DetailView):
def get_context_data(self, **kwargs):
context = {
'app': 'User',
'action': 'User granted asset',
'app': _('Users'),
'action': _('User granted assets'),
}
kwargs.update(context)
return super().get_context_data(**kwargs)
@ -319,8 +319,8 @@ class UserProfileView(LoginRequiredMixin, TemplateView):
from perms.utils import get_user_granted_assets
assets = get_user_granted_assets(self.request.user)
context = {
'app': 'User',
'action': 'User Profile',
'app': _('Users'),
'action': _('Profile'),
'assets': assets,
}
kwargs.update(context)
@ -345,8 +345,8 @@ class UserProfileUpdateView(LoginRequiredMixin, UpdateView):
def get_context_data(self, **kwargs):
context = {
'app': 'User',
'action': 'Profile update',
'app': _('User'),
'action': _('Profile setting'),
}
kwargs.update(context)
return super().get_context_data(**kwargs)
@ -363,8 +363,8 @@ class UserPasswordUpdateView(LoginRequiredMixin, UpdateView):
def get_context_data(self, **kwargs):
context = {
'app': 'User',
'action': 'Password update',
'app': _('Users'),
'action': _('Password update'),
}
kwargs.update(context)
return super().get_context_data(**kwargs)
@ -385,8 +385,8 @@ class UserPublicKeyUpdateView(LoginRequiredMixin, UpdateView):
def get_context_data(self, **kwargs):
context = {
'app': 'User',
'action': 'Public key update',
'app': _('Users'),
'action': _('Public key update'),
}
kwargs.update(context)
return super().get_context_data(**kwargs)

View File

@ -61,7 +61,7 @@ def start_gunicorn():
cmd += log
if DEBUG:
cmd += " --reload"
p = subprocess.call(cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr)
p = subprocess.Popen(cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr)
return p