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
b2d6645f
Commit
b2d6645f
authored
Jan 26, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feature] 添加资产详情标签
parent
cb902362
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
3 deletions
+51
-3
forms.py
apps/assets/forms.py
+6
-0
asset_detail.html
apps/assets/templates/assets/asset_detail.html
+27
-0
label_list.html
apps/assets/templates/assets/label_list.html
+1
-1
views_urls.py
apps/assets/urls/views_urls.py
+1
-0
label.py
apps/assets/views/label.py
+16
-2
No files found.
apps/assets/forms.py
View file @
b2d6645f
...
...
@@ -418,6 +418,12 @@ class LabelForm(forms.ModelForm):
model
=
Label
fields
=
[
'name'
,
'value'
,
'assets'
]
def
__init__
(
self
,
*
args
,
**
kwargs
):
if
kwargs
.
get
(
'instance'
,
None
):
initial
=
kwargs
.
get
(
'initial'
,
{})
initial
[
'assets'
]
=
kwargs
[
'instance'
]
.
assets
.
all
()
super
()
.
__init__
(
*
args
,
**
kwargs
)
def
save
(
self
,
commit
=
True
):
label
=
super
()
.
save
(
commit
=
commit
)
assets
=
self
.
cleaned_data
[
'assets'
]
...
...
apps/assets/templates/assets/asset_detail.html
View file @
b2d6645f
...
...
@@ -244,6 +244,33 @@
</table>
</div>
</div>
<div
class=
"panel panel-warning"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Labels' %}
</div>
<div
class=
"panel-body"
>
{#
<table
class=
"table"
>
#}
{#
<tbody>
#}
{# {% for label in asset.labels.all %}#}
{#
<tr
{%
if
forloop
.
counter =
=
1
%}
class=
"no-borders-tr"
{%
endif
%}
>
#}
{#
<td>
{{ label.name }}
</td>
#}
{#
<td>
#}
{#
<span
class=
"pull-right"
>
#}
{# {{ label.value }}#}
{#
</span>
#}
{#
</td>
#}
{#
</tr>
#}
{# {% endfor %}#}
{#
</tbody>
#}
{#
</table>
#}
<ul
class=
"tag-list"
style=
"padding: 0"
>
{% for label in asset.labels.all %}
<li
><a
href=
""
><i
class=
"fa fa-tag"
></i>
{{ label.name }}:{{ label.value }}
</a></li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
</div>
</div>
...
...
apps/assets/templates/assets/label_list.html
View file @
b2d6645f
...
...
@@ -35,7 +35,7 @@ function initTable() {
}},
{
targets
:
4
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
update_btn
=
'<a href="{% url "assets:
cluster
-update" pk=DEFAULT_PK %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'{{ DEFAULT_PK }}'
,
cellData
);
var
update_btn
=
'<a href="{% url "assets:
label
-update" pk=DEFAULT_PK %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'{{ DEFAULT_PK }}'
,
cellData
);
var
del_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn_cluster_delete" data-uid="{{ DEFAULT_PK }}">{% trans "Delete" %}</a>'
.
replace
(
'{{ DEFAULT_PK }}'
,
cellData
);
$
(
td
).
html
(
update_btn
+
del_btn
)
}}],
...
...
apps/assets/urls/views_urls.py
View file @
b2d6645f
...
...
@@ -55,5 +55,6 @@ urlpatterns = [
url
(
r'^label/$'
,
views
.
LabelListView
.
as_view
(),
name
=
'label-list'
),
url
(
r'^label/create/$'
,
views
.
LabelCreateView
.
as_view
(),
name
=
'label-create'
),
url
(
r'^label/(?P<pk>[0-9a-zA-Z\-]{36})/update/$'
,
views
.
LabelUpdateView
.
as_view
(),
name
=
'label-update'
),
]
apps/assets/views/label.py
View file @
b2d6645f
...
...
@@ -7,7 +7,8 @@ from django.utils.translation import ugettext_lazy as _
from
django.urls
import
reverse_lazy
from
common.mixins
import
AdminUserRequiredMixin
from
common.const
import
create_success_msg
from
common.const
import
create_success_msg
,
update_success_msg
from
..models
import
Label
from
..forms
import
LabelForm
...
...
@@ -30,6 +31,7 @@ class LabelListView(AdminUserRequiredMixin, TemplateView):
class
LabelCreateView
(
AdminUserRequiredMixin
,
CreateView
):
model
=
Label
template_name
=
'assets/label_create_update.html'
form_class
=
LabelForm
success_url
=
reverse_lazy
(
'assets:label-list'
)
...
...
@@ -45,7 +47,19 @@ class LabelCreateView(AdminUserRequiredMixin, CreateView):
class
LabelUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
pass
model
=
Label
template_name
=
'assets/label_create_update.html'
form_class
=
LabelForm
success_url
=
reverse_lazy
(
'assets:label-list'
)
success_message
=
update_success_msg
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Update label'
),
}
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
class
LabelDetailView
(
AdminUserRequiredMixin
,
DetailView
):
...
...
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