def hostDel(request): if request.method == 'POST': host_batch = request.GET.get('arg', '') host_id_all = str(request.POST.get('host_id_all', '')) if host_batch: for cmdb_host_id in host_id_all.split(','): bg_item = get_object(CmdbHost, cmdb_host_id=cmdb_host_id) bg_item.delete() return HttpResponse(u'删除成功')
def appDel(request): if request.method == 'POST': app_batch = request.GET.get('arg', '') cluster_id_all = str(request.POST.get('cluster_id_all', '')) if app_batch: for cluster_id in cluster_id_all.split(','): bg_item = get_object(CmdbAppCluster, id=cluster_id) bg_item.delete() return HttpResponse(u'删除成功')
def taskDel(request): bg_id = request.GET.get('bg_id', '') if bg_id: BgTaskManagement.objects.filter(bg_id=bg_id).delete() if request.method == 'POST': bg_batch = request.GET.get('arg', '') bg_id_all = str(request.POST.get('bg_id_all', '')) if bg_batch: for bg_id in bg_id_all.split(','): bg_item = get_object(BgTaskManagement, bg_id=bg_id) bg_item.delete() return HttpResponse(u'删除成功')
def taskEdit(request, bg_id): status = 0 obj = get_object(BgTaskManagement, bg_id=bg_id) if request.method == 'POST': bgform = BgForm(request.POST, instance=obj) if bgform.is_valid(): bgform.save() status = 1 else: status = 2 else: bgform = BgForm(instance=obj) return render(request, 'background/task_edit.html', locals())
def userEdit(request, acc_user_id): status = 0 obj = get_object(models.User, acc_user_id=acc_user_id) if request.method == 'POST': accfrom = accFrom(request.POST, instance=obj) if accfrom.is_valid(): accfrom.save() status = 1 else: status = 2 else: accform = accFrom(instance=obj) return render(request, 'account/user_edit.html', locals())
def taskLogDetail(request): bg_log_id = request.GET.get("bg_log_id") obj = get_object(BgTaskLog, bg_log_id=bg_log_id) log_dir = obj.bg_log_dir try: with open(log_dir, 'r+', encoding='utf-8') as f: log = f.read() log_info = log[0] print(log[0]) except: log_info = "日志还未生成完毕" return render(request, 'background/task_log_detail.html', locals(), { 'log': log_info, 'log_dir': log_dir })