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
65461a09
Commit
65461a09
authored
Sep 19, 2016
by
xiaokong1937@gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user-group edit implement
parent
6c7e5104
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
28 deletions
+42
-28
user_group_create.html
apps/users/templates/users/user_group_create.html
+11
-23
views.py
apps/users/views.py
+31
-5
No files found.
apps/users/templates/users/user_group_create.html
View file @
65461a09
...
@@ -13,18 +13,7 @@
...
@@ -13,18 +13,7 @@
<div
class=
"col-sm-12"
>
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<div
class=
"ibox-title"
>
<h5>
{% trans 'Create user group' %}
</h5>
<h5>
{{ action }}
</h5>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
</div>
<div
class=
"ibox-content"
>
<div
class=
"ibox-content"
>
<form
method=
"post"
class=
"form-horizontal"
action=
""
>
<form
method=
"post"
class=
"form-horizontal"
action=
""
>
...
@@ -32,9 +21,9 @@
...
@@ -32,9 +21,9 @@
{{ form.name|bootstrap_horizontal }}
{{ form.name|bootstrap_horizontal }}
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"users"
class=
"col-sm-2 control-label"
>
用户
</label>
<label
for=
"users"
class=
"col-sm-2 control-label"
>
{% trans 'Users' %}
</label>
<div
class=
"col-sm-9"
>
<div
class=
"col-sm-9"
>
<select
name=
"users"
id=
"users"
data-placeholder=
"
选择用户
"
class=
"select2 form-control m-b"
multiple
tabindex=
"2"
>
<select
name=
"users"
id=
"users"
data-placeholder=
"
{% trans 'Select User' %}
"
class=
"select2 form-control m-b"
multiple
tabindex=
"2"
>
{% for user in users %}
{% for user in users %}
<option
value=
"{{ user.id }}"
>
{{ user.name }}
</option>
<option
value=
"{{ user.id }}"
>
{{ user.name }}
</option>
{% endfor %}
{% endfor %}
...
@@ -46,8 +35,8 @@
...
@@ -46,8 +35,8 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
<button
class=
"btn btn-white"
type=
"reset"
>
取消
</button>
<button
class=
"btn btn-white"
type=
"reset"
>
{% trans 'Cancel' %}
</button>
<button
id=
"submit_button"
class=
"btn btn-primary"
type=
"submit"
>
确认保存
</button>
<button
id=
"submit_button"
class=
"btn btn-primary"
type=
"submit"
>
{% trans 'confirm' %}
</button>
</div>
</div>
</div>
</div>
</form>
</form>
...
@@ -58,9 +47,9 @@
...
@@ -58,9 +47,9 @@
</div>
</div>
{% endblock %}
{% endblock %}
{% block custom_foot_js %}
{% block custom_foot_js %}
<script>
<script>
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
$
(
'.select2'
).
select2
().
val
([{{
group_users
}}]).
trigger
(
"change"
);
})
})
</script>
</script>
{% endblock %}
{% endblock %}
\ No newline at end of file
apps/users/views.py
View file @
65461a09
...
@@ -9,7 +9,7 @@ from django.contrib.messages.views import SuccessMessageMixin
...
@@ -9,7 +9,7 @@ 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.db.models
import
Q
from
django.db.models
import
Q
from
django.http
import
HttpResponseRedirect
from
django.http
import
HttpResponseRedirect
from
django.shortcuts
import
get_object_or_404
,
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
_
from
django.urls
import
reverse_lazy
from
django.urls
import
reverse_lazy
...
@@ -21,6 +21,7 @@ from django.views.generic.list import ListView
...
@@ -21,6 +21,7 @@ from django.views.generic.list import ListView
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
UpdateView
,
FormView
,
SingleObjectMixin
,
\
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
UpdateView
,
FormView
,
SingleObjectMixin
,
\
FormMixin
FormMixin
from
django.views.generic.detail
import
DetailView
from
django.views.generic.detail
import
DetailView
from
formtools.wizard.views
import
SessionWizardView
from
formtools.wizard.views
import
SessionWizardView
from
common.utils
import
get_object_or_none
,
get_logger
from
common.utils
import
get_object_or_none
,
get_logger
...
@@ -223,15 +224,40 @@ class UserGroupCreateView(AdminUserRequiredMixin, CreateView):
...
@@ -223,15 +224,40 @@ class UserGroupCreateView(AdminUserRequiredMixin, CreateView):
def
form_valid
(
self
,
form
):
def
form_valid
(
self
,
form
):
user_group
=
form
.
save
()
user_group
=
form
.
save
()
users_id_list
=
self
.
request
.
POST
.
getlist
(
'users'
,
[])
users_id_list
=
self
.
request
.
POST
.
getlist
(
'users'
,
[])
users
=
[
get_object_or_404
(
User
,
id
=
user_id
)
for
user_id
in
users_id_list
]
users
=
User
.
objects
.
filter
(
id__in
=
users_id_list
)
user_group
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
user_group
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
user_group
.
users
.
add
(
*
tuple
(
users
)
)
user_group
.
users
.
add
(
*
users
)
user_group
.
save
()
user_group
.
save
()
return
super
(
UserGroupCreateView
,
self
)
.
form_valid
(
form
)
return
super
(
UserGroupCreateView
,
self
)
.
form_valid
(
form
)
class
UserGroupUpdateView
(
UpdateView
):
class
UserGroupUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
pass
model
=
UserGroup
form_class
=
UserGroupForm
template_name
=
'users/user_group_create.html'
success_url
=
reverse_lazy
(
'users:user-group-list'
)
def
get_context_data
(
self
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
context
=
super
(
UserGroupUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
users
=
User
.
objects
.
all
()
group_users
=
","
.
join
([
str
(
u
.
id
)
for
u
in
self
.
object
.
users
.
all
()])
context
.
update
({
'app'
:
_
(
'Users'
),
'action'
:
_
(
'Update User Group'
),
'users'
:
users
,
'group_users'
:
group_users
})
return
context
def
form_valid
(
self
,
form
):
user_group
=
form
.
save
()
users_id_list
=
self
.
request
.
POST
.
getlist
(
'users'
,
[])
users
=
User
.
objects
.
filter
(
id__in
=
users_id_list
)
user_group
.
users
.
clear
()
user_group
.
users
.
add
(
*
users
)
user_group
.
save
()
return
super
(
UserGroupUpdateView
,
self
)
.
form_valid
(
form
)
class
UserGroupDetailView
(
AdminUserRequiredMixin
,
DetailView
):
class
UserGroupDetailView
(
AdminUserRequiredMixin
,
DetailView
):
...
...
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