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
6e46a17d
Commit
6e46a17d
authored
Aug 19, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Useradd group change
parent
e48f3639
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
73 additions
and
22 deletions
+73
-22
forms.py
apps/users/forms.py
+21
-3
models.py
apps/users/models.py
+1
-1
_user.html
apps/users/templates/users/_user.html
+16
-15
user_list.html
apps/users/templates/users/user_list.html
+1
-1
usergroup_add.html
apps/users/templates/users/usergroup_add.html
+0
-1
usergroup_list.html
apps/users/templates/users/usergroup_list.html
+1
-1
hardcopy.0
hardcopy.0
+33
-0
No files found.
apps/users/forms.py
View file @
6e46a17d
...
@@ -13,9 +13,17 @@ class UserAddForm(ModelForm):
...
@@ -13,9 +13,17 @@ class UserAddForm(ModelForm):
'username'
,
'name'
,
'email'
,
'groups'
,
'wechat'
,
'username'
,
'name'
,
'email'
,
'groups'
,
'wechat'
,
'phone'
,
'enable_2FA'
,
'role'
,
'date_expired'
,
'comment'
,
'phone'
,
'enable_2FA'
,
'role'
,
'date_expired'
,
'comment'
,
]
]
# widgets = {
# 'groups': forms.SelectMultiple(attrs={'class': 'chosen-select'})
help_texts
=
{
# }
'username'
:
'* required'
,
'name'
:
'* required'
,
'email'
:
'* required'
,
'groups'
:
'* required'
}
widgets
=
{
'groups'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'chosen-select'
,
'data-placeholder'
:
'请选择用户组'
})
}
class
UserUpdateForm
(
ModelForm
):
class
UserUpdateForm
(
ModelForm
):
...
@@ -26,6 +34,13 @@ class UserUpdateForm(ModelForm):
...
@@ -26,6 +34,13 @@ class UserUpdateForm(ModelForm):
'phone'
,
'enable_2FA'
,
'role'
,
'date_expired'
,
'comment'
,
'phone'
,
'enable_2FA'
,
'role'
,
'date_expired'
,
'comment'
,
]
]
help_texts
=
{
'username'
:
'* required'
,
'name'
:
'* required'
,
'email'
:
'* required'
,
'groups'
:
'* required'
}
class
UserGroupForm
(
ModelForm
):
class
UserGroupForm
(
ModelForm
):
class
Meta
:
class
Meta
:
...
@@ -33,3 +48,6 @@ class UserGroupForm(ModelForm):
...
@@ -33,3 +48,6 @@ class UserGroupForm(ModelForm):
fields
=
[
fields
=
[
'name'
,
'comment'
,
'name'
,
'comment'
,
]
]
help_texts
=
{
'name'
:
'* required'
}
apps/users/models.py
View file @
6e46a17d
...
@@ -75,7 +75,7 @@ class UserGroup(models.Model):
...
@@ -75,7 +75,7 @@ class UserGroup(models.Model):
class
User
(
AbstractUser
):
class
User
(
AbstractUser
):
username
=
models
.
CharField
(
max_length
=
20
,
unique
=
True
,
verbose_name
=
'用户名'
,
help_text
=
'* required'
)
username
=
models
.
CharField
(
max_length
=
20
,
unique
=
True
,
verbose_name
=
'用户名'
)
name
=
models
.
CharField
(
max_length
=
20
,
verbose_name
=
'姓名'
,
help_text
=
'* required'
)
name
=
models
.
CharField
(
max_length
=
20
,
verbose_name
=
'姓名'
,
help_text
=
'* required'
)
email
=
models
.
EmailField
(
max_length
=
30
,
unique
=
True
,
verbose_name
=
'邮件'
,
help_text
=
'* required'
)
email
=
models
.
EmailField
(
max_length
=
30
,
unique
=
True
,
verbose_name
=
'邮件'
,
help_text
=
'* required'
)
groups
=
models
.
ManyToManyField
(
UserGroup
,
verbose_name
=
'用户组'
,
help_text
=
'* required'
)
groups
=
models
.
ManyToManyField
(
UserGroup
,
verbose_name
=
'用户组'
,
help_text
=
'* required'
)
...
...
apps/users/templates/users/_user.html
View file @
6e46a17d
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
{% load bootstrap %}
{% load bootstrap %}
{% block custom_head_css_js %}
{% block custom_head_css_js %}
<link
href=
"{% static "
css
/
plugins
/
chosen
/
chosen
.
css
"
%}"
rel=
"stylesheet"
>
<link
href=
"{% static "
css
/
plugins
/
chosen
/
chosen
.
css
"
%}"
rel=
"stylesheet"
>
<script
href=
"{% static "
js
/
plugins
/
chosen
/
chosen
.
jquery
.
min
.
js
"
%}"
type=
"text/javascript
"
></script>
<script
src=
"{% static "
js
/
plugins
/
chosen
/
chosen
.
jquery
.
min
.
js
"
%}
"
></script>
{% endblock %}
{% endblock %}
{% block content %}
{% block content %}
...
@@ -67,18 +67,18 @@
...
@@ -67,18 +67,18 @@
</div>
</div>
{% endblock %}
{% endblock %}
{% block custom_foot_js %}
{% block custom_foot_js %}
<script
type=
"text/javascript"
>
<script
>
{
#
$
(
document
).
ready
(
function
()
{
#
}
$
(
document
).
ready
(
function
()
{
{
#
var
config
=
{
#
}
var
config
=
{
{
#
'.chosen-select'
:
{},
#
}
'.chosen-select'
:
{},
{
#
'.chosen-select-deselect'
:
{
allow_single_deselect
:
true
},
#
}
'.chosen-select-deselect'
:
{
allow_single_deselect
:
true
},
{
#
'.chosen-select-no-single'
:
{
disable_search_threshold
:
10
},
#
}
'.chosen-select-no-single'
:
{
disable_search_threshold
:
10
},
{
#
'.chosen-select-no-results'
:
{
no_results_text
:
'Oops, nothing found!'
},
#
}
'.chosen-select-no-results'
:
{
no_results_text
:
'Oops, nothing found!'
},
{
#
'.chosen-select-width'
:
{
width
:
"95%"
}
#
}
'.chosen-select-width'
:
{
width
:
"95%"
}
{
#
};
#
}
};
{
#
for
(
var
selector
in
config
)
{
#
}
for
(
var
selector
in
config
)
{
{
#
$
(
selector
).
chosen
(
config
[
selector
]);
#
}
$
(
selector
).
chosen
(
config
[
selector
]);
{
#
}
#
}
}
{
#
})
#
}
})
</script>
</script>
{% endblock %}
{% endblock %}
\ No newline at end of file
apps/users/templates/users/user_list.html
View file @
6e46a17d
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
<div
class=
""
>
<div
class=
""
>
<a
href=
"{% url 'users:user-add' %}"
class=
"btn btn-sm btn-primary "
>
添加用户
</a>
<a
href=
"{% url 'users:user-add' %}"
class=
"btn btn-sm btn-primary "
>
添加用户
</a>
<a
id=
"del_btn"
class=
"btn btn-sm btn-danger "
>
删除所选
</a>
<a
id=
"del_btn"
class=
"btn btn-sm btn-danger "
>
删除所选
</a>
<form
id=
"search_form"
method=
"get"
action=
"
{% url 'users:user-list' %}
"
class=
"pull-right mail-search"
>
<form
id=
"search_form"
method=
"get"
action=
""
class=
"pull-right mail-search"
>
<div
class=
"input-group"
>
<div
class=
"input-group"
>
<input
type=
"text"
class=
"form-control input-sm"
name=
"keyword"
placeholder=
"用户名或姓名"
value=
"{{ keyword }}"
>
<input
type=
"text"
class=
"form-control input-sm"
name=
"keyword"
placeholder=
"用户名或姓名"
value=
"{{ keyword }}"
>
<div
class=
"input-group-btn"
>
<div
class=
"input-group-btn"
>
...
...
apps/users/templates/users/usergroup_add.html
View file @
6e46a17d
...
@@ -38,7 +38,6 @@
...
@@ -38,7 +38,6 @@
<option
value=
"{{ user.id }}"
>
{{ user.name }}
</option>
<option
value=
"{{ user.id }}"
>
{{ user.name }}
</option>
{% endfor %}
{% endfor %}
</select>
</select>
<span
class=
"help-block m-b-none"
>
用户和用户组必选一个
</span>
</div>
</div>
</div>
</div>
...
...
apps/users/templates/users/usergroup_list.html
View file @
6e46a17d
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
<div
class=
""
>
<div
class=
""
>
<a
href=
"{% url 'users:usergroup-add' %}"
class=
"btn btn-sm btn-primary "
>
添加用户组
</a>
<a
href=
"{% url 'users:usergroup-add' %}"
class=
"btn btn-sm btn-primary "
>
添加用户组
</a>
<a
id=
"del_btn"
class=
"btn btn-sm btn-danger "
>
删除所选
</a>
<a
id=
"del_btn"
class=
"btn btn-sm btn-danger "
>
删除所选
</a>
<form
id=
"search_form"
method=
"get"
action=
"
{% url 'users:user-list' %}
"
class=
"pull-right mail-search"
>
<form
id=
"search_form"
method=
"get"
action=
""
class=
"pull-right mail-search"
>
<div
class=
"input-group"
>
<div
class=
"input-group"
>
<input
type=
"text"
class=
"form-control input-sm"
name=
"keyword"
placeholder=
"名称"
value=
"{{ keyword }}"
>
<input
type=
"text"
class=
"form-control input-sm"
name=
"keyword"
placeholder=
"名称"
value=
"{{ keyword }}"
>
<div
class=
"input-group-btn"
>
<div
class=
"input-group-btn"
>
...
...
hardcopy.0
0 → 100644
View file @
6e46a17d
58
/root/env2.7/lib/python2.7/site-packages/django/db/models/fields/__init__.pyc in get_prep_value(self, value)
944 if value is None:
945 return None
--> 946 return int(value)
947
948 def contribute_to_class(self, cls, name, **kwargs):
TypeError: int() argument must be a string or a number, not 'QuerySet'
In [6]: group.user_set.update(users)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-94520763e8e7> in <module>()
----> 1 group.user_set.update(users)
/root/env2.7/lib/python2.7/site-packages/django/db/models/manager.pyc in manager_method(self, *args, **kwargs)
83 def create_method(name, method):
84 def manager_method(self, *args, **kwargs):
---> 85 return getattr(self.get_queryset(), name)(*args, **kwargs)
86 manager_method.__name__ = method.__name__
87 manager_method.__doc__ = method.__doc__
TypeError: update() takes exactly 1 argument (2 given)
In [7]: users
Out[7]: <QuerySet [<User: christina86>, <User: tina71>, <User: emily71>, <User: tammy66>, <User: sarah66>, <User: linda75>, <User: ev
elyn88>, <User: mildred72>, <User: sharon93>, <User: christina88>, <User: heather80>, <User: amy80>, <User: julia81>, <User: sarah89>
, <User: phillip74>, <User: kimberly74>, <User: ann73>, <User: helen63>, <User: joyce77>, <User: debra67>, '...(remaining elements tr
uncated)...']>
In [8]: group.user_set
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