コード例 #1
0
ファイル: views.py プロジェクト: 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	
コード例 #2
0
ファイル: views.py プロジェクト: helloworldlanou/example
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	
コード例 #3
0
ファイル: views.py プロジェクト: helloworldlanou/example
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	
コード例 #4
0
ファイル: views.py プロジェクト: binhngoc17/deck-shipyard
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))
コード例 #5
0
ファイル: views.py プロジェクト: swipswaps/shipyard
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))
コード例 #6
0
ファイル: views.py プロジェクト: valberg/shipyard
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))
コード例 #7
0
ファイル: views.py プロジェクト: cloud-school/shipyard
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))