From b7c3cc5532c0108b0b2559703bf3b4f5f475868f Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Fri, 13 Nov 2015 00:03:51 +0800 Subject: [PATCH] add idc --- jasset/forms.py | 8 ++ jasset/models.py | 2 +- jasset/urls.py | 10 +- jasset/views.py | 77 ++++++++++- templates/jasset/asset_list.html | 2 +- templates/jasset/idc_add.html | 95 +++++++++++++ templates/jasset/idc_detail.html | 229 +++++++++++++++++++++++++++++++ templates/jasset/idc_edit.html | 99 +++++++++++++ templates/jasset/idc_list.html | 115 ++++++++++++++++ templates/nav.html | 2 + 10 files changed, 632 insertions(+), 7 deletions(-) create mode 100644 templates/jasset/idc_add.html create mode 100644 templates/jasset/idc_detail.html create mode 100644 templates/jasset/idc_edit.html create mode 100644 templates/jasset/idc_list.html 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' %} +