コード例 #1
0
ファイル: node.py プロジェクト: 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('/')
コード例 #2
0
ファイル: node.py プロジェクト: solupro/ysfc
				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('/')

	form = NodeForm(initial={
		'name' : request.POST.get('name', ''),
		'site' : request.POST.get('site', ''),
		'description': request.POST.get('description', ''),
		'status' : request.POST.get('status', 1),
		'nodeclass' : request.POST.get('nodeclass', ''),
	})
	return render_to_response('node_add.html',{'form':form}, context_instance=RequestContext(request))


def show(request, node_site='', page=1):
	node = None
	try:
		node = Node.objects.get(site=node_site)
	except Exception, e:
		print e
		messages.info(request, 'The node does not exists!')
	if node:
		page = page if page >= 1 else 1