Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
73f5891f
Commit
73f5891f
authored
Oct 12, 2016
by
江世峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asset:update assets_list by tag
parent
b99b88a3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
263 additions
and
20 deletions
+263
-20
api.py
apps/assets/api.py
+0
-1
forms.py
apps/assets/forms.py
+1
-3
asset_list.html
apps/assets/templates/assets/asset_list.html
+0
-0
asset_tag_create.html
apps/assets/templates/assets/asset_tag_create.html
+119
-0
asset_tag_detail.html
apps/assets/templates/assets/asset_tag_detail.html
+0
-0
asset_tags_list.html
apps/assets/templates/assets/asset_tags_list.html
+56
-0
asset_tags.py
apps/assets/templatetags/asset_tags.py
+6
-0
example_tags.py
apps/assets/templatetags/example_tags.py
+0
-0
utils.py
apps/assets/utils.py
+35
-1
views.py
apps/assets/views.py
+15
-11
common_tags.py
apps/common/templatetags/common_tags.py
+5
-0
jumpserver.css
apps/static/css/jumpserver.css
+20
-0
inputTags.css
apps/static/css/plugins/inputTags.css
+2
-2
_base_list.html
apps/templates/_base_list.html
+4
-2
No files found.
apps/assets/api.py
View file @
73f5891f
...
...
@@ -51,4 +51,3 @@ class IDCViewSet(viewsets.ReadOnlyModelViewSet):
queryset
=
IDC
.
objects
.
all
()
serializer_class
=
IDCSerializer
apps/assets/forms.py
View file @
73f5891f
...
...
@@ -26,12 +26,10 @@ class AssetCreateForm(forms.ModelForm):
def
__init__
(
self
,
*
args
,
**
kwargs
):
instance
=
kwargs
.
get
(
'instance'
,
None
)
if
instance
:
initial
=
kwargs
.
get
(
'initial'
,
{})
tags
=
instance
.
tags
.
all
()
#
tags = instance.tags.all()
initial
[
'tags'
]
=
[
t
.
pk
for
t
in
kwargs
[
'instance'
]
.
tags
.
all
()]
print
(
kwargs
.
get
(
'initial'
))
super
(
AssetCreateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
_save_m2m
(
self
):
...
...
apps/assets/templates/assets/asset_list.html
View file @
73f5891f
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/asset_tag_create.html
0 → 100644
View file @
73f5891f
{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% load bootstrap %}
{% block custom_head_css_js %}
<link
href=
"{% static 'css/plugins/select2/select2.min.css' %}"
rel=
"stylesheet"
>
<script
src=
"{% static 'js/plugins/select2/select2.full.min.js' %}"
></script>
<style>
div
.dataTables_wrapper
div
.dataTables_filter
,
.dataTables_length
{
float
:
left
;
}
</style>
{% endblock %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-10"
>
<div
class=
"ibox float-e-margins"
>
<div
id=
"ibox-content"
class=
"ibox-title"
>
<h5>
{{ action }}
</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>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<div
class=
"panel blank-panel"
>
<div
class=
"panel-body"
>
<div
class=
"tab-content"
>
<div
id=
"tab-1"
class=
"ibox float-e-margins tab-pane active"
></div>
<form
id=
"tagForm"
method=
"post"
class=
"form-horizontal"
>
{% csrf_token %}
<h3
class=
"widget-head-color-box"
>
基本信息
</h3>
{{ form.name|bootstrap_horizontal }}
<div
class=
"form-group"
>
<label
class=
"col-sm-2 control-label"
>
关联的资产
</label>
<div
class=
"col-sm-9"
id=
"asset_sed"
>
<input
type=
"text"
class=
" form-control"
id=
"add_asset"
value=
"{{ assets_count }}"
>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-5"
>
<button
class=
"btn btn-white"
type=
"reset"
>
重置
</button>
<button
class=
"btn btn-primary"
type=
"submit"
>
提交
</button>
<div
id=
'box2'
>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 模态框(Modal) -->
<div
class=
"modal fade"
id=
"modal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"myModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog modal-lg"
>
<div
class=
"modal-content"
id=
"box"
>
<!--此部分为主体内容,将远程加载进来-->
</div>
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
$
(
'.select2-system-user'
).
select2
();
})
$
(
'#add_asset'
).
on
(
'click'
,
function
(){
$
(
'#modal'
).
modal
(
'show'
);
});
$
(
'#modal'
).
modal
({
show
:
false
,
backdrop
:
'static'
,
keyboard
:
'false'
,
remote
:
"{% url 'assets:asset-modal-list' %}?tag_id={{ tag_id }}"
,
});
$
(
'#modal'
).
on
(
'show.bs.modal'
,
function
(){
//alert('当调用show方法时,立即触发;')
});
$
(
'#modal'
).
on
(
'shown.bs.modal'
,
function
(){
//alert('当弹窗完全加载完后,再触发;')
});
$
(
'#modal'
).
on
(
'hide.bs.modal'
,
function
(){
//alert('当关闭时,立即触发;')
});
$
(
'#modal'
).
on
(
'hidden.bs.modal'
,
function
(){
//alert('当关完全关闭后,再触发;')
});
$
(
'#modal'
).
on
(
'loaded.bs.modal'
,
function
(){
//alert('当远程数据加载完毕后,再触发;')
});
</script>
{% endblock %}
\ No newline at end of file
apps/assets/templates/assets/asset_tag_detail.html
0 → 100644
View file @
73f5891f
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/asset_tags_list.html
0 → 100644
View file @
73f5891f
{% extends '_base_list.html' %}
{% load i18n %}
{% load common_tags %}
{% block content_left_head %}
<a
href=
"{% url 'assets:asset-tag-create' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create tag" %}
</a>
{% endblock %}
{% block table_head %}
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
onclick=
"checkAll('check_all', 'checked')"
>
</th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset-tag-list' %}?sort=name"
>
{% trans 'Tag Name' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
<th
class=
"text-center"
></th>
{% endblock %}
{% block table_body %}
{% for asset_tag in asset_tags_list %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ asset_tag.id }}"
>
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-tag-detail' pk=asset_tag.id %}"
>
{{ asset_tag.name }}
</a>
</td>
<td
class=
"text-center"
>
{{ asset_tag.asset_set.count }}
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-tag-update' pk=asset_tag.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
onclick=
"objectDelete(this,'{{ asset_tag.name }}','{% url 'assets:asset-tag-delete' asset_tag.id %}')"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
{% endfor %}
{% endblock %}
{% block content_bottom_left %}
<form
id=
""
method=
"get"
action=
""
class=
" mail-search"
>
<div
class=
"input-group"
>
<select
class=
"form-control m-b"
style=
"width: auto"
>
<option>
{% trans 'Delete selected' %}
</option>
<option>
{% trans 'Update selected' %}
</option>
<option>
{% trans 'Deactive selected' %}
</option>
<option>
{% trans 'Export selected' %}
</option>
</select>
<div
class=
"input-group-btn pull-left"
style=
"padding-left: 5px;"
>
<button
id=
'search_btn'
type=
"submit"
style=
"height: 32px;"
class=
"btn btn-sm btn-primary"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</form>
{% endblock %}
apps/assets/templatetags/asset_tags.py
0 → 100644
View file @
73f5891f
from
django
import
template
from
django.utils
import
timezone
from
django.conf
import
settings
register
=
template
.
Library
()
apps/assets/templatetags/example_tags.py
deleted
100644 → 0
View file @
b99b88a3
apps/assets/utils.py
View file @
73f5891f
# ~*~ coding: utf-8 ~*~
#
from
rest_framework
import
serializers
from
models
import
Asset
from
models
import
Tag
from
django.views.generic.edit
import
CreateView
class
CreateAssetTagsMiXin
(
CreateView
):
def
get_form_kwargs
(
self
):
tags_list
=
self
.
request
.
POST
.
getlist
(
'tags'
)
kwargs
=
{
'initial'
:
self
.
get_initial
(),
'prefix'
:
self
.
get_prefix
(),
}
if
self
.
request
.
method
in
(
'POST'
,
'PUT'
):
post_data
=
self
.
request
.
POST
.
copy
()
if
post_data
.
has_key
(
'tags'
):
post_data
.
pop
(
'tags'
)
for
t
in
tags_list
:
try
:
oTag
=
Tag
.
objects
.
get
(
pk
=
int
(
t
))
except
(
Tag
.
DoesNotExist
,
UnicodeEncodeError
):
oTag
=
Tag
(
name
=
t
,
created_by
=
self
.
request
.
user
.
username
or
'Admin'
)
oTag
.
save
()
post_data
.
update
({
'tags'
:
oTag
.
pk
})
else
:
post_data
.
update
({
'tags'
:
int
(
t
)})
kwargs
.
update
({
'data'
:
post_data
,
'files'
:
self
.
request
.
FILES
,
})
return
kwargs
class
UpdateAssetTagsMiXin
(
CreateAssetTagsMiXin
):
def
get_form_kwargs
(
self
):
kwargs
=
super
(
UpdateAssetTagsMiXin
,
self
)
.
get_form_kwargs
()
if
hasattr
(
self
,
'object'
):
kwargs
.
update
({
'instance'
:
self
.
object
})
return
kwargs
\ No newline at end of file
apps/assets/views.py
View file @
73f5891f
...
...
@@ -12,6 +12,7 @@ from django.views.generic.detail import DetailView, SingleObjectMixin
from
django.shortcuts
import
get_object_or_404
,
reverse
,
redirect
from
common.utils
import
int_seq
from
.utils
import
CreateAssetTagsMiXin
,
UpdateAssetTagsMiXin
from
.models
import
Asset
,
AssetGroup
,
IDC
,
AssetExtend
,
AdminUser
,
SystemUser
,
Tag
from
.forms
import
*
from
.hands
import
AdminUserRequiredMixin
...
...
@@ -37,7 +38,7 @@ class AssetListView(AdminUserRequiredMixin, ListView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'Assets'
,
'action'
:
'
A
sset list'
,
'action'
:
'
a
sset list'
,
'tag_list'
:
[(
i
.
id
,
i
.
name
,
i
.
asset_set
.
all
()
.
count
())
for
i
in
Tag
.
objects
.
all
()
.
order_by
(
'name'
)]
}
...
...
@@ -45,24 +46,23 @@ class AssetListView(AdminUserRequiredMixin, ListView):
return
super
(
AssetListView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetCreateView
(
AdminUserRequiredMixin
,
CreateView
):
class
AssetCreateView
(
AdminUserRequiredMixin
,
CreateAssetTagsMiXin
,
CreateView
):
model
=
Asset
tag_type
=
'asset'
form_class
=
AssetCreateForm
template_name
=
'assets/asset_create.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
def
form_invalid
(
self
,
form
):
def
form_valid
(
self
,
form
):
asset
=
form
.
save
()
asset
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
asset
.
save
()
return
super
(
AssetCreateView
,
self
)
.
form_valid
(
form
)
#tags = form.cleaned_data['tags']
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
return
super
(
AssetCreateView
,
self
)
.
form_invalid
(
form
)
def
form_valid
(
self
,
form
):
tag_name_list
=
form
.
cleaned_data
[
'tags'
]
# print self.tag_type,tag_name_list
return
super
(
AssetCreateView
,
self
)
.
form_valid
(
form
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -74,7 +74,9 @@ class AssetCreateView(AdminUserRequiredMixin, CreateView):
return
super
(
AssetCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
class
AssetUpdateView
(
AdminUserRequiredMixin
,
UpdateAssetTagsMiXin
,
UpdateView
):
model
=
Asset
form_class
=
AssetCreateForm
template_name
=
'assets/asset_update.html'
...
...
@@ -90,7 +92,6 @@ class AssetUpdateView(AdminUserRequiredMixin, UpdateView):
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
print
"jsf"
return
super
(
AssetUpdateView
,
self
)
.
form_invalid
(
form
)
...
...
@@ -581,7 +582,10 @@ class TagView(ListView):
return
asset_list
def
get_context_data
(
self
,
**
kwargs
):
kwargs
[
'app'
]
=
'Assets'
kwargs
[
'action'
]
=
'asset list'
kwargs
[
'tag_list'
]
=
[(
i
.
id
,
i
.
name
,
i
.
asset_set
.
all
()
.
count
()
)
for
i
in
Tag
.
objects
.
all
()
.
order_by
(
'name'
)]
kwargs
[
'tag_id'
]
=
self
.
kwargs
[
'tag_id'
]
return
super
(
TagView
,
self
)
.
get_context_data
(
**
kwargs
)
...
...
apps/common/templatetags/common_tags.py
View file @
73f5891f
...
...
@@ -43,3 +43,7 @@ def join_attr(seq, attr=None, sep=None):
seq
=
[
getattr
(
obj
,
attr
)
for
obj
in
seq
]
print
(
seq
)
return
sep
.
join
(
seq
)
@register.filter
def
IntToStr
(
value
):
return
str
(
value
)
\ No newline at end of file
apps/static/css/jumpserver.css
View file @
73f5891f
...
...
@@ -196,3 +196,22 @@ table.dataTable tbody td.selected td i.text-navy
.m-r-30
{
margin-right
:
30px
!important
;
}
.ydxbd
{
font-size
:
12px
;
width
:
100%
;
overflow
:
hidden
;
padding-top
:
15px
;
margin-bottom
:
15px
;
display
:
block
;
background
:
#f4f4f4
;
padding-left
:
10px
;
}
.mar
{
margin-left
:
2px
;
line-height
:
15px
;
}
.mar-j
{
margin-left
:
3px
;
margin-right
:
3px
;
}
\ No newline at end of file
apps/static/css/plugins/inputTags.css
View file @
73f5891f
@import
url("https://fonts.
useso
.com/css?family=Open+Sans:300,400,600,700")
;
@import
url("https://fonts.
useso
.com/css?family=Roboto:400,300,500,700")
;
@import
url("https://fonts.
googleapis
.com/css?family=Open+Sans:300,400,600,700")
;
@import
url("https://fonts.
googleapis
.com/css?family=Roboto:400,300,500,700")
;
/** {*/
/*box-sizing: border-box;*/
/*}*/
...
...
apps/templates/_base_list.html
View file @
73f5891f
...
...
@@ -14,9 +14,11 @@
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<h5>
{{ action }}
</h5>
<h5>
{{ action }}
</h5>
<div
class=
"ibox-tools"
>
<a
class=
"collap
i
se-link"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment