Commit dc11f345 authored by ibuler's avatar ibuler

添加IDC的支持

parent a5c3048a
......@@ -2,11 +2,18 @@ from django.db import models
from UserManage.models import User
class IDC(models.Model):
name = models.CharField(max_length=20)
def __unicode__(self):
return self.name
class Assets(models.Model):
id = models.AutoField(primary_key=True)
ip = models.CharField(max_length=20)
port = models.IntegerField(max_length=5)
idc = models.CharField(max_length=50)
idc = models.ForeignKey(IDC)
comment = models.CharField(max_length=100, blank=True, null=True)
def __unicode__(self):
......@@ -15,4 +22,6 @@ class Assets(models.Model):
class AssetsUser(models.Model):
uid = models.ForeignKey(User)
aid = models.ForeignKey(Assets)
\ No newline at end of file
aid = models.ForeignKey(Assets)
......@@ -20,6 +20,9 @@ urlpatterns = patterns('',
(r'^showGroup/$', views.showGroup),
(r'^addGroup/$', views.addGroup),
(r'^chgGroup/$', views.chgGroup),
(r'^showIDC/$', views.showGroup),
(r'^addIDC/$', views.addGroup),
(r'^chgIDC/$', views.chgGroup),
(r'^showSudo/$', views.showSudo),
(r'^chgSudo/$', views.chgSudo),
(r'^showAssets/$', views.showAssets),
......
......@@ -5,7 +5,7 @@ from django.template import RequestContext
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from UserManage.models import User, Group, Logs, Pid
from Assets.models import Assets, AssetsUser
from Assets.models import Assets, AssetsUser, IDC
import subprocess
from Crypto.Cipher import AES
from binascii import b2a_hex, a2b_hex
......@@ -599,10 +599,15 @@ def chgGroup(request):
group_id = request.GET.get('id')
group = Group.objects.get(id=group_id)
else:
group_id = request.POST.get('id')
group_name = request.POST.get('name')
group_id = request.POST.filter('id')
if group_id:
group_id = group_id[0]
group_name = request.POST.get('name')
else:
return HttpResponseRedirect('/showGroup/')
if not group_name:
error = u'不能为空'
return render_to_response('info.html', {'error': error})
else:
group = Group.objects.get(id=group_id)
group.name = group_name
......@@ -613,6 +618,68 @@ def chgGroup(request):
context_instance=RequestContext(request))
@superuser_required
def showIDC(request):
error = ''
msg = ''
idcs = IDC.objects.all()
if request.method == 'POST':
selected_idc = request.REQUEST.getlist('selected')
if selected_idc:
for idc_id in selected_idc:
idc = IDC.objects.get(id=idc_id)
idc.delete()
msg = '删除成功'
return render_to_response('showIDC.html',
{'idcs': idcs, 'error': error, 'msg': msg, 'asset_menu': 'active'},
context_instance=RequestContext(request))
@superuser_required
def chgIDC(request):
error = ''
msg = ''
if request.method == 'GET':
idc_id = request.GET.filter('id')
if idc_id:
idc_id = idc_id[0]
idc = Group.objects.get(id=idc_id)
else:
return HttpResponseRedirect('/showIDC/')
else:
idc_id = request.POST.get('id')
idc_name = request.POST.get('name')
if not idc_name:
error = u'不能为空'
return render_to_response('info.html', {'error': error})
else:
idc = Group.objects.get(id=idc_id)
idc.name = idc_name
idc.save()
msg = u'修改成功'
return render_to_response('chgGroup.html', {'group': idc, 'error': error, 'msg': msg, 'asset_menu': 'active'},
context_instance=RequestContext(request))
@superuser_required
def addIDC(request):
error = ''
msg = ''
if request.method == 'POST':
idc_name = request.POST.get('name')
if idc_name:
group = Group(name=idc_name)
group.save()
msg = u'%s IDC添加成功' % idc_name
else:
error = u'不能为空'
return render_to_response('addIDC.html',
{'error': error, 'msg': msg, 'user_menu': 'active'},
context_instance=RequestContext(request))
@admin_required
def showSudo(request):
if request.method == 'GET':
......@@ -728,12 +795,15 @@ def addAssets(request):
"""添加服务器"""
error = ''
msg = ''
idcs = IDC.objects.all()
if request.method == 'POST':
ip = request.POST.get('ip')
port = request.POST.get('port')
idc = request.POST.get('idc')
comment = request.POST.get('comment')
idc = IDC.objects.get(id=idc)
if '' in (ip, port):
error = '带*号内容不能为空。'
elif Assets.objects.filter(ip=ip):
......@@ -743,7 +813,7 @@ def addAssets(request):
asset.save()
msg = u'%s 添加成功' % ip
return render_to_response('addAssets.html', {'msg': msg, 'error': error, 'asset_menu': 'active'},
return render_to_response('addAssets.html', {'msg': msg, 'error': error, 'idcs': idcs, 'asset_menu': 'active'},
context_instance=RequestContext(request))
......
......@@ -28,7 +28,11 @@
<div class="form-group">
<label for="idc" class="col-sm-2 control-label">IDC<span style="color: red"> *</span></label>
<div class="col-sm-4">
<input type="text" class="form-control" id="idc" name="idc" placeholder="IDC">
<select name="idc" id="idc">
{% for idc in idcs %}
<option value="{{ idc.id }}}}">{{ idc.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
......
{% extends 'base.html' %}
{% block content %}
<form class="form-horizontal" role="form" method="post" action="" >
<fieldset >
<legend>添加IDC</legend>
{% if error %}
<div class="alert alert-danger">
{{ error }}
</div>
{% endif %}
{% if msg %}
<div class="alert alert-success">
{{ msg }}
</div>
{% endif %}
<div class="form-group">
<label for="name" class="col-sm-2 control-label">IDC<span style="color: red"> *</span></label>
<div class="col-sm-4">
<input type="text" class="form-control" id="name" name="name" placeholder="IDC">
</div>
<div class="col-sm-4">
<a href="/addIDC/">添加IDC</a>
</div>
<div class="col-sm-4">
<a href="/showIDC/">删除IDC</a>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<button class="btn btn-primary">添加</button>
</div>
</div>
</fieldset>
</form>
{% endblock %}
\ No newline at end of file
......@@ -2,7 +2,7 @@
{% block content %}
<form class="form-horizontal" role="form" method="post" action="/chgGroup/" >
<fieldset >
<legend>修改用户信息</legend>
<legend>修改属组信息</legend>
{% if error %}
<div class="alert alert-danger">
{{ error }}
......
{% extends 'base.html' %}
{% block content %}
<form class="form-horizontal" role="form" method="post" action="/chgGroup/" >
<fieldset >
<legend>修改IDC信息</legend>
{% if error %}
<div class="alert alert-danger">
{{ error }}
</div>
{% endif %}
{% if msg %}
<div class="alert alert-success">
{{ msg }}
</div>
{% endif %}
<div class="form-group">
<div class="col-sm-4">
<input type="text" id="id" name="id" value="{{ idc.id }}" hidden="hidden">
</div>
</div>
<div class="form-group">
<label for="oldname" class="col-sm-2 control-label">原来IDC<span style="color: red"> *</span></label>
<div class="col-sm-4">
<input type="text" id="oldname" name="oldname" class="form-control" value="{{ idc.name }}" readOnly="readOnly">
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">IDC<span style="color: red"> *</span></label>
<div class="col-sm-4">
<input type="text" id="name" name="name" class="form-control" placeholder="IDC">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<button class="btn btn-primary">修改</button>
</div>
</div>
</fieldset>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<form method="post" action="">
{% if info %}
<p class="alert alert-success">
{{ info }}
</p>
{% endif %}
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th><input onclick="selectAll()" type="checkbox" name="select_all" style="select_all" id="select_all"/></th>
<th>ID</th>
<th>IDC</th>
<th>修改</th>
</tr>
</thead>
<tbody>
{% for idc in idcs %}
<tr>
<td><input type="checkbox" name="selected" value="{{ idc.id }}"></td>
<td>{{ idc.id }}</td>
<td>{{ idc.name }}</td>
<td><a href="/chgIDC/?id={{ idc.id }}">修改</a></td>
</tr>
{% endfor %}
</tbody>
</table>
<button class="btn btn-primary">删除</button>
</form>
{% endblock %}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment