Commit d0600662 authored by halcyon's avatar halcyon

dashboard and bugs

parent e086a036
......@@ -4,13 +4,12 @@ from django.db.models import Q
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from models import IDC, Asset, BisGroup
from juser.models import UserGroup
from connect import PyCrypt, KEY
from jlog.models import Log
from jumpserver.views import jasset_group_add, jasset_host_edit, pages, page_list_return
from jumpserver.views import jasset_group_add, jasset_host_edit, pages
cryptor = PyCrypt(KEY)
......@@ -143,20 +142,8 @@ def batch_host_edit(request):
def list_host(request):
header_title, path1, path2 = u'查看主机', u'资产管理', u'查看主机'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
posts = contact_list = Asset.objects.all().order_by('ip')
p = paginator = Paginator(contact_list, 10)
try:
current_page = int(request.GET.get('page', '1'))
except ValueError:
current_page = 1
page_range = page_list_return(len(p.page_range), current_page)
try:
contacts = paginator.page(current_page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
posts = Asset.objects.all().order_by('ip')
contact_list, p, contacts, page_range, current_page = pages(posts, request)
return render_to_response('jasset/host_list.html', locals(), context_instance=RequestContext(request))
......@@ -311,7 +298,7 @@ def edit_group(request):
group.asset_set.add(g)
BisGroup.objects.filter(id=group_id).update(name=j_group, comment=j_comment)
smg = u'主机组%s修改成功' % j_group
return HttpResponseRedirect('/jasset/group_detail/%s' % group_id)
return HttpResponseRedirect('/jasset/group_detail/?id=%s' % group_id)
return render_to_response('jasset/group_add.html', locals(), context_instance=RequestContext(request))
......@@ -319,47 +306,30 @@ def edit_group(request):
def detail_group(request):
header_title, path1, path2 = u'主机组详情', u'资产管理', u'主机组详情'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
offset = request.GET.get('id')
group_name = BisGroup.objects.get(id=offset).name
b = BisGroup.objects.get(id=offset)
posts = contact_list = Asset.objects.filter(bis_group=b).order_by('ip')
p = paginator = Paginator(contact_list, 5)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
group_id = request.GET.get('id')
group_name = BisGroup.objects.get(id=group_id).name
b = BisGroup.objects.get(id=group_id)
posts = Asset.objects.filter(bis_group=b).order_by('ip')
contact_list, p, contacts, page_range, current_page = pages(posts, request)
return render_to_response('jasset/group_detail.html', locals(), context_instance=RequestContext(request))
def detail_idc(request):
header_title, path1, path2 = u'主机组详情', u'资产管理', u'主机组详情'
header_title, path1, path2 = u'IDC详情', u'资产管理', u'IDC详情'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
offset = request.GET.get('id')
idc_name = IDC.objects.get(id=offset).name
b = IDC.objects.get(id=offset)
posts = contact_list = Asset.objects.filter(idc=b).order_by('ip')
p = paginator = Paginator(contact_list, 5)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
idc_id = request.GET.get('id')
idc_name = IDC.objects.get(id=idc_id).name
b = IDC.objects.get(id=idc_id)
posts = Asset.objects.filter(idc=b).order_by('ip')
contact_list, p, contacts, page_range, current_page = pages(posts, request)
return render_to_response('jasset/idc_detail.html', locals(), context_instance=RequestContext(request))
def group_del_host(request, offset):
if request.method == 'POST':
group_name = request.POST.get('group_name')
print group_name
if offset == 'group':
group = BisGroup.objects.get(name=group_name)
elif offset == 'idc':
......@@ -367,14 +337,15 @@ def group_del_host(request, offset):
len_list = request.POST.get("len_list")
for i in range(int(len_list)):
key = "id_list[" + str(i) + "]"
print key
jid = request.POST.get(key)
print jid
g = Asset.objects.get(id=jid)
print g
group.asset_set.remove(g)
print 'ok'
return HttpResponseRedirect('/jasset/%s_detail/%s' % (offset, group.id))
if offset == 'group':
group.asset_set.remove(g)
elif offset == 'idc':
Asset.objects.filter(id=jid).delete()
BisGroup.objects.filter(name=g.ip).delete()
return HttpResponseRedirect('/jasset/%s_detail/?id=%s' % (offset, group.id))
def group_del(request, offset):
......@@ -388,9 +359,7 @@ def host_search(request):
posts = Asset.objects.filter(Q(ip__contains=keyword) | Q(idc__name__contains=keyword) |
Q(bis_group__name__contains=keyword) | Q(
comment__contains=keyword)).distinct().order_by('ip')
print posts
contact_list, p, contacts = pages(posts, request)
print contact_list, p, contacts
contact_list, p, contacts, page_range, current_page = pages(posts, request)
return render_to_response('jasset/host_search.html', locals(), context_instance=RequestContext(request))
......
......@@ -89,6 +89,7 @@ def index(request):
hosts = Asset.objects.all()
online_host = Log.objects.filter(is_finished=0)
online_user = online_host.distinct()
top_dic = {'活跃用户数': [8, 10, 5, 9, 8, 12, 3], '活跃主机数': [10, 16, 20, 8, 9, 5, 9], '登录次数': [20, 30, 35, 18, 40, 38, 65]}
return render_to_response('index.html', locals(), context_instance=RequestContext(request))
......@@ -121,7 +122,6 @@ def page_list_return(total, current=1):
return range(min_page, max_page+1)
def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment):
groups = []
is_active = {u'是': '1', u'否': '2'}
......@@ -154,19 +154,22 @@ def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_com
def pages(posts, r):
"""分页公用函数"""
contact_list = posts
p = paginator = Paginator(contact_list, 10)
p = paginator = Paginator(contact_list, 20)
try:
page = int(r.GET.get('page', '1'))
current_page = int(r.GET.get('page', '1'))
except ValueError:
page = 1
current_page = 1
page_range = page_list_return(len(p.page_range), current_page)
try:
contacts = paginator.page(page)
contacts = paginator.page(current_page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return contact_list, p, contacts
return contact_list, p, contacts, page_range, current_page
def login(request):
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -21,6 +21,7 @@
<!-- highcharts -->
<script src="/static/js/highcharts/highcharts.js"></script>
<script src="/static/js/highcharts/highstock.js"></script>
<!-- active menu -->
<script>
......
......@@ -58,9 +58,11 @@
</div>
</div>
</div>
<div id="usertop10" style="width:100%;height:400px;"></div>
<div id="hosttop10" style="width:100%;height:400px; margin-top:170px"></div>
</br>
<div id="top10" style="width:100%;height:400px;"></div>
<div id="usertop10" style="width:100%;height:400px;margin-top:170px"></div>
<br/>
<div id="hosttop10" style="width:100%;height:400px;"></div>
<br/>
<div id="dynamic" style="width:100%;height:400px;"></div>
</div>
</div>
......@@ -68,6 +70,53 @@
<script>
var cate = {{ li_str|safe }};
$(function () {
$('#top10').highcharts({
title: {
text: '数据总览',
x: -20 //center
},
subtitle: {
text: 'Source: JumpServer',
x: -20
},
rangeSelector: {
allButtonsEnabled: true,
selected: 2
},
xAxis: {
type: 'datetime',
categories: cate
},
yAxis:{
min: 0,
title: {
text: '登录次数'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: '次'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [
{% for k,v in top_dic.items %}
{
name: '{{ k }}',
data: {{ v }}
},
{% endfor %}
]
});
$('#usertop10').highcharts({
title: {
text: '一周用户登录TOP10',
......
......@@ -80,18 +80,29 @@
<ul class="pagination" style="margin-top: 0; float: right">
{% if contacts.has_previous %}
<li><a href="?page={{ contacts.previous_page_number }}">&laquo;</a></li>
<li class="paginate_button previous" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="?id={{ group_id }}&page={{ contacts.previous_page_number }}">Previous</a>
</li>
{% else %}
<li class="paginate_button previous disabled" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="#">Previous</a>
</li>
{% endif %}
{% for page in p.page_range %}
{% ifequal offset1 page %}
<li class="active"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% for page in page_range %}
{% ifequal current_page page %}
<li class="paginate_button active" aria-controls="editable" tabindex="0"><a href="?id={{ group_id }}&page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% else %}
<li><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?id={{ group_id }}&page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% endifequal %}
{% endfor %}
{% if contacts.has_next %}
<li><a href="?page={{ contacts.next_page_number }}">&raquo;</a></li>
<li class="paginate_button next" aria-controls="editable" tabindex="0" id="editable_next">
<a href="?id={{ group_id }}&page={{ contacts.next_page_number }}">Next</a>
</li>
{% else %}
<li class="paginate_button next disabled" aria-controls="editable" tabindex="0" id="editable_next">
<a href="#">Next</a>
</li>
{% endif %}
</ul>
</div>
......@@ -157,7 +168,7 @@
url: "/jasset/group_del_host/group/",
data: {"id_list": id_list, "len_list": j, "group_name": group_name},
success: function (data) {
window.open(window.location.pathname, "_self");
window.open(window.location.href, "_self");
}
});
}
......
......@@ -45,18 +45,29 @@
<ul class="pagination" style="margin-top: 0; float: right">
{% if contacts.has_previous %}
<li><a href="?page={{ contacts.previous_page_number }}">&laquo;</a></li>
<li class="paginate_button previous" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="?id={{ group_id }}&page={{ contacts.previous_page_number }}">Previous</a>
</li>
{% else %}
<li class="paginate_button previous disabled" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="#">Previous</a>
</li>
{% endif %}
{% for page in p.page_range %}
{% ifequal offset1 page %}
<li class="active"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% for page in page_range %}
{% ifequal current_page page %}
<li class="paginate_button active" aria-controls="editable" tabindex="0"><a href="?keyword={{ keyword }}&page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% else %}
<li><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?keyword={{ keyword }}&page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% endifequal %}
{% endfor %}
{% if contacts.has_next %}
<li><a href="?page={{ contacts.next_page_number }}">&raquo;</a></li>
<li class="paginate_button next" aria-controls="editable" tabindex="0" id="editable_next">
<a href="?id={{ group_id }}&page={{ contacts.next_page_number }}">Next</a>
</li>
{% else %}
<li class="paginate_button next disabled" aria-controls="editable" tabindex="0" id="editable_next">
<a href="#">Next</a>
</li>
{% endif %}
</ul>
</div>
......
......@@ -80,7 +80,7 @@
{% if contacts.has_previous %}
<li class="paginate_button previous" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="?page={{ contacts.previous_page_number }}">Previous</a>
<a href="?id={{ idc_id }}&page={{ contacts.previous_page_number }}">Previous</a>
</li>
{% else %}
<li class="paginate_button previous disabled" aria-controls="editable" tabindex="0" id="editable_previous">
......@@ -89,14 +89,14 @@
{% endif %}
{% for page in page_range %}
{% ifequal current_page page %}
<li class="paginate_button active" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
<li class="paginate_button active" aria-controls="editable" tabindex="0"><a href="?id={{ idc_id }}&page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% else %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?id={{ idc_id }}&page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% endifequal %}
{% endfor %}
{% if contacts.has_next %}
<li class="paginate_button next" aria-controls="editable" tabindex="0" id="editable_next">
<a href="?page={{ contacts.next_page_number }}">Next</a>
<a href="?id={{ idc_id }}&page={{ contacts.next_page_number }}">Next</a>
</li>
{% else %}
<li class="paginate_button next disabled" aria-controls="editable" tabindex="0" id="editable_next">
......@@ -167,7 +167,7 @@
url: "/jasset/group_del_host/idc/",
data: {"id_list": id_list, "len_list": j, "group_name": group_name},
success: function (data) {
window.open(window.location.pathname, "_self");
window.open(window.location.href, "_self");
}
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment