Commit a5e48744 authored by ibuler's avatar ibuler

prepare change api name

parent aa08f0aa
...@@ -9,66 +9,66 @@ app_name = 'assets' ...@@ -9,66 +9,66 @@ app_name = 'assets'
urlpatterns = [ urlpatterns = [
# Resource asset url # Resource asset url
url(r'^$', views.AssetListView.as_view(), name='asset-index'), url(r'^$', views.AssetListView.as_view(), name='asset-index'),
url(r'^asset$', views.AssetListView.as_view(), name='asset-list'), url(r'^asset/$', views.AssetListView.as_view(), name='asset-list'),
url(r'^asset/create$', views.AssetCreateView.as_view(), name='asset-create'), url(r'^asset/create/$', views.AssetCreateView.as_view(), name='asset-create'),
url(r'^asset/(?P<pk>[0-9]+)$', views.AssetDetailView.as_view(), name='asset-detail'), 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]+)/update/$', views.AssetUpdateView.as_view(), name='asset-update'),
url(r'^asset/(?P<pk>[0-9]+)/delete$', views.AssetDeleteView.as_view(), name='asset-delete'), url(r'^asset/(?P<pk>[0-9]+)/delete/$', views.AssetDeleteView.as_view(), name='asset-delete'),
url(r'^asset-modal$', views.AssetModalListView.as_view(), name='asset-modal-list'), url(r'^asset-modal$', views.AssetModalListView.as_view(), name='asset-modal-list'),
url(r'^asset-modal-update$', views.AssetModalCreateView.as_view(), name='asset-modal-update'), url(r'^asset-modal-update$', views.AssetModalCreateView.as_view(), name='asset-modal-update'),
# Resource asset group url # Resource asset group url
url(r'^asset-group$', views.AssetGroupListView.as_view(), name='asset-group-list'), url(r'^asset-group/$', views.AssetGroupListView.as_view(), name='asset-group-list'),
url(r'^asset-group/create$', views.AssetGroupCreateView.as_view(), name='asset-group-create'), url(r'^asset-group/create/$', views.AssetGroupCreateView.as_view(), name='asset-group-create'),
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'^tags$', views.TagsListView.as_view(), name='asset-tag-list'), 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'^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'^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]+)/$', 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]+)/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'), 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'),
url(r'^idc/create$', views.IDCCreateView.as_view(), name='idc-create'), url(r'^idc/create/$', views.IDCCreateView.as_view(), name='idc-create'),
url(r'^idc/(?P<pk>[0-9]+)$', views.IDCDetailView.as_view(), name='idc-detail'), url(r'^idc/(?P<pk>[0-9]+)/$', views.IDCDetailView.as_view(), name='idc-detail'),
url(r'^idc/(?P<pk>[0-9]+)/update', views.IDCUpdateView.as_view(), name='idc-update'), url(r'^idc/(?P<pk>[0-9]+)/update/', views.IDCUpdateView.as_view(), name='idc-update'),
url(r'^idc/(?P<pk>[0-9]+)/delete$', views.IDCDeleteView.as_view(), name='idc-delete'), url(r'^idc/(?P<pk>[0-9]+)/delete/$', views.IDCDeleteView.as_view(), name='idc-delete'),
url(r'^idc/(?P<pk>[0-9]+)/assets$', views.IDCAssetsView.as_view(), name='idc-assets'), url(r'^idc/(?P<pk>[0-9]+)/assets/$', views.IDCAssetsView.as_view(), name='idc-assets'),
# Resource admin user url # Resource admin user url
url(r'^admin-user$', views.AdminUserListView.as_view(), name='admin-user-list'), url(r'^admin-user/$', views.AdminUserListView.as_view(), name='admin-user-list'),
url(r'^admin-user/create$', views.AdminUserCreateView.as_view(), name='admin-user-create'), url(r'^admin-user/create/$', views.AdminUserCreateView.as_view(), name='admin-user-create'),
url(r'^admin-user/(?P<pk>[0-9]+)$', views.AdminUserDetailView.as_view(), name='admin-user-detail'), url(r'^admin-user/(?P<pk>[0-9]+)/$', views.AdminUserDetailView.as_view(), name='admin-user-detail'),
url(r'^admin-user/(?P<pk>[0-9]+)/update', views.AdminUserUpdateView.as_view(), name='admin-user-update'), url(r'^admin-user/(?P<pk>[0-9]+)/update/$', views.AdminUserUpdateView.as_view(), name='admin-user-update'),
url(r'^admin-user/(?P<pk>[0-9]+)/delete$', views.AdminUserDeleteView.as_view(), name='admin-user-delete'), url(r'^admin-user/(?P<pk>[0-9]+)/delete/$', views.AdminUserDeleteView.as_view(), name='admin-user-delete'),
# Resource system user url # Resource system user url
url(r'^system-user$', views.SystemUserListView.as_view(), name='system-user-list'), url(r'^system-user/$', views.SystemUserListView.as_view(), name='system-user-list'),
url(r'^system-user/create$', views.SystemUserCreateView.as_view(), name='system-user-create'), url(r'^system-user/create/$', views.SystemUserCreateView.as_view(), name='system-user-create'),
url(r'^system-user/(?P<pk>[0-9]+)$', views.SystemUserDetailView.as_view(), name='system-user-detail'), url(r'^system-user/(?P<pk>[0-9]+)/$', views.SystemUserDetailView.as_view(), name='system-user-detail'),
url(r'^system-user/(?P<pk>[0-9]+)/update', views.SystemUserUpdateView.as_view(), name='system-user-update'), url(r'^system-user/(?P<pk>[0-9]+)/update/$', views.SystemUserUpdateView.as_view(), name='system-user-update'),
url(r'^system-user/(?P<pk>[0-9]+)/delete$', views.SystemUserDeleteView.as_view(), name='system-user-delete'), url(r'^system-user/(?P<pk>[0-9]+)/delete/$', views.SystemUserDeleteView.as_view(), name='system-user-delete'),
url(r'^system-user/(?P<pk>[0-9]+)/asset$', views.SystemUserAssetView.as_view(), name='system-user-asset'), url(r'^system-user/(?P<pk>[0-9]+)/asset/$', views.SystemUserAssetView.as_view(), name='system-user-asset'),
# url(r'^system-user/(?P<pk>[0-9]+)/asset-group$', views.SystemUserAssetGroupView.as_view(), # url(r'^system-user/(?P<pk>[0-9]+)/asset-group$', views.SystemUserAssetGroupView.as_view(),
# name='system-user-asset-group'), # name='system-user-asset-group'),
] ]
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'v1/asset-groups', api.AssetGroupViewSet, 'api-asset-group') router.register(r'v1/asset-groups', api.AssetGroupViewSet, 'asset-group')
router.register(r'v1/assets', api.AssetViewSet, 'api-asset') router.register(r'v1/assets', api.AssetViewSet, 'asset')
router.register(r'v1/idc', api.IDCViewSet, 'api-idc') router.register(r'v1/idc', api.IDCViewSet, 'idc')
router.register(r'v1/admin-user', api.AdminUserViewSet, 'api-admin-user') router.register(r'v1/admin-user', api.AdminUserViewSet, 'admin-user')
router.register(r'v1/system-user', api.SystemUserViewSet, 'api-system-user') router.register(r'v1/system-user', api.SystemUserViewSet, 'system-user')
urlpatterns += [ urlpatterns += [
url(r'^v1/assets_bulk/$', api.AssetListUpdateApi.as_view(), name='api-asset-bulk-update'), url(r'^v1/assets_bulk/$', api.AssetListUpdateApi.as_view(), name='asset-bulk-update'),
# url(r'^v1/idc/(?P<pk>[0-9]+)/assets/$', api.IDCAssetsApi.as_view(), name='api-idc-assets'), # url(r'^v1/idc/(?P<pk>[0-9]+)/assets/$', api.IDCAssetsApi.as_view(), name='api-idc-assets'),
url(r'^v1/system-user/auth/', api.SystemUserAuthApi.as_view(), name='api-system-user-auth'), url(r'^v1/system-user/auth/', api.SystemUserAuthApi.as_view(), name='system-user-auth'),
] ]
urlpatterns += router.urls urlpatterns += router.urls
...@@ -16,7 +16,7 @@ urlpatterns = [ ...@@ -16,7 +16,7 @@ urlpatterns = [
] ]
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'v1/proxy-log', api.ProxyLogViewSet, 'api-proxy-log') router.register(r'v1/proxy-log', api.ProxyLogViewSet, 'proxy-log')
router.register(r'v1/command-log', api.CommandLogViewSet, 'api-command-log') router.register(r'v1/command-log', api.CommandLogViewSet, 'command-log')
urlpatterns += router.urls urlpatterns += router.urls
...@@ -22,11 +22,16 @@ from django.views.generic.base import TemplateView ...@@ -22,11 +22,16 @@ from django.views.generic.base import TemplateView
urlpatterns = [ urlpatterns = [
url(r'^captcha/', include('captcha.urls')), url(r'^captcha/', include('captcha.urls')),
url(r'^$', TemplateView.as_view(template_name='base.html'), name='index'), url(r'^$', TemplateView.as_view(template_name='base.html'), name='index'),
url(r'^(api/)?users/', include('users.urls')), url(r'^users/', include('users.urls', namespace='users')),
url(r'^(api/)?assets/', include('assets.urls')), url(r'^assets/', include('assets.urls', namespace='assets')),
url(r'^(api/)?perms/', include('perms.urls')), url(r'^perms/', include('perms.urls', namespace='perms')),
url(r'^(api/)?audits/', include('audits.urls')), url(r'^audits/', include('audits.urls', namespace='audits')),
url(r'^(api/)?terminal/', include('terminal.urls')), url(r'^terminal/', include('terminal.urls', namespace='terminal')),
url(r'^api/users/', include('users.urls', namespace='api-users')),
url(r'^api/assets/', include('assets.urls', namespace='api-assets')),
url(r'^api/perms/', include('perms.urls', namespace='api-perms')),
url(r'^api/audits/', include('audits.urls', namespace='api-audits')),
url(r'^api/terminal/', include('terminal.urls', namespace='api-terminal')),
] ]
......
...@@ -21,7 +21,7 @@ class AssetPermissionViewSet(viewsets.ModelViewSet): ...@@ -21,7 +21,7 @@ class AssetPermissionViewSet(viewsets.ModelViewSet):
def get_queryset(self): def get_queryset(self):
queryset = super(AssetPermissionViewSet, self).get_queryset() queryset = super(AssetPermissionViewSet, self).get_queryset()
user_id = self.request.query_params.get('user', '') user_id = self.request.query_params.get('user', '')
user_group_id = self.request.query_params.get('user-group', '') user_group_id = self.request.query_params.get('user_group', '')
if user_id and user_id.isdigit(): if user_id and user_id.isdigit():
user = get_object_or_404(User, id=int(user_id)) user = get_object_or_404(User, id=int(user_id))
...@@ -165,7 +165,7 @@ class UserGroupGrantedAssetsApi(ListAPIView): ...@@ -165,7 +165,7 @@ class UserGroupGrantedAssetsApi(ListAPIView):
user_group_id = self.kwargs.get('pk', '') user_group_id = self.kwargs.get('pk', '')
if user_group_id: if user_group_id:
user_group = get_object_or_404(User, id=user_group_id) user_group = get_object_or_404(UserGroup, id=user_group_id)
queryset = get_user_group_granted_assets(user_group) queryset = get_user_group_granted_assets(user_group)
else: else:
queryset = [] queryset = []
...@@ -180,7 +180,7 @@ class UserGroupGrantedAssetGroupsApi(ListAPIView): ...@@ -180,7 +180,7 @@ class UserGroupGrantedAssetGroupsApi(ListAPIView):
user_group_id = self.kwargs.get('pk', '') user_group_id = self.kwargs.get('pk', '')
if user_group_id: if user_group_id:
user_group = get_object_or_404(User, id=user_group_id) user_group = get_object_or_404(UserGroup, id=user_group_id)
queryset = get_user_group_granted_asset_groups(user_group) queryset = get_user_group_granted_asset_groups(user_group)
else: else:
queryset = [] queryset = []
......
...@@ -23,21 +23,21 @@ urlpatterns = [ ...@@ -23,21 +23,21 @@ urlpatterns = [
] ]
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register('v1/asset-permissions', api.AssetPermissionViewSet, 'api-asset-permission') router.register('v1/asset-permissions', api.AssetPermissionViewSet, 'asset-permission')
urlpatterns += [ urlpatterns += [
url(r'^v1/user/my/assets/$', api.MyGrantedAssetsApi.as_view(), name='api-my-assets'), url(r'^v1/user/my/assets/$', api.MyGrantedAssetsApi.as_view(), name='my-assets'),
url(r'^v1/user/my/asset-groups/$', api.MyGrantedAssetsGroupsApi.as_view(), name='api-my-asset-groups'), url(r'^v1/user/my/asset-groups/$', api.MyGrantedAssetsGroupsApi.as_view(), name='my-asset-groups'),
url(r'^v1/user/my/asset-group/(?P<pk>[0-9]+)/assets/$', api.MyAssetGroupAssetsApi.as_view(), url(r'^v1/user/my/asset-group/(?P<pk>[0-9]+)/assets/$', api.MyAssetGroupAssetsApi.as_view(),
name='user-my-asset-group-assets'), name='user-my-asset-group-assets'),
# Select user permission of asset and asset group # Select user permission of asset and asset group
url(r'^v1/user/(?P<pk>[0-9]+)/assets/$', api.UserGrantedAssetsApi.as_view(), name='api-user-assets'), url(r'^v1/user/(?P<pk>[0-9]+)/assets/$', api.UserGrantedAssetsApi.as_view(), name='user-assets'),
url(r'^v1/user/(?P<pk>[0-9]+)/asset-groups/$', api.UserGrantedAssetGroupsApi.as_view(), url(r'^v1/user/(?P<pk>[0-9]+)/asset-groups/$', api.UserGrantedAssetGroupsApi.as_view(),
name='api-user-asset-groups'), name='api-user-asset-groups'),
# Select user group permission of asset and asset group # Select user group permission of asset and asset group
url(r'^v1/user-group/(?P<pk>[0-9]+)/assets/$', api.UserGroupGrantedAssetsApi.as_view(), name='api-user-group-assets'), url(r'^v1/user-group/(?P<pk>[0-9]+)/assets/$', api.UserGroupGrantedAssetsApi.as_view(), name='user-group-assets'),
url(r'^v1/user-group/(?P<pk>[0-9]+)/asset-groups/$', api.UserGroupGrantedAssetGroupsApi.as_view(), url(r'^v1/user-group/(?P<pk>[0-9]+)/asset-groups/$', api.UserGroupGrantedAssetGroupsApi.as_view(),
name='api-user-group-asset-groups'), name='api-user-group-asset-groups'),
......
...@@ -265,6 +265,7 @@ $.fn.serializeObject = function() ...@@ -265,6 +265,7 @@ $.fn.serializeObject = function()
}; };
var jumpserver = {}; var jumpserver = {};
jumpserver.checked = false; jumpserver.checked = false;
jumpserver.selected = {};
jumpserver.initDataTable = function (options) { jumpserver.initDataTable = function (options) {
// options = { // options = {
// ele *: $('#dataTable_id'), // ele *: $('#dataTable_id'),
...@@ -283,10 +284,9 @@ jumpserver.initDataTable = function (options) { ...@@ -283,10 +284,9 @@ jumpserver.initDataTable = function (options) {
{ {
targets: 0, targets: 0,
orderable: false, orderable: false,
createdCell: function(td) { createdCell: function(td, cellData) {
$(td).html('<input type="checkbox" class="ipt_check">'); $(td).html('<input type="checkbox" class="text-center ipt_check" id=99991937>'.replace('99991937', cellData));
} }},
},
{className: 'text-center', targets: '_all'} {className: 'text-center', targets: '_all'}
]; ];
columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs; columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs;
...@@ -298,31 +298,7 @@ jumpserver.initDataTable = function (options) { ...@@ -298,31 +298,7 @@ jumpserver.initDataTable = function (options) {
}, },
order: options.order || [[ 1, 'asc' ]], order: options.order || [[ 1, 'asc' ]],
select: options.select || 'multi', select: options.select || 'multi',
buttons: options.buttons || [ buttons: [],
{extend: 'excel',
exportOptions: {
modifier: {
selected: true
}
}
},
{extend: 'pdf',
exportOptions: {
modifier: {
selected: true
}
}
},
{extend: 'print',
customize: function (win){
$(win.document.body).addClass('white-bg');
$(win.document.body).css('font-size', '10px');
$(win.document.body).find('table')
.addClass('compact')
.css('font-size', 'inherit');
}
}
],
columnDefs: columnDefs, columnDefs: columnDefs,
ajax: { ajax: {
url: options.ajax_url , url: options.ajax_url ,
...@@ -334,9 +310,11 @@ jumpserver.initDataTable = function (options) { ...@@ -334,9 +310,11 @@ jumpserver.initDataTable = function (options) {
table.on('select', function(e, dt, type, indexes) { table.on('select', function(e, dt, type, indexes) {
var $node = table[ type ]( indexes ).nodes().to$(); var $node = table[ type ]( indexes ).nodes().to$();
$node.find('input.ipt_check').prop('checked', true); $node.find('input.ipt_check').prop('checked', true);
jumpserver.selected[$node.find('input.ipt_check').prop('id')] = true
}).on('deselect', function(e, dt, type, indexes) { }).on('deselect', function(e, dt, type, indexes) {
var $node = table[ type ]( indexes ).nodes().to$(); var $node = table[ type ]( indexes ).nodes().to$();
$node.find('input.ipt_check').prop('checked', false); $node.find('input.ipt_check').prop('checked', false);
jumpserver.selected[$node.find('input.ipt_check').prop('id')] = false
}).on('draw', function(){ }).on('draw', function(){
$('#op').html(options.op_html || ''); $('#op').html(options.op_html || '');
$('#uc').html(options.uc_html || ''); $('#uc').html(options.uc_html || '');
......
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
$(td).html(btn) $(td).html(btn)
}} }}
], ],
ajax_url: '{% url "perms:api-asset-permission-list" %}?user-group={{ user_group.id }}', ajax_url: '{% url "perms:api-asset-permission-list" %}?user_group={{ user_group.id }}',
columns: [{data: function(){return ""}}, {data: "name" }, {data: "assets" }, {data: "asset_groups"}, columns: [{data: function(){return ""}}, {data: "name" }, {data: "assets" }, {data: "asset_groups"},
{data: "system_users"}, {data: "is_active"}, {data: "id"}] {data: "system_users"}, {data: "is_active"}, {data: "id"}]
}; };
...@@ -165,7 +165,6 @@ ...@@ -165,7 +165,6 @@
id: $this.attr('id'), id: $this.attr('id'),
user_group_id: {{ user_group.id }} user_group_id: {{ user_group.id }}
}; };
console.log(body);
var the_url = "{% url 'perms:revoke-user-group-asset-permission' %}"; var the_url = "{% url 'perms:revoke-user-group-asset-permission' %}";
var success = function () { var success = function () {
$this.closest('tr').remove(); $this.closest('tr').remove();
...@@ -177,6 +176,8 @@ ...@@ -177,6 +176,8 @@
success_message: '{% trans "Revoke Successfully!" %}', success_message: '{% trans "Revoke Successfully!" %}',
success: success success: success
}); });
}).on('click', 'buttons-excel', function () {
console.log('click excel')
}) })
</script> </script>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
} }
}} }}
], ],
ajax_url: '{% url "perms:api-user-assets" pk=user.id %}', ajax_url: '{% url "perms:api-user-group-assets" pk=user_group.id %}',
columns: [{data: function(){return ""}}, {data: "hostname" }, {data: "ip" }, {data: "port"}, columns: [{data: function(){return ""}}, {data: "hostname" }, {data: "ip" }, {data: "port"},
{data: "system_users_join"}, {data: "is_active"}] {data: "system_users_join"}, {data: "is_active"}]
}; };
...@@ -148,8 +148,8 @@ ...@@ -148,8 +148,8 @@
$(td).html(detail_btn.replace('99991937', rowData.id)); $(td).html(detail_btn.replace('99991937', rowData.id));
}} }}
], ],
ajax_url: '{% url "perms:api-user-asset-groups" pk=user.id %}', ajax_url: '{% url "perms:api-user-group-asset-groups" pk=user_group.id %}',
columns: [{data: function(){return ""}}, {data: "name" }, {data: "asset_amount" }] columns: [{data: function(){return ""}}, {data: "name" }, {data: "assets_amount" }]
}; };
jumpserver.initDataTable(options); jumpserver.initDataTable(options);
jumpserver.initDataTable(options2); jumpserver.initDataTable(options2);
......
{% extends '_base_list.html' %} {% extends '_base_list.html' %}
{% load i18n static %} {% load i18n static %}
{% block table_search %}{% endblock %} {% block table_search %}
<div class="html5buttons">
<div class="dt-buttons btn-group">
<a class="btn btn-default buttons-pdf" tabindex="0" href="#">
<span>PDF</span></a>
<a class="btn btn-default buttons-excel" tabindex="0" href="#">
<span>Excel</span>
</a>
</div>
</div>
{% endblock %}
{% block table_container %} {% block table_container %}
<div class="uc pull-left m-l-5 m-r-5"><a href="{% url "users:user-create" %}" class="btn btn-sm btn-primary"> {% trans "Create user" %} </a></div> <div class="uc pull-left m-l-5 m-r-5"><a href="{% url "users:user-create" %}" class="btn btn-sm btn-primary"> {% trans "Create user" %} </a></div>
<div class="uc pull-left"><a href="javascript:void(0);" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#user_import_modal"> {% trans "Import user" %} </a></div> <div class="uc pull-left"><a href="javascript:void(0);" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#user_import_modal"> {% trans "Import user" %} </a></div>
...@@ -72,11 +82,19 @@ $(document).ready(function(){ ...@@ -72,11 +82,19 @@ $(document).ready(function(){
} }
}}], }}],
ajax_url: '{% url "users:api-user-list" %}', ajax_url: '{% url "users:api-user-list" %}',
columns: [{data: function(){return ""}}, {data: "username" }, {data: "name" }, {data: "get_role_display" }, columns: [{data: "id"}, {data: "username" }, {data: "name" }, {data: "get_role_display" },
{data: "groups_display" }, {data: "is_valid" }, {data: "id" }], {data: "groups_display" }, {data: "is_valid" }, {data: "id" }]
op_html: $('#actions').html()
}; };
jumpserver.initDataTable(options); var table = jumpserver.initDataTable(options);
$('.buttons-pdf').click(function () {
var users = [];
var rows = table.rows('.selected').data();
$.each(rows, function (index, obj) {
users.push(obj.id)
})
});
}).on('click', '#btn_bulk_update', function(){ }).on('click', '#btn_bulk_update', function(){
var action = $('#slct_bulk_update').val(); var action = $('#slct_bulk_update').val();
var $data_table = $('#user_list_table').DataTable(); var $data_table = $('#user_list_table').DataTable();
...@@ -216,15 +234,11 @@ $(document).ready(function(){ ...@@ -216,15 +234,11 @@ $(document).ready(function(){
} else { } else {
$('#user_import_modal').modal('hide'); $('#user_import_modal').modal('hide');
var $data_table = $('#user_list_table').DataTable(); var $data_table = $('#user_list_table').DataTable();
toastr.success("{% trans 'Import User Success.' %}") toastr.success("{% trans 'Import User Success.' %}");
$data_table.ajax.reload(); $data_table.ajax.reload();
} }
} }
$form.ajaxSubmit({success: success}); $form.ajaxSubmit({success: success});
}).on('change', '#id_excel', function() {
$(this).siblings('.help-block').remove();
}).on('click', '.ipt_check', function () {
console.log('Hello')
}) })
</script> </script>
{% endblock %} {% endblock %}
......
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import csv
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.contrib.auth import login as auth_login, logout as auth_logout from django.contrib.auth import login as auth_login, logout as auth_logout
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
from django.core.files.storage import default_storage from django.core.files.storage import default_storage
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import reverse, redirect from django.shortcuts import reverse, redirect
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
...@@ -530,3 +531,14 @@ class BulkImportUserView(AdminUserRequiredMixin, JSONResponseMixin, FormView): ...@@ -530,3 +531,14 @@ class BulkImportUserView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
'msg': 'ok' if not errors else '<br />'.join(errors) 'msg': 'ok' if not errors else '<br />'.join(errors)
} }
return self.render_json_response(data) return self.render_json_response(data)
def down_csv(request, xx):
print(xx)
response = HttpResponse(content_type='application/csv')
response['Content-Disposition'] = 'attachment; filename="somefile.csv"'
writer = csv.writer(response)
writer.writerow(['First row', 'Foo', 'Bar', 'Baz'])
writer.writerow(['Second row', 'A', 'B', 'C', '"Testing"', "Here's a quote"])
return response
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment