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
b99b88a3
Commit
b99b88a3
authored
8 years ago
by
江世峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asset:update tag
parent
0c611b64
master
auditor_jym
audits
dev
dev_beta
dev_beta_db
gengmei
lagacy-0.4.0
node_service
password
rbac
restrict_access
test
v52
wph
1.5.2
1.5.1
1.5.0
1.4.10
1.4.9
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.3
1.3.2
1.3.1
1.3.0
1.2.1
1.2.0
1.1.1
1.1.0
1.0.0
v1.4.10
v1.4.7
v1.4.4
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
168 additions
and
23 deletions
+168
-23
forms.py
apps/assets/forms.py
+37
-1
models.py
apps/assets/models.py
+1
-1
asset_create.html
apps/assets/templates/assets/asset_create.html
+0
-2
asset_group_create.html
apps/assets/templates/assets/asset_group_create.html
+1
-1
asset_list.html
apps/assets/templates/assets/asset_list.html
+2
-3
asset_modal_list.html
apps/assets/templates/assets/asset_modal_list.html
+5
-3
asset_update.html
apps/assets/templates/assets/asset_update.html
+5
-6
urls.py
apps/assets/urls.py
+7
-1
views.py
apps/assets/views.py
+109
-4
_nav.html
apps/templates/_nav.html
+1
-1
No files found.
apps/assets/forms.py
View file @
b99b88a3
...
@@ -40,6 +40,7 @@ class AssetCreateForm(forms.ModelForm):
...
@@ -40,6 +40,7 @@ class AssetCreateForm(forms.ModelForm):
self
.
instance
.
tags
.
clear
()
self
.
instance
.
tags
.
clear
()
self
.
instance
.
tags
.
add
(
*
tuple
(
tags
))
self
.
instance
.
tags
.
add
(
*
tuple
(
tags
))
class
Meta
:
class
Meta
:
model
=
Asset
model
=
Asset
...
@@ -53,7 +54,8 @@ class AssetCreateForm(forms.ModelForm):
...
@@ -53,7 +54,8 @@ class AssetCreateForm(forms.ModelForm):
'groups'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'groups'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select asset groups'
)}),
'data-placeholder'
:
_
(
'Select asset groups'
)}),
'tags'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'tags'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select asset groups'
)}),
'id'
:
'tags'
,
'data-placeholder'
:
_
(
'Select asset tags'
)}),
'system_users'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'system_users'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select asset system users'
)}),
'data-placeholder'
:
_
(
'Select asset system users'
)}),
'admin_user'
:
forms
.
Select
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select asset admin user'
)}),
'admin_user'
:
forms
.
Select
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select asset admin user'
)}),
...
@@ -263,4 +265,37 @@ class SystemUserForm(forms.ModelForm):
...
@@ -263,4 +265,37 @@ class SystemUserForm(forms.ModelForm):
'username'
:
'* required'
,
'username'
:
'* required'
,
'auth_push'
:
'Auto push system user to asset'
,
'auth_push'
:
'Auto push system user to asset'
,
'auth_update'
:
'Auto update system user ssh key'
,
'auth_update'
:
'Auto update system user ssh key'
,
}
class
AssetTagForm
(
forms
.
ModelForm
):
assets
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Asset
.
objects
.
all
(),
label
=
_
(
'Asset'
),
required
=
False
,
widget
=
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select assets'
)})
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
if
kwargs
.
get
(
'instance'
,
None
):
initial
=
kwargs
.
get
(
'initial'
,
{})
initial
[
'assets'
]
=
kwargs
[
'instance'
]
.
asset_set
.
all
()
super
(
AssetTagForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
_save_m2m
(
self
):
super
(
AssetTagForm
,
self
)
.
_save_m2m
()
assets
=
self
.
cleaned_data
[
'assets'
]
self
.
instance
.
asset_set
.
clear
()
self
.
instance
.
asset_set
.
add
(
*
tuple
(
assets
))
class
Meta
:
model
=
Tag
fields
=
[
"name"
,
]
widgets
=
{
'name'
:
forms
.
TextInput
(
attrs
=
{}),
}
help_texts
=
{
'name'
:
'* required'
,
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
apps/assets/models.py
View file @
b99b88a3
...
@@ -365,7 +365,7 @@ class Asset(models.Model):
...
@@ -365,7 +365,7 @@ class Asset(models.Model):
class
Tag
(
models
.
Model
):
class
Tag
(
models
.
Model
):
name
=
models
.
CharField
(
'标签名'
,
max_length
=
64
)
name
=
models
.
CharField
(
'标签名'
,
max_length
=
64
,
unique
=
True
)
created_time
=
models
.
DateTimeField
(
'创建时间'
,
auto_now_add
=
True
)
created_time
=
models
.
DateTimeField
(
'创建时间'
,
auto_now_add
=
True
)
created_by
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Created by'
))
created_by
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Created by'
))
...
...
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/asset_create.html
View file @
b99b88a3
...
@@ -25,8 +25,6 @@
...
@@ -25,8 +25,6 @@
<div
class=
"hr-line-dashed"
></div>
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Other' %}
</h3>
<h3>
{% trans 'Other' %}
</h3>
{{ form.tags|bootstrap_horizontal }}
{{ form.tags|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<div
class=
"hr-line-dashed"
></div>
...
...
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/asset_group_create.html
View file @
b99b88a3
...
@@ -37,7 +37,7 @@ div.dataTables_wrapper div.dataTables_filter,
...
@@ -37,7 +37,7 @@ div.dataTables_wrapper div.dataTables_filter,
<div
class=
"panel-body"
>
<div
class=
"panel-body"
>
<div
class=
"tab-content"
>
<div
class=
"tab-content"
>
<div
id=
"tab-1"
class=
"ibox float-e-margins tab-pane active"
></div>
<div
id=
"tab-1"
class=
"ibox float-e-margins tab-pane active"
></div>
<form
id=
"
IDC
Form"
method=
"post"
class=
"form-horizontal"
>
<form
id=
"
group
Form"
method=
"post"
class=
"form-horizontal"
>
{% csrf_token %}
{% csrf_token %}
<h3
class=
"widget-head-color-box"
>
资产组信息
</h3>
<h3
class=
"widget-head-color-box"
>
资产组信息
</h3>
{{ form.name|bootstrap_horizontal }}
{{ form.name|bootstrap_horizontal }}
...
...
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/asset_list.html
View file @
b99b88a3
...
@@ -42,8 +42,7 @@
...
@@ -42,8 +42,7 @@
</td>
</td>
<td
class=
"text-center"
>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-update' pk=asset.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
href=
"{% url 'assets:asset-update' pk=asset.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
href=
"{% url 'assets:asset-delete' pk=asset.id %}"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
-
<a
href=
"{% url 'assets:asset-delete' pk=asset.id %}"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
{#
<a
href=
"{% url '' %}"
>
{% trans 'Delete' %}
</a>
#}
</td>
</td>
</tr>
</tr>
{% endfor %}
{% endfor %}
...
@@ -72,7 +71,7 @@
...
@@ -72,7 +71,7 @@
<a
href=
"{% url 'assets:asset-tags' tag_id=tag.0%}"
>
<a
href=
"{% url 'assets:asset-tags' tag_id=tag.0%}"
>
{{ tag.1}}({{ tag.2 }})
{{ tag.1}}({{ tag.2 }})
</a>
</a>
{% endfor %}
{% endfor %}
{% endblock %}
{% endblock %}
...
...
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/asset_modal_list.html
View file @
b99b88a3
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
</thead>
</thead>
<tbody>
<tbody>
{% for asset in asset_modal_list %}
{% for asset in asset_modal_list %}
{% if asset.id in
group
_assets %}
{% if asset.id in
all
_assets %}
<tr
name=
"oAssets"
class=
"odd selected"
>
<tr
name=
"oAssets"
class=
"odd selected"
>
<td
class=
"text-center"
><input
type=
"checkbox"
name=
"checked"
value=
"{{ asset.id }}"
checked=
"checked"
></td>
<td
class=
"text-center"
><input
type=
"checkbox"
name=
"checked"
value=
"{{ asset.id }}"
checked=
"checked"
></td>
{% else %}
{% else %}
...
@@ -47,7 +47,6 @@
...
@@ -47,7 +47,6 @@
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
//$(window).load(function (){
$
(
document
).
ready
(
function
(){
$
(
document
).
ready
(
function
(){
var
table
=
$
(
'#editable'
).
DataTable
({
var
table
=
$
(
'#editable'
).
DataTable
({
...
@@ -68,7 +67,7 @@ $(document).ready(function(){
...
@@ -68,7 +67,7 @@ $(document).ready(function(){
{
data
:
"dp"
}
{
data
:
"dp"
}
]
]
});
});
//
讲
ID列隐藏
//
将
ID列隐藏
table
.
column
(
'1'
).
visible
(
false
);
table
.
column
(
'1'
).
visible
(
false
);
$
(
'#editable tbody'
).
on
(
'click'
,
'tr'
,
function
()
{
$
(
'#editable tbody'
).
on
(
'click'
,
'tr'
,
function
()
{
...
@@ -82,6 +81,9 @@ $(document).ready(function(){
...
@@ -82,6 +81,9 @@ $(document).ready(function(){
};
};
});
});
$
(
'#close-btn'
).
on
(
'click'
,
function
(){
$
(
'#modal'
).
modal
(
'hide'
);
});
$
(
'#save-btn'
).
on
(
'click'
,
function
(){
$
(
'#save-btn'
).
on
(
'click'
,
function
(){
// alert( table.rows('.selected').data().length +' row(s) selected' );
// alert( table.rows('.selected').data().length +' row(s) selected' );
var
d
=
table
.
rows
(
'.selected'
).
data
();
var
d
=
table
.
rows
(
'.selected'
).
data
();
...
...
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/asset_update.html
View file @
b99b88a3
...
@@ -70,12 +70,10 @@
...
@@ -70,12 +70,10 @@
<script>
<script>
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
$
(
'.select2'
).
select2
();
{
#
$
(
'#tags'
).
inputTags
({
#
}
$
(
"#tags"
).
select2
({
{
#
tags
:
[{
%
for
tag
in
form
.
tags
.
value
%
}
{{
tag
|
safe
}},
{
%
endfor
%
}]
#
}
tags
:
true
,
{
#
});
#
}
maximumSelectionLength
:
8
//最多能够选择的个数
$
(
'#tags'
).
inputTags
(
});
);
})
})
</script>
</script>
{% endblock %}
{% endblock %}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
apps/assets/urls.py
View file @
b99b88a3
...
@@ -28,7 +28,13 @@ urlpatterns = [
...
@@ -28,7 +28,13 @@ urlpatterns = [
url
(
r'^asset-group/(?P<pk>[0-9]+)$'
,
views
.
AssetGroupDetailView
.
as_view
(),
name
=
'asset-group-detail'
),
url
(
r'^asset-group/(?P<pk>[0-9]+)$'
,
views
.
AssetGroupDetailView
.
as_view
(),
name
=
'asset-group-detail'
),
url
(
r'^asset-group/(?P<pk>[0-9]+)/update$'
,
views
.
AssetGroupUpdateView
.
as_view
(),
name
=
'asset-group-update'
),
url
(
r'^asset-group/(?P<pk>[0-9]+)/update$'
,
views
.
AssetGroupUpdateView
.
as_view
(),
name
=
'asset-group-update'
),
url
(
r'^asset-group/(?P<pk>[0-9]+)/delete$'
,
views
.
AssetGroupDeleteView
.
as_view
(),
name
=
'asset-group-delete'
),
url
(
r'^asset-group/(?P<pk>[0-9]+)/delete$'
,
views
.
AssetGroupDeleteView
.
as_view
(),
name
=
'asset-group-delete'
),
url
(
r'^asset-tag/(?P<tag_id>[0-9]+)$'
,
views
.
TagView
.
as_view
(),
name
=
'asset-tags'
),
url
(
r'^tags$'
,
views
.
TagsListView
.
as_view
(),
name
=
'asset-tag-list'
),
url
(
r'^asset-by-tag/(?P<tag_id>[0-9]+)$'
,
views
.
TagView
.
as_view
(),
name
=
'asset-tags'
),
url
(
r'^tags/create$'
,
views
.
AssetTagCreateView
.
as_view
(),
name
=
'asset-tag-create'
),
url
(
r'^asset-tag/(?P<pk>[0-9]+)$'
,
views
.
AssetTagDetailView
.
as_view
(),
name
=
'asset-tag-detail'
),
url
(
r'^asset-tag/(?P<pk>[0-9]+)/update$'
,
views
.
AssetTagUpdateView
.
as_view
(),
name
=
'asset-tag-update'
),
url
(
r'^asset-tag/(?P<pk>[0-9]+)/delete$'
,
views
.
AssetTagDeleteView
.
as_view
(),
name
=
'asset-tag-delete'
),
# Resource idc url
# Resource idc url
url
(
r'^idc$'
,
views
.
IDCListView
.
as_view
(),
name
=
'idc-list'
),
url
(
r'^idc$'
,
views
.
IDCListView
.
as_view
(),
name
=
'idc-list'
),
...
...
This diff is collapsed.
Click to expand it.
apps/assets/views.py
View file @
b99b88a3
...
@@ -13,7 +13,7 @@ from django.shortcuts import get_object_or_404, reverse, redirect
...
@@ -13,7 +13,7 @@ from django.shortcuts import get_object_or_404, reverse, redirect
from
common.utils
import
int_seq
from
common.utils
import
int_seq
from
.models
import
Asset
,
AssetGroup
,
IDC
,
AssetExtend
,
AdminUser
,
SystemUser
,
Tag
from
.models
import
Asset
,
AssetGroup
,
IDC
,
AssetExtend
,
AdminUser
,
SystemUser
,
Tag
from
.forms
import
AssetCreateForm
,
AssetGroupForm
,
IDCForm
,
AdminUserForm
,
SystemUserForm
from
.forms
import
*
from
.hands
import
AdminUserRequiredMixin
from
.hands
import
AdminUserRequiredMixin
...
@@ -53,12 +53,14 @@ class AssetCreateView(AdminUserRequiredMixin, CreateView):
...
@@ -53,12 +53,14 @@ class AssetCreateView(AdminUserRequiredMixin, CreateView):
success_url
=
reverse_lazy
(
'assets:asset-list'
)
success_url
=
reverse_lazy
(
'assets:asset-list'
)
def
form_invalid
(
self
,
form
):
def
form_invalid
(
self
,
form
):
#tags = form.cleaned_data['tags']
print
(
form
.
errors
)
print
(
form
.
errors
)
return
super
(
AssetCreateView
,
self
)
.
form_invalid
(
form
)
return
super
(
AssetCreateView
,
self
)
.
form_invalid
(
form
)
def
form_valid
(
self
,
form
):
def
form_valid
(
self
,
form
):
tag_name_list
=
form
.
cleaned_data
[
'tags'
]
tag_name_list
=
form
.
cleaned_data
[
'tags'
]
print
self
.
tag_type
,
tag_name_list
#
print self.tag_type,tag_name_list
return
super
(
AssetCreateView
,
self
)
.
form_valid
(
form
)
return
super
(
AssetCreateView
,
self
)
.
form_valid
(
form
)
...
@@ -86,6 +88,11 @@ class AssetUpdateView(AdminUserRequiredMixin, UpdateView):
...
@@ -86,6 +88,11 @@ class AssetUpdateView(AdminUserRequiredMixin, UpdateView):
kwargs
.
update
(
context
)
kwargs
.
update
(
context
)
return
super
(
AssetUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
AssetUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
print
"jsf"
return
super
(
AssetUpdateView
,
self
)
.
form_invalid
(
form
)
class
AssetDeleteView
(
DeleteView
):
class
AssetDeleteView
(
DeleteView
):
model
=
Asset
model
=
Asset
...
@@ -119,10 +126,17 @@ class AssetModalListView(AdminUserRequiredMixin, ListView):
...
@@ -119,10 +126,17 @@ class AssetModalListView(AdminUserRequiredMixin, ListView):
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
group_id
=
self
.
request
.
GET
.
get
(
'group_id'
)
group_id
=
self
.
request
.
GET
.
get
(
'group_id'
)
tag_id
=
self
.
request
.
GET
.
get
(
'tag_id'
)
if
group_id
:
if
group_id
:
group
=
AssetGroup
.
objects
.
get
(
id
=
group_id
)
group
=
AssetGroup
.
objects
.
get
(
id
=
group_id
)
context
=
{
context
=
{
'group_assets'
:[
x
.
id
for
x
in
group
.
assets
.
all
()]
'all_assets'
:[
x
.
id
for
x
in
group
.
assets
.
all
()]
}
kwargs
.
update
(
context
)
if
tag_id
:
tag
=
Tag
.
objects
.
get
(
id
=
tag_id
)
context
=
{
'all_assets'
:[
x
.
id
for
x
in
tag
.
asset_set
.
all
()]
}
}
kwargs
.
update
(
context
)
kwargs
.
update
(
context
)
return
super
(
AssetModalListView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
AssetModalListView
,
self
)
.
get_context_data
(
**
kwargs
)
...
@@ -150,7 +164,6 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
...
@@ -150,7 +164,6 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
asset_group
=
form
.
save
()
asset_group
=
form
.
save
()
assets_id_list
=
self
.
request
.
POST
.
getlist
(
'assets'
,
[])
assets_id_list
=
self
.
request
.
POST
.
getlist
(
'assets'
,
[])
assets
=
[
get_object_or_404
(
Asset
,
id
=
int
(
asset_id
))
for
asset_id
in
assets_id_list
]
assets
=
[
get_object_or_404
(
Asset
,
id
=
int
(
asset_id
))
for
asset_id
in
assets_id_list
]
print
assets
asset_group
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
asset_group
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
asset_group
.
assets
.
add
(
*
tuple
(
assets
))
asset_group
.
assets
.
add
(
*
tuple
(
assets
))
asset_group
.
save
()
asset_group
.
save
()
...
@@ -161,6 +174,7 @@ class AssetGroupListView(AdminUserRequiredMixin, ListView):
...
@@ -161,6 +174,7 @@ class AssetGroupListView(AdminUserRequiredMixin, ListView):
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
context_object_name
=
'asset_group_list'
context_object_name
=
'asset_group_list'
template_name
=
'assets/asset_group_list.html'
template_name
=
'assets/asset_group_list.html'
ordering
=
'-id'
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
context
=
{
...
@@ -569,3 +583,94 @@ class TagView(ListView):
...
@@ -569,3 +583,94 @@ class TagView(ListView):
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
kwargs
[
'tag_list'
]
=
[(
i
.
id
,
i
.
name
,
i
.
asset_set
.
all
()
.
count
()
)
for
i
in
Tag
.
objects
.
all
()
.
order_by
(
'name'
)]
kwargs
[
'tag_list'
]
=
[(
i
.
id
,
i
.
name
,
i
.
asset_set
.
all
()
.
count
()
)
for
i
in
Tag
.
objects
.
all
()
.
order_by
(
'name'
)]
return
super
(
TagView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
TagView
,
self
)
.
get_context_data
(
**
kwargs
)
class
TagsListView
(
AdminUserRequiredMixin
,
ListView
):
model
=
Tag
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
context_object_name
=
'asset_tags_list'
template_name
=
'assets/asset_tags_list.html'
ordering
=
'-id'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Tag'
),
'action'
:
_
(
'Asset Tags list'
),
'keyword'
:
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
}
kwargs
.
update
(
context
)
return
super
(
TagsListView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetTagCreateView
(
AdminUserRequiredMixin
,
CreateView
):
model
=
Tag
form_class
=
AssetTagForm
template_name
=
'assets/asset_tag_create.html'
success_url
=
reverse_lazy
(
'assets:asset-tag-list'
)
#ordering = '-id'
# Todo: Asset group create template select assets so hard, need be resolve next
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Tag'
),
'action'
:
_
(
'Asset Tags list'
),
'assets_count'
:
0
,
}
kwargs
.
update
(
context
)
return
super
(
AssetTagCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
form_valid
(
self
,
form
):
asset_tag
=
form
.
save
()
assets_id_list
=
self
.
request
.
POST
.
getlist
(
'assets'
,
[])
assets
=
[
get_object_or_404
(
Asset
,
id
=
int
(
asset_id
))
for
asset_id
in
assets_id_list
]
asset_tag
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
asset_tag
.
asset_set
.
add
(
*
tuple
(
assets
))
asset_tag
.
save
()
return
super
(
AssetTagCreateView
,
self
)
.
form_valid
(
form
)
class
AssetTagDetailView
(
SingleObjectMixin
,
AdminUserRequiredMixin
,
ListView
):
template_name
=
'assets/asset_tag_detail.html'
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
(
queryset
=
Tag
.
objects
.
all
())
return
super
(
AssetTagDetailView
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
def
get_queryset
(
self
):
return
self
.
object
.
asset_set
.
all
()
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Tag'
),
'action'
:
_
(
'Asset Tags detail'
),
'asset_tag'
:
self
.
object
,
}
kwargs
.
update
(
context
)
return
super
(
AssetTagDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetTagUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
model
=
Tag
form_class
=
AssetTagForm
template_name
=
'assets/asset_tag_create.html'
success_url
=
reverse_lazy
(
'assets:asset-tag-list'
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
(
queryset
=
Tag
.
objects
.
all
())
return
super
(
AssetTagUpdateView
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Tag'
),
'action'
:
_
(
'Asset Tags detail'
),
'assets_count'
:
self
.
object
.
asset_set
.
all
()
.
count
(),
'tag_id'
:
self
.
object
.
id
,
}
kwargs
.
update
(
context
)
return
super
(
AssetTagUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetTagDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
template_name
=
'assets/delete_confirm.html'
model
=
Tag
success_url
=
reverse_lazy
(
'assets:asset-tag-list'
)
This diff is collapsed.
Click to expand it.
apps/templates/_nav.html
View file @
b99b88a3
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
<li
id=
"idc"
><a
href=
"{% url 'assets:idc-list' %}"
>
{% trans 'IDC' %}
</a></li>
<li
id=
"idc"
><a
href=
"{% url 'assets:idc-list' %}"
>
{% trans 'IDC' %}
</a></li>
<li
id=
"admin-user"
><a
href=
"{% url 'assets:admin-user-list' %}"
>
{% trans 'Admin user' %}
</a></li>
<li
id=
"admin-user"
><a
href=
"{% url 'assets:admin-user-list' %}"
>
{% trans 'Admin user' %}
</a></li>
<li
id=
"system-user"
><a
href=
"{% url 'assets:system-user-list' %}"
>
{% trans 'System user' %}
</a></li>
<li
id=
"system-user"
><a
href=
"{% url 'assets:system-user-list' %}"
>
{% trans 'System user' %}
</a></li>
<li
id=
"
"
><a
href=
"
"
>
{% trans 'Label' %}
</a></li>
<li
id=
"
asset-tag"
><a
href=
"{% url 'assets:asset-tag-list' %}
"
>
{% trans 'Label' %}
</a></li>
</ul>
</ul>
</li>
</li>
<li
id=
"perms"
>
<li
id=
"perms"
>
...
...
This diff is collapsed.
Click to expand it.
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