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
24e31a69
Commit
24e31a69
authored
Sep 19, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish asset
parent
d323c9df
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
181 additions
and
77 deletions
+181
-77
forms.py
apps/assets/forms.py
+10
-8
models.py
apps/assets/models.py
+21
-13
asset_create.html
apps/assets/templates/assets/asset_create.html
+0
-0
asset_detail.html
apps/assets/templates/assets/asset_detail.html
+27
-43
asset_list.html
apps/assets/templates/assets/asset_list.html
+4
-4
asset_update.html
apps/assets/templates/assets/asset_update.html
+82
-0
views.py
apps/assets/views.py
+37
-9
No files found.
apps/assets/forms.py
View file @
24e31a69
...
@@ -24,16 +24,16 @@ from django.utils.translation import gettext_lazy as _
...
@@ -24,16 +24,16 @@ from django.utils.translation import gettext_lazy as _
class
AssetCreateForm
(
forms
.
ModelForm
):
class
AssetCreateForm
(
forms
.
ModelForm
):
tags
=
forms
.
CharField
(
label
=
_
(
'Tags'
),
widget
=
forms
.
TextInput
(
attrs
=
{
'id'
:
'tags'
}),
tags
=
forms
.
CharField
(
label
=
_
(
'Tags'
),
widget
=
forms
.
TextInput
(
attrs
=
{
'id'
:
'tags'
}),
help_text
=
'Use `,` split'
)
required
=
False
,
help_text
=
'Use `,` split'
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
instance
=
kwargs
.
get
(
'instance'
)
instance
=
kwargs
.
get
(
'instance'
,
None
)
if
instance
:
if
instance
:
initial
=
kwargs
.
get
(
'initial'
,
{})
initial
=
kwargs
.
get
(
'initial'
,
{})
tags
=
Tag
.
objects
.
filter
(
asset
=
instance
)
tags
=
instance
.
tags
.
all
(
)
tags_value
=
','
.
join
([
tag
.
value
for
tag
in
tags
])
initial
[
'tags'
]
=
","
.
join
([
tag
.
value
for
tag
in
tags
])
initial
[
'tags'
]
=
tags_value
print
(
kwargs
.
get
(
'initial'
))
super
(
AssetCreateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
AssetCreateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
_save_m2m
(
self
):
def
_save_m2m
(
self
):
...
@@ -43,14 +43,16 @@ class AssetCreateForm(forms.ModelForm):
...
@@ -43,14 +43,16 @@ class AssetCreateForm(forms.ModelForm):
value_list
=
tags
.
split
(
','
)
value_list
=
tags
.
split
(
','
)
self
.
instance
.
tags
.
all
()
.
delete
()
self
.
instance
.
tags
.
all
()
.
delete
()
Tag
.
objects
.
bulk_create
(
Tag
.
objects
.
bulk_create
(
[
Tag
(
value
=
value
)
for
value
in
value_list
]
[
Tag
(
value
=
value
,
asset
=
self
.
instance
)
for
value
in
value_list
]
)
)
class
Meta
:
class
Meta
:
model
=
Asset
model
=
Asset
fields
=
[
fields
=
[
'hostname'
,
'ip'
,
'port'
,
'type'
,
'comment'
,
'admin_user'
,
'system_users'
,
'idc'
,
'groups'
'hostname'
,
'ip'
,
'port'
,
'type'
,
'comment'
,
'admin_user'
,
'system_users'
,
'idc'
,
'groups'
,
'other_ip'
,
'remote_card_ip'
,
'mac_address'
,
'brand'
,
'cpu'
,
'memory'
,
'disk'
,
'os'
,
'cabinet_no'
,
'cabinet_pos'
,
'number'
,
'status'
,
'env'
,
'sn'
,
]
]
widgets
=
{
widgets
=
{
'groups'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'groups'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
...
@@ -75,7 +77,7 @@ class AssetGroupForm(forms.ModelForm):
...
@@ -75,7 +77,7 @@ class AssetGroupForm(forms.ModelForm):
)
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
if
kwargs
.
get
(
'instance'
):
if
kwargs
.
get
(
'instance'
,
None
):
initial
=
kwargs
.
get
(
'initial'
,
{})
initial
=
kwargs
.
get
(
'initial'
,
{})
initial
[
'assets'
]
=
kwargs
[
'instance'
]
.
assets
.
all
()
initial
[
'assets'
]
=
kwargs
[
'instance'
]
.
assets
.
all
()
super
(
AssetGroupForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
AssetGroupForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
...
...
apps/assets/models.py
View file @
24e31a69
...
@@ -277,7 +277,10 @@ class AssetGroup(models.Model):
...
@@ -277,7 +277,10 @@ class AssetGroup(models.Model):
def
get_default_extend
(
key
,
value
):
def
get_default_extend
(
key
,
value
):
return
AssetExtend
.
objects
.
get_or_create
(
key
=
key
,
value
=
value
)[
0
]
try
:
return
AssetExtend
.
objects
.
get_or_create
(
key
=
key
,
value
=
value
)[
0
]
except
:
return
None
def
get_default_idc
():
def
get_default_idc
():
...
@@ -295,8 +298,8 @@ class Asset(models.Model):
...
@@ -295,8 +298,8 @@ class Asset(models.Model):
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
"Admin user"
))
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
"Admin user"
))
system_users
=
models
.
ManyToManyField
(
SystemUser
,
blank
=
True
,
related_name
=
'assets'
,
verbose_name
=
_
(
"System User"
))
system_users
=
models
.
ManyToManyField
(
SystemUser
,
blank
=
True
,
related_name
=
'assets'
,
verbose_name
=
_
(
"System User"
))
idc
=
models
.
ForeignKey
(
IDC
,
null
=
True
,
related_name
=
'assets'
,
idc
=
models
.
ForeignKey
(
IDC
,
null
=
True
,
related_name
=
'assets'
,
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
'IDC'
),
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
'IDC'
),
)
default
=
get_default_idc
)
#
default=get_default_idc)
mac_address
=
models
.
CharField
(
max_length
=
20
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
"Mac address"
))
mac_address
=
models
.
CharField
(
max_length
=
20
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
"Mac address"
))
brand
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Brand'
))
brand
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Brand'
))
cpu
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'CPU'
))
cpu
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'CPU'
))
...
@@ -307,14 +310,14 @@ class Asset(models.Model):
...
@@ -307,14 +310,14 @@ class Asset(models.Model):
cabinet_pos
=
models
.
IntegerField
(
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Cabinet position'
))
cabinet_pos
=
models
.
IntegerField
(
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Cabinet position'
))
number
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Asset number'
))
number
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Asset number'
))
status
=
models
.
ForeignKey
(
AssetExtend
,
null
=
True
,
blank
=
True
,
status
=
models
.
ForeignKey
(
AssetExtend
,
null
=
True
,
blank
=
True
,
related_name
=
"status_asset"
,
verbose_name
=
_
(
'Asset status'
),
related_name
=
"status_asset"
,
verbose_name
=
_
(
'Asset status'
),
)
default
=
functools
.
partial
(
get_default_extend
,
'status'
,
'In use'
))
#
default=functools.partial(get_default_extend, 'status', 'In use'))
type
=
models
.
ForeignKey
(
AssetExtend
,
null
=
True
,
limit_choices_to
=
{
'key'
:
'type'
},
type
=
models
.
ForeignKey
(
AssetExtend
,
null
=
True
,
limit_choices_to
=
{
'key'
:
'type'
},
related_name
=
"type_asset"
,
verbose_name
=
_
(
'Asset type'
),
related_name
=
"type_asset"
,
verbose_name
=
_
(
'Asset type'
),
)
default
=
functools
.
partial
(
get_default_extend
,
'type'
,
'Server'
))
#
default=functools.partial(get_default_extend, 'type','Server'))
env
=
models
.
ForeignKey
(
AssetExtend
,
null
=
True
,
limit_choices_to
=
{
'key'
:
'env'
},
env
=
models
.
ForeignKey
(
AssetExtend
,
blank
=
True
,
null
=
True
,
limit_choices_to
=
{
'key'
:
'env'
},
related_name
=
"env_asset"
,
verbose_name
=
_
(
'Asset environment'
),
related_name
=
"env_asset"
,
verbose_name
=
_
(
'Asset environment'
),
)
default
=
functools
.
partial
(
get_default_extend
,
'env'
,
'Production'
))
#
default=functools.partial(get_default_extend, 'env', 'Production'))
sn
=
models
.
CharField
(
max_length
=
128
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Serial number'
))
sn
=
models
.
CharField
(
max_length
=
128
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Serial number'
))
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'
))
is_active
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
'Is active'
))
is_active
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
'Is active'
))
...
@@ -324,8 +327,13 @@ class Asset(models.Model):
...
@@ -324,8 +327,13 @@ class Asset(models.Model):
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
'
%(ip)
s:
%(port)
s'
%
{
'ip'
:
self
.
ip
,
'port'
:
self
.
port
}
return
'
%(ip)
s:
%(port)
s'
%
{
'ip'
:
self
.
ip
,
'port'
:
self
.
port
}
def
initial
(
self
):
def
is_valid
(
self
):
pass
warning
=
''
if
not
self
.
is_active
:
warning
+=
' inactive'
else
:
return
True
,
''
return
False
,
warning
class
Meta
:
class
Meta
:
db_table
=
'asset'
db_table
=
'asset'
...
@@ -367,7 +375,7 @@ class Tag(models.Model):
...
@@ -367,7 +375,7 @@ class Tag(models.Model):
unique_together
=
(
'value'
,
'asset'
)
unique_together
=
(
'value'
,
'asset'
)
def
init
ial
():
def
init
_all_models
():
for
cls
in
(
AssetExtend
,
AssetGroup
):
for
cls
in
(
AssetExtend
,
AssetGroup
):
cls
.
initial
()
cls
.
initial
()
...
...
apps/assets/templates/assets/asset_create
_update
.html
→
apps/assets/templates/assets/asset_create.html
View file @
24e31a69
File moved
apps/assets/templates/assets/asset_detail.html
View file @
24e31a69
...
@@ -16,10 +16,12 @@
...
@@ -16,10 +16,12 @@
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"panel-options"
>
<div
class=
"panel-options"
>
<ul
class=
"nav nav-tabs"
>
<ul
class=
"nav nav-tabs"
>
<li
class=
"active"
><a
href=
""
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
{% trans 'Asset detail' %}
</a>
<li
class=
"active"
>
<a
href=
""
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
{% trans 'Asset detail' %}
</a>
</li>
<li>
<a
href=
""
class=
"text-center"
><i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Asset login log' %}
</a>
</li>
</li>
<li><a
href=
""
class=
"text-center"
><i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Asset users' %}
</a></li>
<li><a
href=
""
class=
"text-center"
><i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Asset login log' %}
</a></li>
</ul>
</ul>
</div>
</div>
<div
class=
"tab-content"
>
<div
class=
"tab-content"
>
...
@@ -45,11 +47,6 @@
...
@@ -45,11 +47,6 @@
<table
class=
"table"
>
<table
class=
"table"
>
<tbody>
<tbody>
<tr
class=
"no-borders-tr"
>
<tr
class=
"no-borders-tr"
>
{#
<td
colspan=
"2"
>
#}
{#
<img
src=
"{{ asset | user_avatar_url }}"
class=
"img-circle"
width=
"64"
height=
"64"
>
#}
{#
</td>
#}
</tr>
<tr>
<td
width=
"20%"
>
{% trans 'Hostname' %}:
</td>
<td
width=
"20%"
>
{% trans 'Hostname' %}:
</td>
<td><b>
{{ asset.hostname }}
</b></td>
<td><b>
{{ asset.hostname }}
</b></td>
</tr>
</tr>
...
@@ -85,20 +82,10 @@
...
@@ -85,20 +82,10 @@
<td>
{% trans 'Disk' %}:
</td>
<td>
{% trans 'Disk' %}:
</td>
<td><b>
{{ asset.disk }}
</b></td>
<td><b>
{{ asset.disk }}
</b></td>
</tr>
</tr>
<tr>
<td>
{% trans 'Label' %}:
</td>
{% for label in asset.label_set.all %}
<td><b>
{{ label.key }} - {{ label.value }}
</b></td>
{% endfor %}
</tr>
<tr>
<tr>
<td>
{% trans 'OS' %}:
</td>
<td>
{% trans 'OS' %}:
</td>
<td><b>
{{ asset.os }}
</b></td>
<td><b>
{{ asset.os }}
</b></td>
</tr>
</tr>
<tr>
<td>
{% trans 'Mac address' %}:
</td>
<td><b>
{{ asset.mac_addr }}
</b></td>
</tr>
<tr>
<tr>
<td>
{% trans 'Asset status' %}:
</td>
<td>
{% trans 'Asset status' %}:
</td>
<td><b>
{{ asset.status }}
</b></td>
<td><b>
{{ asset.status }}
</b></td>
...
@@ -163,44 +150,38 @@
...
@@ -163,44 +150,38 @@
</span></td>
</span></td>
</tr>
</tr>
<tr>
<tr>
<td>
{% trans 'Enable OTP' %}:
</td>
<td>
{% trans 'Rrefresh hardware' %}:
</td>
<td><span
class=
"pull-right"
>
<td>
<div
class=
"switch"
>
<span
class=
"pull-right"
>
<div
class=
"onoffswitch"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
>
{% trans 'Refresh' %}
</button>
<input
type=
"checkbox"
class=
"onoffswitch-checkbox"
{%
if
asset
.
enable_otp
%}
checked
{%
endif
%}
</span>
id=
"enable_otp"
>
</td>
<label
class=
"onoffswitch-label"
for=
"enable_otp"
>
<span
class=
"onoffswitch-inner"
></span>
<span
class=
"onoffswitch-switch"
></span>
</label>
</div>
</div>
</span></td>
</tr>
</tr>
<tr>
<tr>
<td>
{% trans '
Reset password
' %}:
</td>
<td>
{% trans '
Test admin user
' %}:
</td>
<td>
<td>
<span
class=
"pull-right"
>
<span
class=
"pull-right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn_reset_p
assword"
style=
"width: 54px"
>
{% trans 'Rese
t' %}
</button>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn_reset_p
k"
style=
"width: 54px;"
>
{% trans 'Tes
t' %}
</button>
</span>
</span>
</td>
</td>
</tr>
</tr>
<tr>
<tr>
<td>
{% trans '
Reset ssh key
' %}:
</td>
<td>
{% trans '
Test system users
' %}:
</td>
<td>
<td>
<span
class=
"pull-right"
>
<span
class=
"pull-right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn_reset_pk"
style=
"width: 54px;"
>
{% trans '
Rese
t' %}
</button>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn_reset_pk"
style=
"width: 54px;"
>
{% trans '
Tes
t' %}
</button>
</span>
</span>
</td>
</td>
</tr>
</tr>
</tbody>
</tbody>
</tbody>
</table>
</table>
</div>
</div>
</div>
</div>
<div
class=
"panel panel-info"
>
<div
class=
"panel panel-info"
>
<div
class=
"panel-heading"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Asset group' %}
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Asset group
s
' %}
</div>
</div>
<div
class=
"panel-body"
>
<div
class=
"panel-body"
>
<table
class=
"table group_edit"
>
<table
class=
"table group_edit"
>
...
@@ -208,25 +189,25 @@
...
@@ -208,25 +189,25 @@
<form>
<form>
<tr>
<tr>
<td
colspan=
"2"
class=
"no-borders"
>
<td
colspan=
"2"
class=
"no-borders"
>
<select
data-placeholder=
"{% trans 'Join
user groups' %}"
id=
"slct_groups
"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
<select
data-placeholder=
"{% trans 'Join
asset groups' %}
"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for
group in groups
%}
{% for
asset_group in asset_groups_remain
%}
<option
value=
"{{
group.id }}"
id=
"opt_{{ group.id }}"
>
{{
group.name }}
</option>
<option
value=
"{{
asset_group.id }}"
>
{{ asset_
group.name }}
</option>
{% endfor %}
{% endfor %}
</select>
</select>
</td>
</td>
</tr>
</tr>
<tr>
<tr>
<td
colspan=
"2"
class=
"no-borders"
>
<td
colspan=
"2"
class=
"no-borders"
>
<button
type=
"button"
class=
"btn btn-info btn-sm
all
"
id=
"btn_add_user_group"
>
{% trans 'Join' %}
</button>
<button
type=
"button"
class=
"btn btn-info btn-sm"
id=
"btn_add_user_group"
>
{% trans 'Join' %}
</button>
</td>
</td>
</tr>
</tr>
</form>
</form>
{% for
group in asset.groups.all
%}
{% for
asset_group in asset_groups
%}
<tr>
<tr>
<td
><b
class=
"bdg_user_group"
data-gid=
{{
group
.
id
}}
>
{{
group.name }}
</b></td>
<td
><b
data-gid=
{{
asset_group
.
id
}}
>
{{ asset_
group.name }}
</b></td>
<td>
<td>
<button
class=
"btn btn-danger pull-right btn-
sm btn_delete_user_group
"
type=
"button"
><i
class=
"fa fa-minus"
></i></button>
<button
class=
"btn btn-danger pull-right btn-
xs
"
type=
"button"
><i
class=
"fa fa-minus"
></i></button>
</td>
</td>
</tr>
</tr>
{% endfor %}
{% endfor %}
...
@@ -243,5 +224,8 @@
...
@@ -243,5 +224,8 @@
{% endblock %}
{% endblock %}
{% block custom_foot_js %}
{% block custom_foot_js %}
<script>
<script>
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
})
</script>
</script>
{% endblock %}
{% endblock %}
apps/assets/templates/assets/asset_list.html
View file @
24e31a69
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
<input
type=
"checkbox"
name=
"checked"
value=
"{{ asset.id }}"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ asset.id }}"
>
</td>
</td>
<td
class=
"text-center"
>
<td
class=
"text-center"
>
<a
href=
"{% url '
users:user
-detail' pk=user.id %}"
>
<a
href=
"{% url '
assets:asset
-detail' pk=user.id %}"
>
{{ asset.hostname }}
{{ asset.hostname }}
</a>
</a>
</td>
</td>
...
@@ -34,10 +34,10 @@
...
@@ -34,10 +34,10 @@
<td
class=
"text-center"
>
{{ asset.type }}
</td>
<td
class=
"text-center"
>
{{ asset.type }}
</td>
<td
class=
"text-center"
>
{{ asset.cpu }} {{ asset.memory }} {{ asset.disk }}
</td>
<td
class=
"text-center"
>
{{ asset.cpu }} {{ asset.memory }} {{ asset.disk }}
</td>
<td
class=
"text-center"
>
<td
class=
"text-center"
>
{% if asset.is_expired %}
{% if asset.is_valid.0 %}
<i
class=
"fa fa-times text-danger"
></i>
{% else %}
<i
class=
"fa fa-check text-navy"
></i>
<i
class=
"fa fa-check text-navy"
></i>
{% else %}
<i
class=
"fa fa-times text-danger"
></i>
{% endif %}
{% endif %}
</td>
</td>
<td
class=
"text-center"
>
<td
class=
"text-center"
>
...
...
apps/assets/templates/assets/asset_update.html
0 → 100644
View file @
24e31a69
{% extends '_base_create_update.html' %}
{% load static %}
{% load bootstrap %}
{% load i18n %}
{% block custom_head_css_js_create %}
<link
href=
"{% static "
css
/
plugins
/
inputTags
.
css
"
%}"
rel=
"stylesheet"
>
<script
src=
"{% static "
js
/
plugins
/
inputTags
.
jquery
.
min
.
js
"
%}"
></script>
{% endblock %}
{% block form %}
<form
action=
""
method=
"post"
class=
"form-horizontal"
>
{% csrf_token %}
<h3>
{% trans 'Basic' %}
</h3>
{{ form.hostname|bootstrap_horizontal }}
{{ form.ip|bootstrap_horizontal }}
{{ form.port|bootstrap_horizontal }}
{{ form.type|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Group' %}
</h3>
{{ form.idc|bootstrap_horizontal }}
{{ form.groups|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Asset user' %}
</h3>
{{ form.admin_user|bootstrap_horizontal }}
{{ form.system_users|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Hardware' %}
</h3>
{{ form.sn|bootstrap_horizontal }}
{{ form.brand|bootstrap_horizontal }}
{{ form.cpu|bootstrap_horizontal }}
{{ form.memory|bootstrap_horizontal }}
{{ form.disk|bootstrap_horizontal }}
{{ form.mac_address|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Configuration' %}
</h3>
{{ form.number|bootstrap_horizontal }}
{{ form.other_ip|bootstrap_horizontal }}
{{ form.remote_card_ip|bootstrap_horizontal }}
{{ form.os|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Location' %}
</h3>
{{ form.cabinet_no|bootstrap_horizontal }}
{{ form.cabinet_pos|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Other' %}
</h3>
{{ form.status|bootstrap_horizontal }}
{{ form.env|bootstrap_horizontal }}
{{ form.tags|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
<button
class=
"btn btn-white"
type=
"reset"
>
{% trans 'Reset' %}
</button>
<button
id=
"submit_button"
class=
"btn btn-primary"
type=
"submit"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</form>
{% endblock %}
{% block custom_foot_js %}
<script>
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
{
#
$
(
'#tags'
).
inputTags
({
#
}
{
#
tags
:
[{
%
for
tag
in
form
.
tags
.
value
%
}
{{
tag
|
safe
}},
{
%
endfor
%
}]
#
}
{
#
});
#
}
$
(
'#tags'
).
inputTags
(
);
})
</script>
{% endblock %}
\ No newline at end of file
apps/assets/views.py
View file @
24e31a69
...
@@ -17,7 +17,7 @@ from .forms import AssetCreateForm, AssetGroupForm, IDCForm, AdminUserForm, Syst
...
@@ -17,7 +17,7 @@ from .forms import AssetCreateForm, AssetGroupForm, IDCForm, AdminUserForm, Syst
from
.hands
import
AdminUserRequiredMixin
from
.hands
import
AdminUserRequiredMixin
class
AssetListView
(
ListView
):
class
AssetListView
(
AdminUserRequiredMixin
,
ListView
):
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
model
=
Asset
model
=
Asset
context_object_name
=
'asset_list'
context_object_name
=
'asset_list'
...
@@ -25,9 +25,15 @@ class AssetListView(ListView):
...
@@ -25,9 +25,15 @@ class AssetListView(ListView):
def
get_queryset
(
self
):
def
get_queryset
(
self
):
queryset
=
super
(
AssetListView
,
self
)
.
get_queryset
()
queryset
=
super
(
AssetListView
,
self
)
.
get_queryset
()
queryset
=
sorted
(
queryset
,
key
=
lambda
asset
:
int_seq
(
asset
.
ip
.
split
(
'.'
))
)
queryset
=
sorted
(
queryset
,
key
=
self
.
sorted_by_valid_and_ip
)
return
queryset
return
queryset
@staticmethod
def
sorted_by_valid_and_ip
(
asset
):
ip_list
=
int_seq
(
asset
.
ip
.
split
(
'.'
))
ip_list
.
insert
(
0
,
asset
.
is_valid
()[
0
])
return
ip_list
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
context
=
{
'app'
:
'Assets'
,
'app'
:
'Assets'
,
...
@@ -40,13 +46,12 @@ class AssetListView(ListView):
...
@@ -40,13 +46,12 @@ class AssetListView(ListView):
class
AssetCreateView
(
AdminUserRequiredMixin
,
CreateView
):
class
AssetCreateView
(
AdminUserRequiredMixin
,
CreateView
):
model
=
Asset
model
=
Asset
form_class
=
AssetCreateForm
form_class
=
AssetCreateForm
template_name
=
'assets/asset_create
_update
.html'
template_name
=
'assets/asset_create.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
success_url
=
reverse_lazy
(
'assets:asset-list'
)
# def form_valid(self, form):
def
form_invalid
(
self
,
form
):
# asset = form.save()
print
(
form
.
errors
)
# print(self.request.POST.get('tags'))
return
super
(
AssetCreateView
,
self
)
.
form_invalid
(
form
)
# return super(AssetCreateView, self).form_valid(form)
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
context
=
{
...
@@ -57,8 +62,19 @@ class AssetCreateView(AdminUserRequiredMixin, CreateView):
...
@@ -57,8 +62,19 @@ class AssetCreateView(AdminUserRequiredMixin, CreateView):
return
super
(
AssetCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
AssetCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetUpdateView
(
UpdateView
):
class
AssetUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
pass
model
=
Asset
form_class
=
AssetCreateForm
template_name
=
'assets/asset_update.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'Assets'
,
'action'
:
'Update asset'
,
}
kwargs
.
update
(
context
)
return
super
(
AssetUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetDeleteView
(
DeleteView
):
class
AssetDeleteView
(
DeleteView
):
...
@@ -72,6 +88,18 @@ class AssetDetailView(DetailView):
...
@@ -72,6 +88,18 @@ class AssetDetailView(DetailView):
context_object_name
=
'asset'
context_object_name
=
'asset'
template_name
=
'assets/asset_detail.html'
template_name
=
'assets/asset_detail.html'
def
get_context_data
(
self
,
**
kwargs
):
asset_groups
=
self
.
object
.
groups
.
all
()
context
=
{
'app'
:
'Assets'
,
'action'
:
'Asset detail'
,
'asset_groups_remain'
:
[
asset_group
for
asset_group
in
AssetGroup
.
objects
.
all
()
if
asset_group
not
in
asset_groups
],
'asset_groups'
:
asset_groups
,
}
kwargs
.
update
(
context
)
return
super
(
AssetDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetGroupCreateView
(
AdminUserRequiredMixin
,
CreateView
):
class
AssetGroupCreateView
(
AdminUserRequiredMixin
,
CreateView
):
model
=
AssetGroup
model
=
AssetGroup
...
...
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