Ejemplo n.º 1
0
def service_list(request):
    #print(request.POST)
    type = request.POST.get('type')
    if request.method == 'POST':
        obj,created = Type.objects.get_or_create(name=type)
        service = Service()
        form = ServiceForm(request.POST, instance=service)
        if form.is_valid():
            inst = form.save(commit=False)
            inst.type = obj
            inst.save()
            operate_log.delay(user=request.user.username,ip=request.META.get('HTTP_X_FORWARDED_FOR',request.META['REMOTE_ADDR']),type=u"添加服务",content=u"添加服务:{}".format(service.name))
            return JsonResponse({"status": u"添加成功"})
        else:
            return JsonResponse({"status": u"添加失败", "msg": u"服务名称已存在"})
    types = Type.objects.all()
    #suppliers = Supplier.objects.all()
    services = Service.objects.all()
    form_ser = ServiceForm()
    #form_sup = SupplierForm()
    return render(request, 'service_list.html', locals())
Ejemplo n.º 2
0
def service_operate(request,id):
    service = get_object_or_404(Service, pk=id)
    if request.method == 'DELETE':
        service.delete()
        operate_log.delay(user=request.user.username,ip=request.META.get('HTTP_X_FORWARDED_FOR',request.META['REMOTE_ADDR']),type=u"删除服务",content=u"删除服务:{}".format(service.name))
        return JsonResponse({"status": u"删除成功"})
    if request.method == 'POST':
        type = request.POST.get('type')
        #create_date = request.POST.get('create_date')
        end_date = request.POST.get('end_date')
        obj,created = Type.objects.get_or_create(name=type)
        form = ServiceForm(request.POST, instance=service)
        if form.is_valid():
            inst = form.save(commit=False)
            inst.type = obj
            #if create_date:
            #    inst.create_date = datetime.datetime.strptime(create_date,"%Y-%m-%d")
            if end_date:
                inst.end_date = datetime.datetime.strptime(end_date,"%Y-%m-%d")
            inst.save()
            operate_log.delay(user=request.user.username,ip=request.META.get('HTTP_X_FORWARDED_FOR',request.META['REMOTE_ADDR']),type=u"更新服务",content=u"更新服务:{}".format(service.name))
            return JsonResponse({"status": u"更新成功"})
        else:
            return JsonResponse({"status": u"更新失败", "msg": u"服务名称已存在"})
    types = Type.objects.all()
    form = ServiceForm(instance=service)
    return render(request, 'service_operate.html', locals())
Ejemplo n.º 3
0
def service_edit(request):
    """ 编辑服务 """
    uuid = request.GET.get('uuid', '')
    service = get_object_or_404(Service, uuid=uuid)
    if request.method == 'POST':
        sf = ServiceForm(request.POST, instance=service)
        if sf.is_valid():
            sf.save()
            return HttpResponseRedirect("/assets/service_list/")
    else:
        sf = ServiceForm(instance=service)
        return my_render('assets/service_edit.html', locals(), request)
Ejemplo n.º 4
0
def service_add(request):
    """ 添加服务 """
    sf = ServiceForm()
    if request.method == 'POST':
        sf_post = ServiceForm(request.POST)
        print 'ok'
        if sf_post.is_valid():
            print 'ok2'
            service_port = sf_post.cleaned_data.get('port')
            print service_port
            sf_post.save()
            if zabbix_on and service_port:
                ret = zabbix_template_add(request)
            return HttpResponseRedirect('/assets/service_list/')
    return my_render('assets/service_add.html', locals(), request)