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
74cdd2d0
Commit
74cdd2d0
authored
Sep 26, 2016
by
xiaokong1937@gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user list groups bulk update
parent
15dcc760
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
2 deletions
+28
-2
models.py
apps/users/models.py
+1
-0
serializers.py
apps/users/serializers.py
+1
-0
user_list.html
apps/users/templates/users/user_list.html
+26
-2
No files found.
apps/users/models.py
View file @
74cdd2d0
...
...
@@ -156,6 +156,7 @@ class User(AbstractUser):
super
(
User
,
self
)
.
save
(
*
args
,
**
kwargs
)
# Add the current user to the default group.
if
not
self
.
groups
.
count
():
group
=
UserGroup
.
initial
()
self
.
groups
.
add
(
group
)
...
...
apps/users/serializers.py
View file @
74cdd2d0
...
...
@@ -73,6 +73,7 @@ class UserPKUpdateSerializer(serializers.ModelSerializer):
class
UserBulkUpdateSerializer
(
BulkSerializerMixin
,
serializers
.
ModelSerializer
):
group_display
=
serializers
.
SerializerMethodField
()
active_display
=
serializers
.
SerializerMethodField
()
groups
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
UserGroup
.
objects
.
all
())
class
Meta
(
object
):
model
=
User
...
...
apps/users/templates/users/user_list.html
View file @
74cdd2d0
...
...
@@ -80,7 +80,8 @@ $(document).ready(function(){
{
targets
:
0
,
orderable
:
false
,
createdCell
:
function
(
td
)
{
$
(
td
).
html
(
'<div class="checkbox checkbox-success"><input type="checkbox" class="ipt_check"><label></label></div>'
);
}},
}
},
{
className
:
'text-center'
,
targets
:
[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
]},
{
targets
:
7
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
...
...
@@ -247,7 +248,30 @@ $(document).ready(function(){
if
(
json_data
.
groups
!=
undefined
)
{
body
.
groups
=
json_data
.
groups
;
}
console
.
log
(
body
)
if
(
typeof
body
.
groups
===
'string'
)
{
body
.
groups
=
[
parseInt
(
body
.
groups
)]
}
else
if
(
typeof
body
.
groups
===
'array'
)
{
new_groups
=
body
.
groups
.
map
(
Number
);
body
.
groups
=
new_groups
;
}
var
$data_table
=
$
(
'#user_list_table'
).
DataTable
()
var
post_list
=
[];
$data_table
.
rows
({
selected
:
true
}).
every
(
function
(){
var
content
=
Object
.
assign
({
id
:
this
.
data
().
id
},
body
);
post_list
.
push
(
content
);
});
if
(
post_list
===
[])
{
return
false
;
};
var
the_url
=
"{% url 'users:user-bulk-update-api' %}"
;
var
success
=
function
()
{
var
msg
=
"{% trans 'The selected users has been updated successfully.' %}"
;
swal
(
"{% trans 'User Updated' %}"
,
msg
,
"success"
);
$
(
'#user_list_table'
).
DataTable
().
ajax
.
reload
();
jumpserver
.
checked
=
false
;
}
APIUpdateAttr
({
url
:
the_url
,
method
:
'PATCH'
,
body
:
JSON
.
stringify
(
post_list
),
success
:
success
});
$
(
'#user_bulk_update_modal'
).
modal
(
'hide'
);
})
</script>
{% endblock %}
...
...
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