# Path: cachemanage/models.py
# class Redislist(models.Model):
#     """
#     asset modle
#         create_time = models.DateTime(default=datetime.now)
#     """
#     redis_host=models.CharField(max_length=100, blank=True, null=True, verbose_name=u"redis_host")
#     redis_role = models.CharField(max_length=20, blank=True, null=True, verbose_name=u"redis_role")
# 
# 
#     def __unicode__(self):
#         return self.redis_host


from django.shortcuts import render
from juser.user_api import *
from cachemanage.models import Redislist
import os
import MySQLdb as mysql
import json



@require_role(role='user')
def cachemanage_index(request):
    path1="redismanage"
    path2="redisindex"


    return my_render('cachemanage/Main.htm', locals(), request)



def server_tree(request):

    return my_render('cachemanage/server_tree.html', locals(), request)

def overview(request):

    return my_render('cachemanage/overview.html', locals(), request)



# @require_role(role='user')
def nginxdata(request):
    if request.GET.get('nginx_host')=="nginx01_pv":
        c.execute("SELECT `time`,`nginx_pv` FROM `cachemansge_nginxstat` WHERE `host`=\"nginx01\"")
        ones = [[i[0] * 1000, i[1]] for i in c.fetchall()]
        data="%s(%s);"% (request.GET.get('callback'), json.dumps(ones))
        # return "%s(%s);" % (request.args.get('callback'), json.dumps(ones))

# Path: cachemanage/models.py
# class Redislist(models.Model):
#     """
#     asset modle
#         create_time = models.DateTime(default=datetime.now)
#     """
#     redis_host=models.CharField(max_length=100, blank=True, null=True, verbose_name=u"redis_host")
#     redis_role = models.CharField(max_length=20, blank=True, null=True, verbose_name=u"redis_role")
# 
# 
#     def __unicode__(self):
#         return self.redis_host


# Path: cachemanage/views.py
from django.shortcuts import render
from juser.user_api import *
from cachemanage.models import Redislist
import os
import MySQLdb as mysql
import json




@require_role(role='user')
def cachemanage_index(request):
    path1="redismanage"
    path2="redisindex"


    return my_render('cachemanage/Main.htm', locals(), request)



def server_tree(request):

    return my_render('cachemanage/server_tree.html', locals(), request)

def overview(request):

    return my_render('cachemanage/overview.html', locals(), request)



# @require_role(role='user')
def nginxdata(request):
    if request.GET.get('nginx_host')=="nginx01_pv":
        c.execute("SELECT `time`,`nginx_pv` FROM `cachemansge_nginxstat` WHERE `host`=\"nginx01\"")
        ones = [[i[0] * 1000, i[1]] for i in c.fetchall()]
        data="%s(%s);"% (request.GET.get('callback'), json.dumps(ones))
        # return "%s(%s);" % (request.args.get('callback'), json.dumps(ones))

        return HttpResponse(data)