Exemplo n.º 1
0
Arquivo: node.py Projeto: solupro/ysfc
def add(request):
	post = {}

	if request.method == 'POST':
		post = request.POST.copy()
		form = NodeForm(post)
		form.node = None
		if not form.is_valid():
			for field in form.errors:
				messages.info(request, form[field].errors.as_text())
		elif getattr(request.session.get('user', ''), 'id', 0) != 1:
			messages.info(request, 'You are not the manager!')
		else:
			cd = form.cleaned_data

			nodeclass = None
			try:
				nodeclass = Nodeclass.objects.get(name=cd['nodeclass'])
			except Exception, e:
				print e
				nodeclass = Nodeclass(name=cd['nodeclass'])
				nodeclass.save()

			node = Node(name=cd['name'], site=cd['site'], description=cd['description'], \
						status=cd['status'], nodeclass=nodeclass, date=int(time.time()))
			node.save()
			messages.info(request, '节点创建成功!')
			return redirect('/')
Exemplo n.º 2
0
Arquivo: node.py Projeto: solupro/ysfc
		form = NodeForm(post)
		form.node = node
		if not form.is_valid():
			for field in form.errors:
				messages.info(request, form[field].errors.as_text())
		elif getattr(request.session['user'], 'id', 0) != 1:
			messages.info(request, 'You are not the manager!')
		else:
			cd = form.cleaned_data

			nodeclass = None
			try:
				nodeclass = Nodeclass.objects.get(name=cd['nodeclass'])
			except Exception, e:
				print e
				nodeclass = Nodeclass(name=cd['nodeclass'])
				nodeclass.save()
			node.name = cd['name']
			node.site = cd['site']
			node.description = cd['description']
			node.status = cd['status']
			node.nodeclass = nodeclass
			node.date = int(time.time())

			node.save()
			messages.info(request, '节点更新成功!')
			return redirect('/')

	form = NodeForm(initial={
		'name' : request.POST.get('name', ''),
		'site' : request.POST.get('site', ''),