diff --git a/jasset/forms.py b/jasset/forms.py index 10c1e9d09..f9af4d499 100644 --- a/jasset/forms.py +++ b/jasset/forms.py @@ -22,3 +22,11 @@ class AssetGroupForm(forms.ModelForm): fields = [ "name", "comment" ] + + +class IdcForm(forms.ModelForm): + class Meta: + model = IDC + fields = ['name', "bandwidth", "operator", 'linkman', 'phone', 'address', 'network', 'comment'] + + diff --git a/jasset/models.py b/jasset/models.py index ea3af02e0..020caf431 100644 --- a/jasset/models.py +++ b/jasset/models.py @@ -43,7 +43,7 @@ class IDC(models.Model): network = models.TextField(blank=True, null=True, verbose_name=u"IP地址段") date_added = models.DateField(auto_now=True, default=datetime.datetime.now(), null=True) operator = models.IntegerField(max_length=32, blank=True, null=True, verbose_name=u"运营商") - comment = models.TextField(blank=True, null=True, verbose_name=u"备注") + comment = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"备注") def __unicode__(self): return self.name diff --git a/jasset/urls.py b/jasset/urls.py index 029b82295..da902558a 100644 --- a/jasset/urls.py +++ b/jasset/urls.py @@ -5,8 +5,6 @@ from jasset.views import * urlpatterns = patterns('', url(r'^asset_add/$', asset_add), # url(r"^host_add_multi/$", host_add_batch), - url(r'^group_add/$', group_add), - url(r'^group_list/$', group_list), url(r'^group_del/$', group_del), url(r'^asset_list/$', asset_list), url(r'^asset_del/$', asset_del), @@ -16,11 +14,17 @@ urlpatterns = patterns('', # url(r"^host_detail/$", host_detail), # url(r"^dept_host_ajax/$", dept_host_ajax), # url(r"^show_all_ajax/$", show_all_ajax), + url(r'^group_add/$', group_add), + url(r'^group_list/$', group_list), url(r'^group_edit/$', group_edit), url(r'^group_list/$', group_list), url(r'^group_detail/$', group_detail), # url(r'^group_del_host/$', group_del_host), - url(r'^asset_edit_batch/$', asset_edit_batch), # url(r'^host_edit_common/batch/$', host_edit_common_batch), + url(r'^idc_add/$', idc_add), + url(r'^idc_list/$', idc_list), + url(r'^idc_detail/$', idc_detail), + url(r'^idc_edit/$', idc_edit), + url(r'^idc_del/$', idc_del), ) \ No newline at end of file diff --git a/jasset/views.py b/jasset/views.py index bde27c68e..943f27c71 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -3,12 +3,11 @@ import ast from django.db.models import Q -from django.template import RequestContext from django.shortcuts import get_object_or_404 from jasset.asset_api import * from jumpserver.api import * -from jasset.forms import AssetForm +from jasset.forms import AssetForm, IdcForm from jasset.models import Asset, IDC, AssetGroup, ASSET_TYPE, ASSET_STATUS @@ -328,3 +327,77 @@ def asset_detail(request): asset_record = AssetRecord.objects.filter(asset=asset).order_by('-alert_time') return my_render('jasset/asset_detail.html', locals(), request) + + +@require_role('admin') +def idc_add(request): + """ + IDC add view + """ + header_title, path1, path2 = u'添加IDC', u'资产管理', u'添加IDC' + if request.method == 'POST': + idc_form = IdcForm(request.POST) + if idc_form.is_valid(): + idc_name = idc_form.cleaned_data['name'] + + if IDC.objects.filter(name=idc_name): + emg = u'添加失败, 此IDC %s 已存在!' % idc_name + return my_render('jasset/idc_add.html', locals(), request) + else: + idc_form.save() + smg = u'IDC: %s添加成功' % idc_name + return HttpResponseRedirect("/jasset/idc_list/") + else: + idc_form = IdcForm() + return render_to_response('jasset/idc_add.html', + locals(), + context_instance=RequestContext(request)) + + +@require_role('admin') +def idc_list(request): + header_title, path1, path2 = u'查看IDC', u'资产管理', u'查看IDC' + posts = IDC.objects.all() + keyword = request.GET.get('keyword', '') + if keyword: + posts = IDC.objects.filter(Q(name__contains=keyword) | Q(comment__contains=keyword)) + else: + posts = IDC.objects.exclude(name='ALL').order_by('id') + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) + return render_to_response('jasset/idc_list.html', + locals(), + context_instance=RequestContext(request)) + + +@require_role('admin') +def idc_edit(request): + idc_id = request.GET.get('id', '') + idc = get_object(IDC, id=idc_id) + if request.method == 'POST': + idc_form = IdcForm(request.POST, instance=idc) + if idc_form.is_valid(): + idc_form.save() + return HttpResponseRedirect("/jasset/idc_list/") + else: + idc_form = IdcForm(instance=idc) + return my_render('jasset/idc_edit.html', locals(), request) + + +@require_role('admin') +def idc_detail(request): + """ IDC详情 """ + header_title, path1, path2 = u'IDC详情', u'资产管理', u'IDC详情' + idc_id = request.GET.get('id', '') + idc = get_object(IDC, id=idc_id) + posts = Asset.objects.filter(idc=idc).order_by('ip') + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) + + return my_render('jasset/idc_detail.html', locals(), request) + + +@require_role('admin') +def idc_del(request): + uuid = request.GET.get('uuid', '') + idc = get_object_or_404(IDC, uuid=uuid) + idc.delete() + return HttpResponseRedirect('/jasset/idc_list/') diff --git a/templates/jasset/asset_list.html b/templates/jasset/asset_list.html index 731f6f44f..7a7bbf937 100644 --- a/templates/jasset/asset_list.html +++ b/templates/jasset/asset_list.html @@ -229,7 +229,7 @@ data: {asset_id_all: asset_id_all}, url: "/jasset/asset_del/?arg=batch", success: function () { - window.open("/jasset/asset_list/", "_self"); + parent.location.reload(); } }); } diff --git a/templates/jasset/idc_add.html b/templates/jasset/idc_add.html new file mode 100644 index 000000000..a093254d0 --- /dev/null +++ b/templates/jasset/idc_add.html @@ -0,0 +1,95 @@ +{% extends 'base.html' %} +{% block content %} +{% load bootstrap %} +{% include 'nav_cat_bar.html' %} +
+
+
+
+
+
填写IDC基本信息
+
+ + + + + + + + + + +
+
+ +
+ {% if emg %} +
{{ emg }}
+ {% endif %} + {% if smg %} +
{{ smg }}
+ {% endif %} +
+ {{ idc_form.name|bootstrap_horizontal }} + +
+ {{ idc_form.bandwidth|bootstrap_horizontal }} + +
+ {{ idc_form.operator|bootstrap_horizontal }} + +
+ {{ idc_form.linkman|bootstrap_horizontal }} + +
+ {{ idc_form.phone|bootstrap_horizontal }} + +
+ {{ idc_form.address|bootstrap_horizontal }} + +
+ {{ idc_form.network|bootstrap_horizontal }} + +
+ {{ idc_form.comment|bootstrap_horizontal }} + +
+
+
+ + +
+
+
+
+
+
+
+
+ + + +{% endblock %} \ No newline at end of file diff --git a/templates/jasset/idc_detail.html b/templates/jasset/idc_detail.html new file mode 100644 index 000000000..0d61dfa1c --- /dev/null +++ b/templates/jasset/idc_detail.html @@ -0,0 +1,229 @@ +{% extends 'base.html' %} +{% load mytags %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
+
+
+
+
+
IDC {{ idc.name }} 详细信息列表
+ +
+ +
+ {% if emg %} +
{{ emg }}
+ {% endif %} + {% if smg %} +
{{ smg }}
+ {% endif %} + + +
+ + + + + + + + + + + + + + + {% for asset in contact_list %} + + + + + + + + + + + {% endfor %} + +
+ + IP地址 主机名 IDC 所属主机组 配置信息 使用默认管理 操作
+ + {{ asset.ip }} {{ asset.hostname }} {{ asset.idc.name }} {{ asset.group.all|group_str2 }}{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }} {{ asset.use_default_auth|bool2str }} + 详情 + {% ifnotequal session_role_id 0 %} + 编辑 + 删除 + {% endifnotequal %} +
+
+
+ + 修改 +
+
+
+
    + {% if keyword %} + {% if contacts.has_previous %} + + {% else %} + + {% endif %} + {% ifequal show_first 1 %} +
  • 1...
  • + {% endifequal %} + {% for page in page_range %} + {% ifequal current_page page %} +
  • {{ page }}
  • + {% else %} +
  • {{ page }}
  • + {% endifequal %} + {% endfor %} + {% ifequal show_end 1 %} +
  • ...{{ p.num_pages }}
  • + {% endifequal %} + {% if contacts.has_next %} + + {% else %} + + {% endif %} + + {% else %} + {% if contacts.has_previous %} + + {% else %} + + {% endif %} + {% ifequal show_first 1 %} +
  • 1...
  • + {% endifequal %} + {% for page in page_range %} + {% ifequal current_page page %} +
  • {{ page }}
  • + {% else %} +
  • {{ page }}
  • + {% endifequal %} + {% endfor %} + {% ifequal show_end 1 %} +
  • ...{{ p.num_pages }}
  • + {% endifequal %} + {% if contacts.has_next %} + + {% else %} + + {% endif %} + {% endif %} +
+
+
+
+
+
+
+
+
+
+ + + +{% endblock %} \ No newline at end of file diff --git a/templates/jasset/idc_edit.html b/templates/jasset/idc_edit.html new file mode 100644 index 000000000..b4db0c424 --- /dev/null +++ b/templates/jasset/idc_edit.html @@ -0,0 +1,99 @@ +{% extends 'base.html' %} +{% block content %} +{% load bootstrap %} +{% include 'nav_cat_bar.html' %} +
+
+
+
+
+
填写IDC基本信息
+ +
+ +
+ {% if emg %} +
{{ emg }}
+ {% endif %} + {% if smg %} +
{{ smg }}
+ {% endif %} +
+ {{ idc_form.name|bootstrap_horizontal }} + +
+ {{ idc_form.bandwidth|bootstrap_horizontal }} + +
+ {{ idc_form.operator|bootstrap_horizontal }} + +
+ {{ idc_form.linkman|bootstrap_horizontal }} + +
+ {{ idc_form.phone|bootstrap_horizontal }} + +
+ {{ idc_form.address|bootstrap_horizontal }} + +
+ {{ idc_form.network|bootstrap_horizontal }} + +
+ {{ idc_form.comment|bootstrap_horizontal }} + +
+
+
+ + +
+
+
+
+
+
+
+
+ + + +{% endblock %} \ No newline at end of file diff --git a/templates/jasset/idc_list.html b/templates/jasset/idc_list.html new file mode 100644 index 000000000..85a409ea2 --- /dev/null +++ b/templates/jasset/idc_list.html @@ -0,0 +1,115 @@ +{% extends 'base.html' %} +{% load mytags %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
+
+
+
+
+
IDC详细信息列表
+ +
+
+
+ 添加IDC + +
+ +
+ + + + {% ifequal session_role_id 2 %} + + {% endifequal %} + + + + + + + + {% for post in contacts.object_list %} + + + + + + + + {% endfor %} + +
机房名 主机数量 备注 操作
{{ post.name }} {{ post.asset_set.count }} {{ post.comment }} + 详情 + 编辑 + 删除 +
+
+
+ {% ifequal session_role_id 2 %} + + + {% endifequal %} +
+ {% include 'paginator.html' %} +
+
+
+
+
+
+
+ + + +{% endblock %} \ No newline at end of file diff --git a/templates/nav.html b/templates/nav.html index ee268ee25..77d9f9664 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -22,6 +22,8 @@
  • 查看资产组
  • 添加资产
  • 查看资产{{ host_active_num }}/{{ host_total_num}}
  • +
  • 添加机房
  • +
  • 查看机房