mirror of https://github.com/jumpserver/jumpserver
				
				
				
			dashboard con
							parent
							
								
									67c1f12086
								
							
						
					
					
						commit
						9d44bc1593
					
				| 
						 | 
				
			
			@ -120,4 +120,4 @@ USE_TZ = False
 | 
			
		|||
 | 
			
		||||
STATIC_URL = '/static/'
 | 
			
		||||
 | 
			
		||||
SESSION_COOKIE_AGE = 3600
 | 
			
		||||
SESSION_COOKIE_AGE = 3600
 | 
			
		||||
| 
						 | 
				
			
			@ -2,8 +2,8 @@
 | 
			
		|||
 | 
			
		||||
import hashlib
 | 
			
		||||
import datetime
 | 
			
		||||
import json
 | 
			
		||||
 | 
			
		||||
from django.db.models import Q
 | 
			
		||||
from django.db.models import Count
 | 
			
		||||
from django.shortcuts import render_to_response
 | 
			
		||||
from django.http import HttpResponseRedirect
 | 
			
		||||
| 
						 | 
				
			
			@ -21,17 +21,23 @@ def md5_crypt(string):
 | 
			
		|||
def getDaysByNum(num):
 | 
			
		||||
    today = datetime.date.today()
 | 
			
		||||
    oneday = datetime.timedelta(days=1)
 | 
			
		||||
    li = []
 | 
			
		||||
    li_date, li_str = [], []
 | 
			
		||||
    for i in range(0, num):
 | 
			
		||||
        today = today-oneday
 | 
			
		||||
        li.append(str(today)[0:10])
 | 
			
		||||
    li.reverse()
 | 
			
		||||
    return li
 | 
			
		||||
        li_date.append(today)
 | 
			
		||||
        li_str.append(str(today)[0:10])
 | 
			
		||||
    li_date.reverse()
 | 
			
		||||
    li_str.reverse()
 | 
			
		||||
    t = (li_date, li_str)
 | 
			
		||||
    return t
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def index(request):
 | 
			
		||||
    path1, path2 = u'仪表盘', 'Dashboard'
 | 
			
		||||
    dic = {}
 | 
			
		||||
    li_date, li_str = getDaysByNum(7)
 | 
			
		||||
    li_str = json.dumps(li_str)
 | 
			
		||||
    print li_str
 | 
			
		||||
    today = datetime.datetime.now().day
 | 
			
		||||
    from_week = datetime.datetime.now() - datetime.timedelta(days=7)
 | 
			
		||||
    week_data = Log.objects.filter(start_time__range=[from_week, datetime.datetime.now()])
 | 
			
		||||
| 
						 | 
				
			
			@ -39,8 +45,10 @@ def index(request):
 | 
			
		|||
    for user in top_ten:
 | 
			
		||||
        username = user['user']
 | 
			
		||||
        li = []
 | 
			
		||||
        for t in getDaysByNum(7):
 | 
			
		||||
            times = week_data.filter(user=user).filter(start_time__gt=t).count()
 | 
			
		||||
        user_data = week_data.filter(user=username)
 | 
			
		||||
        for t in li_date:
 | 
			
		||||
            year, month, day = t.year, t.month, t.day
 | 
			
		||||
            times = user_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).count()
 | 
			
		||||
            li.append(times)
 | 
			
		||||
        dic[username] = li
 | 
			
		||||
    print dic
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -58,11 +58,13 @@
 | 
			
		|||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div>{{ li_str }}</div>
 | 
			
		||||
        <div id="high" style="width:100%;height:400px;"></div>
 | 
			
		||||
    </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
var cate = {{ li_str }};
 | 
			
		||||
$(function () {
 | 
			
		||||
    $('#high').highcharts({
 | 
			
		||||
        title: {
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +76,8 @@ $(function () {
 | 
			
		|||
            x: -20
 | 
			
		||||
        },
 | 
			
		||||
        xAxis: {
 | 
			
		||||
            categories: ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六','星期日']
 | 
			
		||||
            type: 'datetime',
 | 
			
		||||
            categories: cate
 | 
			
		||||
        },
 | 
			
		||||
        yAxis: {
 | 
			
		||||
            title: {
 | 
			
		||||
| 
						 | 
				
			
			@ -95,19 +98,6 @@ $(function () {
 | 
			
		|||
            verticalAlign: 'middle',
 | 
			
		||||
            borderWidth: 0
 | 
			
		||||
        },
 | 
			
		||||
{#        series: [{#}
 | 
			
		||||
{#            name: '{{ user }}',#}
 | 
			
		||||
{#            data: [5, 10, 20, 10, 8, 1, 0]#}
 | 
			
		||||
{#        }, {#}
 | 
			
		||||
{#            name: '广宏伟',#}
 | 
			
		||||
{#            data: [10, 11, 13, 12, 18, 11, 6]#}
 | 
			
		||||
{#        }, {#}
 | 
			
		||||
{#            name: '刘德华',#}
 | 
			
		||||
{#            data: [2, 2, 5, 6, 4, 7, 3]#}
 | 
			
		||||
{#        }, {#}
 | 
			
		||||
{#            name: '梁朝伟',#}
 | 
			
		||||
{#            data: [3, 4, 5, 8, 11, 15, 8]#}
 | 
			
		||||
{#        }]#}
 | 
			
		||||
        series: [
 | 
			
		||||
            {% for k,v in dic.items %}
 | 
			
		||||
                {name: '{{ k }}',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue