Beispiel #1
0
def tenant_tpl_add(request):
    if request.method == 'POST':
        try:
            excel_file = request.FILES.get('tpl_file', '')
            env_type = request.POST.get("env_type")
            data = xlrd.open_workbook(filename=None,file_contents=excel_file.read())
            table1 = data.sheets()[0]
            nrows = table1.nrows
            error_msg = ""
            for i in range(1, nrows):
                new_data = table1.row_values(i)
                print new_data
                new_tenant = Tenant_info()
                new_tenant.tenant_name = new_data[0]
                new_tenant.user_name = new_data[1]
                new_tenant.user_passwd = new_data[2]
                new_tenant.admin_host = new_data[3]
                new_tenant.net_work = new_data[4]
                new_tenant.env_type = env_type
                new_tenant.comments = new_data[5]
                new_tenant.save()

        except Exception as e:
            print e
            return HttpResponse("error")
        if error_msg!="":
            return HttpResponse(error_msg)
        return HttpResponse("true")
Beispiel #2
0
def tenant_batch_add(requset):
    if requset.method == "POST":
        batch_info = requset.POST.get("batch_add",None)
        env_type =  requset.POST.get("env_type",None)
        print env_type
        if batch_info:
            for item in  batch_info.split(";"):
                if item =="":
                    continue
                try:
                    item =  item.strip().split("|")
                    tenant_obj = Tenant_info()
                    tenant_obj.tenant_name = item[0]
                    tenant_obj.user_name = item[1]
                    tenant_obj.user_passwd = item[2]
                    tenant_obj.admin_host = item[3]
                    tenant_obj.net_work = item[4]
                    tenant_obj.comments = item[5]
                    if env_type == "all":
                        tenant_obj.env_type = item[6]
                    else:
                        tenant_obj.env_type = env_type
                    tenant_obj.save()
                except Exception as e:
                    continue
    return HttpResponse("true")