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
126d7fd6
Commit
126d7fd6
authored
Sep 05, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add asset group add Form m2m
parent
2cb6b15b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
16 deletions
+32
-16
forms.py
apps/assets/forms.py
+14
-1
models.py
apps/assets/models.py
+1
-1
asset_add.html
apps/assets/templates/assets/asset_add.html
+0
-10
assetgroup_add.html
apps/assets/templates/assets/assetgroup_add.html
+1
-0
assetgroup_list.html
apps/assets/templates/assets/assetgroup_list.html
+1
-1
views.py
apps/assets/views.py
+15
-3
No files found.
apps/assets/forms.py
View file @
126d7fd6
...
@@ -6,7 +6,6 @@ from django.utils.translation import gettext_lazy as _
...
@@ -6,7 +6,6 @@ from django.utils.translation import gettext_lazy as _
class
AssetForm
(
forms
.
ModelForm
):
class
AssetForm
(
forms
.
ModelForm
):
class
Meta
:
class
Meta
:
model
=
Asset
model
=
Asset
...
@@ -22,6 +21,20 @@ class AssetForm(forms.ModelForm):
...
@@ -22,6 +21,20 @@ class AssetForm(forms.ModelForm):
class
AssetGroupForm
(
forms
.
ModelForm
):
class
AssetGroupForm
(
forms
.
ModelForm
):
assets
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Asset
.
objects
.
all
())
def
__init__
(
self
,
*
args
,
**
kwargs
):
if
kwargs
.
get
(
'instance'
):
initial
=
kwargs
.
get
(
'initial'
,
{})
initial
[
'assets'
]
=
kwargs
[
'instance'
]
.
assets
.
all
()
super
(
AssetGroupForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
_save_m2m
(
self
):
super
(
AssetGroupForm
,
self
)
.
_save_m2m
()
assets
=
self
.
cleaned_data
[
'assets'
]
self
.
instance
.
assets
.
clear
()
self
.
instance
.
assets
.
add
(
*
tuple
(
assets
))
class
Meta
:
class
Meta
:
model
=
AssetGroup
model
=
AssetGroup
fields
=
[
fields
=
[
...
...
apps/assets/models.py
View file @
126d7fd6
...
@@ -103,7 +103,7 @@ class Asset(models.Model):
...
@@ -103,7 +103,7 @@ class Asset(models.Model):
remote_card_ip
=
models
.
CharField
(
max_length
=
16
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Remote card IP'
))
remote_card_ip
=
models
.
CharField
(
max_length
=
16
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Remote card IP'
))
hostname
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Hostname'
))
hostname
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Hostname'
))
port
=
models
.
IntegerField
(
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Port'
))
port
=
models
.
IntegerField
(
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Port'
))
groups
=
models
.
ManyToManyField
(
AssetGroup
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Asset groups'
))
groups
=
models
.
ManyToManyField
(
AssetGroup
,
related_name
=
'assets'
,
verbose_name
=
_
(
'Asset groups'
))
username
=
models
.
CharField
(
max_length
=
16
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Admin user'
))
username
=
models
.
CharField
(
max_length
=
16
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Admin user'
))
password
=
models
.
CharField
(
max_length
=
256
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
"Admin password"
))
password
=
models
.
CharField
(
max_length
=
256
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
"Admin password"
))
admin_user
=
models
.
ForeignKey
(
AdminUser
,
null
=
True
,
blank
=
True
,
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
"Admin user"
))
admin_user
=
models
.
ForeignKey
(
AdminUser
,
null
=
True
,
blank
=
True
,
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
"Admin user"
))
...
...
apps/assets/templates/assets/asset_add.html
View file @
126d7fd6
...
@@ -44,18 +44,8 @@
...
@@ -44,18 +44,8 @@
<input
type=
"text"
placeholder=
""
name=
"port"
class=
"form-control"
>
<input
type=
"text"
placeholder=
""
name=
"port"
class=
"form-control"
>
</div>
</div>
</div>
</div>
{#
<div
class=
"form-group"
id=
"id_type"
>
#}
{#
<label
class=
"col-sm-2 control-label"
>
资产类型
</label>
#}
{#
<div
class=
"col-sm-9"
>
#}
{#
<input
type=
"text"
placeholder=
""
name=
"type"
class=
"form-control"
>
#}
{#
</div>
#}
{#
</div>
#}
{{ form.type|bootstrap_horizontal }}
{{ form.type|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<div
class=
"hr-line-dashed"
></div>
<h3>
关联资产用户
</h3>
<h3>
关联资产用户
</h3>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
...
...
apps/assets/templates/assets/assetgroup_add.html
View file @
126d7fd6
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
<form
method=
"post"
id=
"userForm"
class=
"form-horizontal"
action=
""
>
<form
method=
"post"
id=
"userForm"
class=
"form-horizontal"
action=
""
>
{% csrf_token %}
{% csrf_token %}
{{ form.name|bootstrap_horizontal }}
{{ form.name|bootstrap_horizontal }}
{# {{ form.assets|bootstrap_horizontal }}#}
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"users"
class=
"col-sm-2 control-label"
>
{% trans 'Asset' %}
</label>
<label
for=
"users"
class=
"col-sm-2 control-label"
>
{% trans 'Asset' %}
</label>
...
...
apps/assets/templates/assets/assetgroup_list.html
View file @
126d7fd6
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
{{ assetgroup.name }}
{{ assetgroup.name }}
</a>
</a>
</td>
</td>
<td
class=
"text-center"
>
{{ assetgroup.asset
_set
.count }}
</td>
<td
class=
"text-center"
>
{{ assetgroup.asset
s
.count }}
</td>
<td
class=
"text-center"
>
{{ assetgroup.comment }}
</td>
<td
class=
"text-center"
>
{{ assetgroup.comment }}
</td>
<td
class=
"text-center"
>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:assetgroup-edit' pk=assetgroup.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Edit' %}
</a>
<a
href=
"{% url 'assets:assetgroup-edit' pk=assetgroup.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Edit' %}
</a>
...
...
apps/assets/views.py
View file @
126d7fd6
...
@@ -2,17 +2,17 @@
...
@@ -2,17 +2,17 @@
from
__future__
import
absolute_import
,
unicode_literals
from
__future__
import
absolute_import
,
unicode_literals
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
django.shortcuts
import
get_object_or_404
from
django.views.generic
import
TemplateView
,
ListView
from
django.views.generic
import
TemplateView
,
ListView
from
django.urls
import
reverse_lazy
from
django.urls
import
reverse_lazy
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
FormView
,
UpdateView
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
FormView
,
UpdateView
from
django.views.generic
import
TemplateView
,
ListView
from
django.views.generic
import
TemplateView
,
ListView
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
FormView
,
UpdateView
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
FormView
,
UpdateView
from
django.urls
import
reverse_lazy
from
django.urls
import
reverse_lazy
from
django.views.generic.detail
import
DetailView
from
django.views.generic.detail
import
DetailView
from
.models
import
Asset
,
AssetGroup
,
IDC
,
AssetExtend
from
.models
import
Asset
,
AssetGroup
,
IDC
,
AssetExtend
from
.forms
import
AssetForm
,
AssetGroupForm
from
.forms
import
AssetForm
,
AssetGroupForm
from
.utils
import
AdminUserRequiredMixin
from
.utils
import
AdminUserRequiredMixin
...
@@ -83,7 +83,19 @@ class AssetGroupDetailView(DetailView):
...
@@ -83,7 +83,19 @@ class AssetGroupDetailView(DetailView):
class
AssetGroupEditView
(
UpdateView
):
class
AssetGroupEditView
(
UpdateView
):
pass
model
=
AssetGroup
form_class
=
AssetGroupForm
template_name
=
'assets/assetgroup_add.html'
success_url
=
reverse_lazy
(
'assets:assetgroup-list'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Create asset group'
),
'assets'
:
Asset
.
objects
.
all
(),
}
kwargs
.
update
(
context
)
return
super
(
AssetGroupEditView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetGroupDeleteView
(
DeleteView
):
class
AssetGroupDeleteView
(
DeleteView
):
...
...
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