# Path: hostlist/models.py
# class DzhUser(models.Model):
#     username = models.CharField(max_length=30, blank=True, verbose_name=u'用户名')
#     engineer = models.CharField(max_length=30, blank=True, verbose_name=u'维护人员')
# 
#     def __unicode__(self):
#         return u'%s %s' % (self.username, self.engineer)
# 
# class DataCenter(models.Model):
#     dc_en = models.CharField(max_length=30, blank=True, verbose_name=u'机房简称')
#     dc_cn = models.CharField(max_length=30, blank=True, verbose_name=u'机房全称')
# 
#     def __unicode__(self):
#         return u'%s %s' % (self.dc_en, self.dc_cn)
# 
# class HostList(models.Model):
#     ip = models.CharField(max_length=15, blank=True, verbose_name=u'IP地址')
#     hostname = models.CharField(max_length=30, verbose_name=u'主机名')
#     minion_id = models.CharField(max_length=60, verbose_name=u'MinionID')
#     no_cn = models.CharField(max_length=30, verbose_name=u'运营商全称')
#     category_cn = models.CharField(max_length=30, blank=True, verbose_name=u'类别')
#     pa_cn = models.CharField(max_length=30, verbose_name=u'地区全称')
#     dc_cn = models.CharField(max_length=30, blank=True, verbose_name=u'机房全称')
#     engineer = models.CharField(max_length=30, blank=True, verbose_name=u'维护人员')
#     mac_addr = models.CharField(max_length=20, blank=True, verbose_name=u'MAC地址')
#     main_source_ip = models.CharField(max_length=30, blank=True, verbose_name=u'主行情源')
#     backup_source_ip = models.CharField(max_length=30, blank=True, verbose_name=u'备行情源')
#     # dccn = models.ForeignKey(dataCenter, related_name='datacenter_hostlist')
#     lic_date = models.CharField(max_length=30, blank=True, verbose_name=u'授权日期')
#     lic_status = models.CharField(max_length=30, blank=True, verbose_name=u'授权状态')
#     # engineer = models.ForeignKey(dzhuser, related_name='dzhuser_hostlist')
#     id_ip = models.CharField(max_length=15, blank=True, verbose_name=u'MinionID中的IP地址')
#     ip_same = models.CharField(max_length=10, blank=True, verbose_name=u'IP地址一致性')
#     remark = models.TextField(max_length=200, blank=True, verbose_name=u'备注')
# 
#     def __unicode__(self):
#         return u'%s %s %s %s %s' % (self.hostname, self.ip, self.category_cn, self.dc_cn, self.engineer)
# 
#     class Meta:
#         ordering = ['minionid']


from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_GET
from hostlist.models import DzhUser, DataCenter, HostList
import logging
        {
            'dc_dict': dc_dict,
            'engi_dict': engi_dict,
            'serv_list': srv_list
        }
    )


@login_required
@require_GET
def asset_list_api(request):
    """
    当前端选择机房与维护人员的时候，通过该接口提交请求并返回数据；
    :param request:
    :return:
    """
    user = request.user.username

    dc = request.GET.get('dcen', '')
    eg = request.GET.get('engi', '')
    result = []
    if dc == 'All_DC' and eg == 'ALL_ENGI':
        result = HostList.objects.all()
    elif dc == 'All_DC' and eg != 'ALL_ENGI':
        eg_result = DzhUser.objects.get(username=eg)
        result = HostList.objects.filter(engineer=eg_result.engineer)
    elif dc != 'All_DC' and eg == 'ALL_ENGI':
        dc_result = DataCenter.objects.get(dcen=dc)
        result = HostList.objects.filter(dccn=dc_result.dccn)
    elif dc != 'All_DC' and eg != 'ALL_ENGI':

# Path: hostlist/models.py
# class DzhUser(models.Model):
#     username = models.CharField(max_length=30, blank=True, verbose_name=u'用户名')
#     engineer = models.CharField(max_length=30, blank=True, verbose_name=u'维护人员')
# 
#     def __unicode__(self):
#         return u'%s %s' % (self.username, self.engineer)
# 
# class DataCenter(models.Model):
#     dc_en = models.CharField(max_length=30, blank=True, verbose_name=u'机房简称')
#     dc_cn = models.CharField(max_length=30, blank=True, verbose_name=u'机房全称')
# 
#     def __unicode__(self):
#         return u'%s %s' % (self.dc_en, self.dc_cn)
# 
# class HostList(models.Model):
#     ip = models.CharField(max_length=15, blank=True, verbose_name=u'IP地址')
#     hostname = models.CharField(max_length=30, verbose_name=u'主机名')
#     minion_id = models.CharField(max_length=60, verbose_name=u'MinionID')
#     no_cn = models.CharField(max_length=30, verbose_name=u'运营商全称')
#     category_cn = models.CharField(max_length=30, blank=True, verbose_name=u'类别')
#     pa_cn = models.CharField(max_length=30, verbose_name=u'地区全称')
#     dc_cn = models.CharField(max_length=30, blank=True, verbose_name=u'机房全称')
#     engineer = models.CharField(max_length=30, blank=True, verbose_name=u'维护人员')
#     mac_addr = models.CharField(max_length=20, blank=True, verbose_name=u'MAC地址')
#     main_source_ip = models.CharField(max_length=30, blank=True, verbose_name=u'主行情源')
#     backup_source_ip = models.CharField(max_length=30, blank=True, verbose_name=u'备行情源')
#     # dccn = models.ForeignKey(dataCenter, related_name='datacenter_hostlist')
#     lic_date = models.CharField(max_length=30, blank=True, verbose_name=u'授权日期')
#     lic_status = models.CharField(max_length=30, blank=True, verbose_name=u'授权状态')
#     # engineer = models.ForeignKey(dzhuser, related_name='dzhuser_hostlist')
#     id_ip = models.CharField(max_length=15, blank=True, verbose_name=u'MinionID中的IP地址')
#     ip_same = models.CharField(max_length=10, blank=True, verbose_name=u'IP地址一致性')
#     remark = models.TextField(max_length=200, blank=True, verbose_name=u'备注')
# 
#     def __unicode__(self):
#         return u'%s %s %s %s %s' % (self.hostname, self.ip, self.category_cn, self.dc_cn, self.engineer)
# 
#     class Meta:
#         ordering = ['minionid']


# Path: hostlist/views.py
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_GET
from hostlist.models import DzhUser, DataCenter, HostList
import logging

        {
            'dc_dict': dc_dict,
            'engi_dict': engi_dict,
            'serv_list': srv_list
        }
    )


@login_required
@require_GET
def asset_list_api(request):
    """
    当前端选择机房与维护人员的时候，通过该接口提交请求并返回数据；
    :param request:
    :return:
    """
    user = request.user.username

    dc = request.GET.get('dcen', '')
    eg = request.GET.get('engi', '')
    result = []
    if dc == 'All_DC' and eg == 'ALL_ENGI':
        result = HostList.objects.all()
    elif dc == 'All_DC' and eg != 'ALL_ENGI':
        eg_result = DzhUser.objects.get(username=eg)
        result = HostList.objects.filter(engineer=eg_result.engineer)
    elif dc != 'All_DC' and eg == 'ALL_ENGI':
        dc_result = DataCenter.objects.get(dcen=dc)
        result = HostList.objects.filter(dccn=dc_result.dccn)
    elif dc != 'All_DC' and eg != 'ALL_ENGI':

        eg_result = DzhUser.objects.get(username=eg)