Exemplo n.º 1
0
Arquivo: views.py Projeto: coscl/OADT
def add(request):
	if request.method == 'POST':
#		post = request.POST
		form = HostForm(request.POST)
		logger.info("add the host ." )
		ret = False
		response = HttpResponse()	
		if form.is_valid():		
			try:		
				form.save()
				h = Host.objects.get(pk = form.cleaned_data['hostname'])
				add_one_host.delay(h)
				ret = True
				logger.info("Host has been added.")	
#			except  Exception,ex:
#				print Exception,":",ex
#				response.status_code = 500
#				h.delete()
#				logger.error("add host error!" + str(ex))
#				ret = str(ex)
			except  SystemExit:
				response.status_code = 500
				logger.error("add node error!")
				ret = str("添加主机节点失败,请检查日志文件")
		else:		
			logger.info("host info not valided")
			response.status_code = 500	
			ret = str(form.errors)	
		response.write(ret)
		return response	
Exemplo n.º 2
0
def add(request):
	if request.method == 'POST':
		post = request.POST
		form = HostForm(request.POST)
		logger.info("add the host ." )
		ret = False
		response = HttpResponse()	
		if form.is_valid():		
			try:		
				form.save()
				h = Host.objects.get(pk = form.cleaned_data['hostname'])
				ret = True
				logger.info("Host has been added.")	
			except  Exception,ex:
				print Exception,":",ex
				response.status_code = 500
				h.delete()
				logger.error("add host error!" + str(ex))
				ret = str(ex)
		else:		
			logger.info("host info not valided")
			response.status_code = 500	
			ret = str(form.errors)	
		response.write(ret)
		return response	
Exemplo n.º 3
0
def add_host(request):
    form = HostForm()
    if request.method == 'POST':
        form = HostForm(request.POST)
        form.owner = request.user
        if form.is_valid():
            form.save()
            return redirect(reverse('hosts.views.index'))
    ctx = {'form': form}
    return render_to_response('hosts/add_host.html',
                              ctx,
                              context_instance=RequestContext(request))
Exemplo n.º 4
0
def add_host(request):
    form = HostForm()
    if request.method == 'POST':
        form = HostForm(request.POST)
        form.owner = request.user
        if form.is_valid():
            form.save()
            return redirect(reverse('hosts.views.index'))
    ctx = {
        'form': form
    }
    return render_to_response('hosts/add_host.html', ctx,
        context_instance=RequestContext(request))
Exemplo n.º 5
0
def edit_host(request, host_id):
    h = Host.objects.get(id=host_id)
    form = HostForm(instance=h)
    if request.method == 'POST':
        form = HostForm(request.POST, instance=h)
        form.owner = request.user
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.INFO,
                                 _('Updated') + ' {0}'.format(h.name))
            return redirect(reverse('hosts.views.index'))
    ctx = {'form': form}
    return render_to_response('hosts/edit_host.html',
                              ctx,
                              context_instance=RequestContext(request))
Exemplo n.º 6
0
def update(request,hostname):
	host = get_object_or_404(Host,pk=hostname)
	ret = False	
	if request.method == 'POST':
		logger.info("To update the host %s." % hostname)
		post = request.POST
		form = HostForm(request.POST,instance=host)
		if form.is_valid():
			form.save()
			ret = True
			logger.info("Host has been update.")	
		else:
			logger.info("host info not valided")
	response = HttpResponse()
	response.write(ret)
	return response	
Exemplo n.º 7
0
def edit_host(request, host_id):
    h = Host.objects.get(id=host_id)
    form = HostForm(instance=h)
    if request.method == 'POST':
        form = HostForm(request.POST, instance=h)
        form.owner = request.user
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.INFO, _('Updated') + ' {0}'.format(
                h.name))
            return redirect(reverse('hosts.views.index'))
    ctx = {
        'form': form
    }
    return render_to_response('hosts/edit_host.html', ctx,
        context_instance=RequestContext(request))