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
3aea9941
Commit
3aea9941
authored
Nov 27, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asset import
parent
c1c9c7b6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
99 additions
and
39 deletions
+99
-39
forms.py
apps/assets/forms.py
+6
-2
models.py
apps/assets/models.py
+3
-3
serializers.py
apps/assets/serializers.py
+7
-7
_asset_import_modal.html
apps/assets/templates/assets/_asset_import_modal.html
+27
-0
asset_detail.html
apps/assets/templates/assets/asset_detail.html
+1
-1
asset_list.html
apps/assets/templates/assets/asset_list.html
+40
-20
views_urls.py
apps/assets/urls/views_urls.py
+2
-0
views.py
apps/assets/views.py
+0
-0
fake.json
apps/fixtures/fake.json
+0
-0
user_list.html
apps/users/templates/users/user_list.html
+1
-1
views_urls.py
apps/users/urls/views_urls.py
+1
-1
views.py
apps/users/views.py
+2
-2
clean_migrations.sh
utils/clean_migrations.sh
+1
-1
make_fake_json.sh
utils/make_fake_json.sh
+8
-1
No files found.
apps/assets/forms.py
View file @
3aea9941
...
...
@@ -309,4 +309,8 @@ class AssetTagForm(forms.ModelForm):
}
help_texts
=
{
'name'
:
'* required'
,
}
\ No newline at end of file
}
class
FileForm
(
forms
.
Form
):
file
=
forms
.
FileField
()
\ No newline at end of file
apps/assets/models.py
View file @
3aea9941
...
...
@@ -309,12 +309,12 @@ class Asset(models.Model):
cabinet_no
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Cabinet number'
))
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'
))
status
=
models
.
CharField
(
choices
=
STATUS_CHOICES
,
max_length
=
1
,
null
=
True
,
blank
=
True
,
default
=
'I'
,
verbose_name
=
_
(
'Asset status'
))
status
=
models
.
CharField
(
choices
=
STATUS_CHOICES
,
max_length
=
8
,
null
=
True
,
blank
=
True
,
default
=
'I
n use
'
,
verbose_name
=
_
(
'Asset status'
))
type
=
models
.
CharField
(
choices
=
TYPE_CHOICES
,
max_length
=
16
,
blank
=
True
,
null
=
True
,
default
=
'Server'
,
verbose_name
=
_
(
'Asset type'
),)
env
=
models
.
CharField
(
choices
=
ENV_CHOICES
,
max_length
=
8
,
blank
=
True
,
null
=
True
,
default
=
'P'
,
verbose_name
=
_
(
'Asset environment'
),)
default
=
'P
rod
'
,
verbose_name
=
_
(
'Asset environment'
),)
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'
))
is_active
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
'Is active'
))
...
...
apps/assets/serializers.py
View file @
3aea9941
...
...
@@ -43,7 +43,6 @@ class AssetSerializer(BulkSerializerMixin, serializers.ModelSerializer):
# system_users = SystemUserSerializer(many=True, read_only=True)
# admin_user = AdminUserSerializer(many=False, read_only=True)
hardware
=
serializers
.
SerializerMethodField
()
type_display
=
serializers
.
SerializerMethodField
()
class
Meta
(
object
):
model
=
Asset
...
...
@@ -51,15 +50,16 @@ class AssetSerializer(BulkSerializerMixin, serializers.ModelSerializer):
@staticmethod
def
get_hardware
(
obj
):
return
'
%
s
%
s
%
s'
%
(
obj
.
cpu
,
obj
.
memory
,
obj
.
disk
)
@staticmethod
def
get_type_display
(
obj
):
if
obj
.
type
:
return
obj
.
type
.
value
if
obj
.
cpu
:
return
'
%
s
%
s
%
s'
%
(
obj
.
cpu
,
obj
.
memory
,
obj
.
disk
)
else
:
return
''
def
get_field_names
(
self
,
declared_fields
,
info
):
fields
=
super
(
AssetSerializer
,
self
)
.
get_field_names
(
declared_fields
,
info
)
fields
.
extend
([
'get_type_display'
,
'get_env_display'
])
return
fields
class
AssetGrantedSerializer
(
serializers
.
ModelSerializer
):
system_users
=
SystemUserSerializer
(
many
=
True
,
read_only
=
True
)
...
...
apps/assets/templates/assets/_asset_import_modal.html
0 → 100644
View file @
3aea9941
{% extends '_modal.html' %}
{% load i18n %}
{% block modal_id %}asset_import_modal{% endblock %}
{% block modal_title%}{% trans "Import asset" %}{% endblock %}
{% block modal_body %}
<p
class=
"text-success"
>
{% trans "Download template or use export excel format" %}
</p>
<form
method=
"post"
action=
"{% url 'assets:asset-import' %}"
id=
"fm_asset_import"
enctype=
"multipart/form-data"
>
{% csrf_token %}
<div
class=
"form-group"
>
<label
class=
"control-label"
for=
"id_assets"
>
{% trans "Template" %}
</label>
<a
href=
"{{ MEDIA_URL }}files/asset_import_template.xlsx"
style=
"display: block"
>
{% trans 'Download' %}
</a>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label"
for=
"id_users"
>
{% trans "Asset excel file" %}
</label>
<input
id=
"id_assets"
type=
"file"
name=
"file"
/>
</div>
</form>
<p>
<p
class=
"text-success"
id=
"id_created"
></p>
<p
id=
"id_created_detail"
></p>
<p
class=
"text-warning"
id=
"id_updated"
></p>
<p
id=
"id_updated_detail"
></p>
<p
class=
"text-danger"
id=
"id_failed"
></p>
<p
id=
"id_failed_detail"
></p>
</p>
{% endblock %}
{% block modal_confirm_id %}btn_asset_import{% endblock %}
apps/assets/templates/assets/asset_detail.html
View file @
3aea9941
...
...
@@ -96,7 +96,7 @@
</tr>
<tr>
<td>
{% trans 'Asset status' %}:
</td>
<td><b>
{{ asset.
status
}}
</b></td>
<td><b>
{{ asset.
get_status_display()
}}
</b></td>
</tr>
<tr>
<td>
{% trans 'Is active' %}:
</td>
...
...
apps/assets/templates/assets/asset_list.html
View file @
3aea9941
...
...
@@ -48,7 +48,6 @@
{% block table_container %}
<div
class=
"uc pull-left m-l-5 m-r-5"
><a
href=
"{% url "
assets:asset-create
"
%}"
class=
"btn btn-sm btn-primary"
>
{% trans "Create asset" %}
</a></div>
<div
class=
"uc pull-left"
><a
href=
"javascript:void(0);"
class=
"btn btn-sm btn-primary"
data-toggle=
"modal"
data-target=
"#asset_import_modal"
>
{% trans "Import asset" %}
</a></div>
<table
class=
"table table-striped table-bordered table-hover "
id=
"asset_list_table"
>
<thead>
<tr>
...
...
@@ -81,6 +80,7 @@
</div>
</div>
</div>
{% include 'assets/_asset_import_modal.html' %}
{% endblock %}
{% block custom_foot_js %}
...
...
@@ -100,7 +100,7 @@
}
else
{
oDiv
.
style
.
display
=
"none"
;
}
}
;
//onload;
}
//onload;
$
(
document
).
ready
(
function
(){
var
options
=
{
...
...
@@ -132,31 +132,51 @@
],
ajax_url
:
'{% url "api-assets:asset-list" %}'
,
columns
:
[{
data
:
"id"
},
{
data
:
"hostname"
},
{
data
:
"ip"
},
{
data
:
"port"
},
{
data
:
"
type_display"
},
{
data
:
"env"
},
{
data
:
"hardware"
},
{
data
:
"is_active"
},
{
data
:
"is_active"
},
{
data
:
"id"
}],
{
data
:
"
get_type_display"
},
{
data
:
"get_env_display"
},
{
data
:
"hardware"
},
{
data
:
"is_active"
},
{
data
:
"is_active"
},
{
data
:
"id"
}],
op_html
:
$
(
'#actions'
).
html
()
};
var
table
=
jumpserver
.
initDataTable
(
options
);
$
(
'.btn_export'
).
click
(
function
()
{
var
assets
=
[];
var
rows
=
table
.
rows
(
'.selected'
).
data
();
$
.
each
(
rows
,
function
(
index
,
obj
)
{
assets
.
push
(
obj
.
id
)
var
assets
=
[];
var
rows
=
table
.
rows
(
'.selected'
).
data
();
$
.
each
(
rows
,
function
(
index
,
obj
)
{
assets
.
push
(
obj
.
id
)
});
$
.
ajax
({
url
:
"{% url "
assets
:
asset
-
export
" %}"
,
method
:
'POST'
,
data
:
JSON
.
stringify
({
assets_id
:
assets
}),
dataType
:
"json"
,
success
:
function
(
data
,
textStatus
)
{
window
.
open
(
data
.
redirect
)
},
error
:
function
()
{
toastr
.
error
(
'Export failed'
);
}
})
});
$
.
ajax
({
url
:
"{% url "
assets
:
export
-
assets
-
xlsx
" %}"
,
method
:
'POST'
,
data
:
JSON
.
stringify
({
users_id
:
users
}),
dataType
:
"json"
,
success
:
function
(
data
,
textStatus
)
{
window
.
open
(
data
.
redirect
)
},
error
:
function
()
{
toastr
.
error
(
'Export failed'
);
$
(
'#btn_asset_import'
).
click
(
function
()
{
var
$form
=
$
(
'#fm_asset_import'
);
$form
.
find
(
'.help-block'
).
remove
();
function
success
(
data
)
{
if
(
data
.
valid
===
false
)
{
$
(
'<span />'
,
{
class
:
'help-block text-danger'
}).
html
(
data
.
msg
).
insertAfter
(
$
(
'#id_users'
));
}
else
{
$
(
'#id_created'
).
html
(
data
.
created_info
);
$
(
'#id_created_detail'
).
html
(
data
.
created
.
join
(
', '
));
$
(
'#id_updated'
).
html
(
data
.
updated_info
);
$
(
'#id_updated_detail'
).
html
(
data
.
updated
.
join
(
', '
));
$
(
'#id_failed'
).
html
(
data
.
failed_info
);
$
(
'#id_failed_detail'
).
html
(
data
.
failed
.
join
(
', '
));
var
$data_table
=
$
(
'#asset_list_table'
).
DataTable
();
$data_table
.
ajax
.
reload
();
}
})
});
}
$form
.
ajaxSubmit
({
success
:
success
});
})
});
</script>
...
...
apps/assets/urls/views_urls.py
View file @
3aea9941
...
...
@@ -9,6 +9,8 @@ urlpatterns = [
url
(
r'^$'
,
views
.
AssetListView
.
as_view
(),
name
=
'asset-index'
),
url
(
r'^asset/$'
,
views
.
AssetListView
.
as_view
(),
name
=
'asset-list'
),
url
(
r'^asset/create/$'
,
views
.
AssetCreateView
.
as_view
(),
name
=
'asset-create'
),
url
(
r'^asset/export/$'
,
views
.
AssetExportView
.
as_view
(),
name
=
'asset-export'
),
url
(
r'^asset/import/$'
,
views
.
BulkImportAssetView
.
as_view
(),
name
=
'asset-import'
),
url
(
r'^asset/(?P<pk>[0-9]+)/$'
,
views
.
AssetDetailView
.
as_view
(),
name
=
'asset-detail'
),
url
(
r'^asset/(?P<pk>[0-9]+)/update/$'
,
views
.
AssetUpdateView
.
as_view
(),
name
=
'asset-update'
),
url
(
r'^asset/(?P<pk>[0-9]+)/delete/$'
,
views
.
AssetDeleteView
.
as_view
(),
name
=
'asset-delete'
),
...
...
apps/assets/views.py
View file @
3aea9941
This diff is collapsed.
Click to expand it.
apps/fixtures/fake.json
View file @
3aea9941
This diff is collapsed.
Click to expand it.
apps/users/templates/users/user_list.html
View file @
3aea9941
...
...
@@ -99,7 +99,7 @@ $(document).ready(function(){
users
.
push
(
obj
.
id
)
});
$
.
ajax
({
url
:
"{% url
"
users
:
export
-
user
"
%}"
,
url
:
"{% url
'users:user-export'
%}"
,
method
:
'POST'
,
data
:
JSON
.
stringify
({
users_id
:
users
}),
dataType
:
"json"
,
...
...
apps/users/urls/views_urls.py
View file @
3aea9941
...
...
@@ -23,6 +23,7 @@ urlpatterns = [
name
=
'user-asset-permission-create'
),
url
(
r'^user/(?P<pk>[0-9]+)/assets'
,
views
.
UserGrantedAssetView
.
as_view
(),
name
=
'user-granted-asset'
),
url
(
r'^user/(?P<pk>[0-9]+)/login-history'
,
views
.
UserDetailView
.
as_view
(),
name
=
'user-login-history'
),
url
(
r'^user/export/'
,
views
.
UserExportView
.
as_view
(),
name
=
'user-export'
),
url
(
r'^first-login/$'
,
views
.
UserFirstLoginView
.
as_view
(),
name
=
'user-first-login'
),
url
(
r'^user/import/$'
,
views
.
BulkImportUserView
.
as_view
(),
name
=
'user-import'
),
# url(r'^user/(?P<pk>[0-9]+)/assets-perm$', views.UserDetailView.as_view(), name='user-detail'),
...
...
@@ -40,5 +41,4 @@ urlpatterns = [
name
=
'user-group-asset-permission-create'
),
url
(
r'^user-group/(?P<pk>[0-9]+)/assets'
,
views
.
UserGroupGrantedAssetView
.
as_view
(),
name
=
'user-group-granted-asset'
),
url
(
r'^export/user/'
,
views
.
ExportUserView
.
as_view
(),
name
=
'export-user'
),
]
apps/users/views.py
View file @
3aea9941
...
...
@@ -557,7 +557,7 @@ class BulkImportUserView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
@method_decorator
(
csrf_exempt
,
name
=
'dispatch'
)
class
ExportUser
View
(
View
):
class
UserExport
View
(
View
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
spm
=
request
.
GET
.
get
(
'spm'
,
''
)
users_id
=
cache
.
get
(
spm
)
...
...
@@ -588,6 +588,6 @@ class ExportUserView(View):
return
HttpResponse
(
'Json object not valid'
,
status
=
400
)
spm
=
uuid
.
uuid4
()
.
get_hex
()
cache
.
set
(
spm
,
users_id
,
300
)
url
=
reverse
(
'users:
export-user-csv
'
)
+
'?spm=
%
s'
%
spm
url
=
reverse
(
'users:
user-export
'
)
+
'?spm=
%
s'
%
spm
return
JsonResponse
({
'redirect'
:
url
})
utils/clean_migrations.sh
View file @
3aea9941
...
...
@@ -2,5 +2,5 @@
#
for
app
in
users
assets perms audits teminal ops
;
do
rm
-f
$app
/migrations/000
*
rm
-f
../apps/
$app
/migrations/000
*
done
utils/make_fake_json.sh
View file @
3aea9941
#!/bin/bash
#
python ../apps/manage.py shell
<<
EOF
from users.models import *
generate_fake()
from assets.models import *
generate_fake()
EOF
python ../apps/manage.py dbshell
<<
EOF
delete from django_content_type;
delete from auth_permission;
EOF
python ../apps/manage.py dumpdata
>
../apps/fixtures/
init
.json
python ../apps/manage.py dumpdata
>
../apps/fixtures/
fake
.json
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