Commit 0ed08534 authored by halcyon's avatar halcyon

完善资产添加和查看资产页面

parent bafbacc1
import datetime
from django.db import models from django.db import models
from juser.models import Group, User from juser.models import Group, User
...@@ -9,6 +10,13 @@ class IDC(models.Model): ...@@ -9,6 +10,13 @@ class IDC(models.Model):
def __unicode__(self): def __unicode__(self):
return self.name return self.name
class Group(models.Model):
name = models.CharField(max_length=80, unique=True)
comment = models.CharField(max_length=160, blank=True, null=True)
def __unicode__(self):
return self.name
class Asset(models.Model): class Asset(models.Model):
LOGIN_TYPE_CHOICES = ( LOGIN_TYPE_CHOICES = (
...@@ -26,7 +34,7 @@ class Asset(models.Model): ...@@ -26,7 +34,7 @@ class Asset(models.Model):
password_common = models.CharField(max_length=80, blank=True, null=True) password_common = models.CharField(max_length=80, blank=True, null=True)
username_super = models.CharField(max_length=20, blank=True, null=True) username_super = models.CharField(max_length=20, blank=True, null=True)
password_super = models.CharField(max_length=80, blank=True, null=True) password_super = models.CharField(max_length=80, blank=True, null=True)
date_added = models.IntegerField(max_length=12) date_added = models.DateTimeField(auto_now=True,default=datetime.datetime.now(), null=True)
is_active = models.BooleanField(default=True) is_active = models.BooleanField(default=True)
comment = models.CharField(max_length=100, blank=True, null=True) comment = models.CharField(max_length=100, blank=True, null=True)
......
...@@ -5,4 +5,7 @@ from jasset.views import * ...@@ -5,4 +5,7 @@ from jasset.views import *
urlpatterns = patterns('', urlpatterns = patterns('',
url(r'^$', index), url(r'^$', index),
url(r'jadd', jadd), url(r'jadd', jadd),
url(r'jlist', jlist),
url(r'jadd_idc', jadd_idc),
url(r'jlist_idc', jlist_idc),
) )
\ No newline at end of file
#coding:utf-8 # coding:utf-8
import datetime
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.template import RequestContext from django.template import RequestContext
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from models import IDC, Asset, Group
from connect import PyCrypt, KEY
def index(request): def index(request):
return render_to_response('jasset/jasset.html',) return render_to_response('jasset/jasset.html', )
def jadd(request): def jadd(request):
global j_passwd
groups = []
cryptor = PyCrypt(KEY)
eidc = IDC.objects.all()
egroup = Group.objects.all()
is_actived = {'active': 1, 'no_active': 0}
login_typed = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'}
if request.method == 'POST': if request.method == 'POST':
j_ip = request.POST.get('j_ip')
j_idc = request.POST.get('j_idc')
j_port = request.POST.get('j_port')
j_type = request.POST.get('j_type')
j_group = request.POST.getlist('j_group')
j_active = request.POST.get('j_active')
j_comment = request.POST.get('j_comment')
if j_type == 'MAP':
j_user = request.POST.get('j_user')
j_password = cryptor.encrypt(request.POST.get('j_password'))
j_root = request.POST.get('j_root')
j_passwd = cryptor.encrypt(request.POST.get('j_passwd'))
j_idc = IDC.objects.get(name=j_idc)
for group in j_group:
c = Group.objects.get(name=group)
groups.append(c)
if Asset.objects.filter(ip=str(j_ip)):
emg = u'该IP已存在!'
return render_to_response('jasset/jadd.html', {'emg': emg, 'j_ip': j_ip})
elif j_type == 'MAP':
a = Asset(ip=j_ip,
port=j_port,
login_type=login_typed[j_type],
idc=j_idc,
is_active=int(is_actived[j_active]),
comment=j_comment,
username_common=j_user,
password_common=j_password,
username_super=j_root,
password_super=j_passwd,)
else:
a = Asset(ip=j_ip,
port=j_port,
login_type=login_typed[j_type],
idc=j_idc,
is_active=int(is_actived[j_active]),
comment=j_comment)
a.save()
a.group = groups
a.save()
return render_to_response('jasset/jadd.html',
{'header_title': u'添加主机 | Add Host',
'path1': '资产管理',
'path2': '添加主机',
'eidc': eidc,
'egroup': egroup, }
)
def jlist(request):
posts = contact_list = Asset.objects.all().order_by('ip')
print posts
paginator = Paginator(contact_list, 5)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return render_to_response('jasset/jlist.html',
{"contacts": contacts,
'p': paginator,
'posts': posts,
'header_title': u'查看主机 | List Host',
'path1': '资产管理',
'path2': '查看主机', },
context_instance=RequestContext(request))
def jadd_idc(request):
pass
def jlist_idc(request):
pass pass
\ No newline at end of file
return render_to_response('jasset/jadd.html',)
\ No newline at end of file
...@@ -111,7 +111,7 @@ USE_I18N = True ...@@ -111,7 +111,7 @@ USE_I18N = True
USE_L10N = True USE_L10N = True
USE_TZ = True USE_TZ = False
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
......
This diff is collapsed.
{% extends 'base.html' %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5> 主机详细信息列表 </h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#">未启用 1</a>
</li>
<li><a href="#">未启用 2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div class="">
<a onclick="fnClickAddRow();" href="javascript:void(0);" class="btn btn-primary "> 添加 </a>
</div>
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<th> IP地址 </th>
<th> 端口号 </th>
<th> 登录方式 </th>
<th> 所属IDC </th>
<th> 所属业务组 </th>
<th> 添加时间 </th>
<th> 备注 </th>
</tr>
</thead>
<tbody>
{% for post in contacts.object_list %}
<tr class="gradeX">
<td> {{ post.ip }} </td>
<td> {{ post.port }} </td>
<td> {{ post.login_type}} </td>
<td class="center"> {{ post.idc.name }} </td>
<td class="center">
{% for group in post.group.all %}
{{ group }}
{% endfor %}
</td>
<td class="center"> {{ post.date_added }} </td>
<td class="center"> {{ post.comment }} </td>
</tr>
{% endfor %}
</tbody>
</table>
<ul class="pagination">
{% if contacts.has_previous %}
<li><a href="?page={{ contacts.previous_page_number }}">&laquo;</a></li>
{% endif %}
{% for page in p.page_range %}
{% ifequal offset1 page %}
<li class="active"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% else %}
<li><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% endifequal %}
{% endfor %}
{% if contacts.has_next %}
<li><a href="?page={{ contacts.next_page_number }}">&raquo;</a></li>
{% endif %}
</ul>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
\ No newline at end of file
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<li> <li>
<a href="mailbox.html"><i class="fa fa-cube"></i> <span class="nav-label">资产管理</span><span class="fa arrow"></span></a> <a href="mailbox.html"><i class="fa fa-cube"></i> <span class="nav-label">资产管理</span><span class="fa arrow"></span></a>
<ul class="nav nav-second-level"> <ul class="nav nav-second-level">
<li><a href="/asset/showlist/">查看资产</a></li> <li><a href="/jasset/jlist/">查看资产</a></li>
<li><a href="/jasset/jadd/">添加资产</a></li> <li><a href="/jasset/jadd/">添加资产</a></li>
<li><a href="/idc/showlist/">查看机房</a></li> <li><a href="/idc/showlist/">查看机房</a></li>
<li><a href="/idc/add/">添加机房</a></li> <li><a href="/idc/add/">添加机房</a></li>
......
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
<div class="form-group"> <div class="form-group">
<div class="col-sm-4 col-sm-offset-2"> <div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-white" type="submit">取消</button> <button class="btn btn-white" type="submit">取消</button>
<button class="btn btn-primary" type="submit">确认保存</button> <button id="submit_button" class="btn btn-primary" type="submit">确认保存</button>
</div> </div>
</div> </div>
</form> </form>
...@@ -110,4 +110,7 @@ ...@@ -110,4 +110,7 @@
</div> </div>
</div> </div>
</div> </div>
</script>
{% endblock %} {% 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