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
824b1c7f
Commit
824b1c7f
authored
8 years ago
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update user update view
parent
bcae7bea
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
161 additions
and
54 deletions
+161
-54
settings.py
apps/jumpserver/settings.py
+2
-1
urls.py
apps/jumpserver/urls.py
+6
-1
广宏伟蓝底.jpg
apps/media/avatar/广宏伟蓝底.jpg
+0
-0
style.css
apps/static/css/style.css
+1
-0
forms.py
apps/users/forms.py
+10
-2
models.py
apps/users/models.py
+1
-1
_user.html
apps/users/templates/users/_user.html
+1
-1
user_detail.html
apps/users/templates/users/user_detail.html
+86
-42
user_edit.html
apps/users/templates/users/user_edit.html
+1
-1
__init__.py
apps/users/templatetags/__init__.py
+0
-0
example_tags.py
apps/users/templatetags/users/example_tags.py
+0
-0
users_tags.py
apps/users/templatetags/users_tags.py
+38
-0
views.py
apps/users/views.py
+15
-5
No files found.
apps/jumpserver/settings.py
View file @
824b1c7f
...
...
@@ -125,10 +125,11 @@ USE_TZ = True
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL
=
'/static/'
MEDIA_URL
=
'/media/'
STATICFILES_DIRS
=
(
os
.
path
.
join
(
BASE_DIR
,
"static"
),
)
AUTH_USER_MODEL
=
'users.User'
BOOTSTRAP_COLUMN_COUNT
=
11
MEDIA_ROOT
=
os
.
path
.
join
(
BASE_DIR
,
'
img
'
)
.
replace
(
'
\\
'
,
'/'
)
+
'/'
MEDIA_ROOT
=
os
.
path
.
join
(
BASE_DIR
,
'
media
'
)
.
replace
(
'
\\
'
,
'/'
)
+
'/'
This diff is collapsed.
Click to expand it.
apps/jumpserver/urls.py
View file @
824b1c7f
...
...
@@ -14,10 +14,15 @@ Including another URLconf
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from
django.conf.urls
import
url
,
include
#from django.contrib import admin
from
django.conf
import
settings
from
django.conf.urls.static
import
static
urlpatterns
=
[
url
(
r'^users/'
,
include
(
'users.urls'
)),
url
(
r'^assets/'
,
include
(
'assets.urls'
)),
# url(r'^admin/', admin.site.urls),
]
if
settings
.
DEBUG
:
urlpatterns
+=
static
(
settings
.
MEDIA_URL
,
document_root
=
settings
.
MEDIA_ROOT
)
This diff is collapsed.
Click to expand it.
apps/media/avatar/广宏伟蓝底.jpg
0 → 100644
View file @
824b1c7f
98.2 KB
This diff is collapsed.
Click to expand it.
apps/static/css/style.css
View file @
824b1c7f
...
...
@@ -4583,3 +4583,4 @@ body.skin-3 {
border-style
:
solid
;
border-width
:
1px
}
This diff is collapsed.
Click to expand it.
apps/users/forms.py
View file @
824b1c7f
...
...
@@ -6,11 +6,11 @@ from django import forms
from
.models
import
User
,
UserGroup
class
UserForm
(
ModelForm
):
class
User
Add
Form
(
ModelForm
):
class
Meta
:
model
=
User
fields
=
[
'username'
,
'name'
,
'email'
,
'groups'
,
'wechat'
,
'avatar'
,
'username'
,
'name'
,
'email'
,
'groups'
,
'wechat'
,
'phone'
,
'enable_2FA'
,
'role'
,
'date_expired'
,
'comment'
,
]
# widgets = {
...
...
@@ -18,3 +18,11 @@ class UserForm(ModelForm):
# }
class
UserUpdateForm
(
ModelForm
):
class
Meta
:
model
=
User
fields
=
[
'name'
,
'email'
,
'groups'
,
'wechat'
,
'avatar'
,
'phone'
,
'enable_2FA'
,
'role'
,
'date_expired'
,
'comment'
,
]
This diff is collapsed.
Click to expand it.
apps/users/models.py
View file @
824b1c7f
...
...
@@ -61,7 +61,7 @@ class User(AbstractUser):
name
=
models
.
CharField
(
max_length
=
20
,
verbose_name
=
'姓名'
,
help_text
=
'* required'
)
email
=
models
.
EmailField
(
max_length
=
30
,
unique
=
True
,
verbose_name
=
'邮件'
,
help_text
=
'* required'
)
groups
=
models
.
ManyToManyField
(
UserGroup
,
verbose_name
=
'用户组'
)
avatar
=
models
.
ImageField
(
upload_to
=
"avatar"
,
verbose_name
=
'头像'
,
blank
=
True
)
avatar
=
models
.
ImageField
(
upload_to
=
"avatar"
,
verbose_name
=
'头像'
)
wechat
=
models
.
CharField
(
max_length
=
30
,
blank
=
True
,
verbose_name
=
'微信'
)
phone
=
models
.
CharField
(
max_length
=
20
,
blank
=
True
,
verbose_name
=
'手机号'
)
enable_2FA
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'启用二次验证'
)
...
...
This diff is collapsed.
Click to expand it.
apps/users/templates/users/_user.html
View file @
824b1c7f
...
...
@@ -26,7 +26,7 @@
</div>
</div>
<div
class=
"ibox-content"
>
<form
method=
"post"
id=
"userForm"
class=
"form-horizontal"
action=
""
>
<form
method=
"post"
id=
"userForm"
class=
"form-horizontal"
action=
""
enctype=
"multipart/form-data"
>
{% csrf_token %}
<h3>
账户
</h3>
{% block username %} {% endblock %}
...
...
This diff is collapsed.
Click to expand it.
apps/users/templates/users/user_detail.html
View file @
824b1c7f
{% extends 'base.html' %}
{% load common_tags %}
{% load users_tags %}
{% load static %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
{#
<div
class=
"ibox-content"
>
#}
{#
<div
class=
"ibox-content"
>
#}
<div
class=
"panel-options"
>
<ul
class=
"nav nav-tabs"
>
<li
class=
"active"
><a
href=
""
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
用户信息
</a></li>
<li
class=
"active"
><a
href=
""
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
用户信息
</a>
</li>
<li><a
href=
""
class=
"text-center"
><i
class=
"fa fa-bar-chart-o"
></i>
用户资产
</a></li>
<li><a
href=
""
class=
"text-center"
><i
class=
"fa fa-bar-chart-o"
></i>
登录记录
</a></li>
<div
class=
""
style=
"float: right"
>
<form
id=
"search_form"
method=
"get"
action=
""
class=
"pull-right mail-search"
>
<div
class=
"input-group"
>
<input
type=
"text"
class=
"form-control input-sm"
id=
"keyword"
name=
"keyword"
value=
"{{ keyword }}"
placeholder=
"Search"
>
<input
type=
"text"
class=
"form-control input-sm"
id=
"keyword"
name=
"keyword"
value=
"{{ keyword }}"
placeholder=
"Search"
>
<div
class=
"input-group-btn"
>
<button
id=
'search_btn'
type=
"submit"
class=
"btn btn-sm btn-primary"
>
搜索
...
...
@@ -55,60 +58,60 @@
<tbody>
<tr>
<td
colspan=
"2"
>
<img
src=
"{% static "
img
/
root
.
png
"
%}"
class=
"img-circle"
,
width=
"64"
height=
"64"
>
<img
src=
"{{ user | user_avatar_url }}"
class=
"img-circle"
width=
"64"
height=
"64"
>
</td>
</tr>
<tr>
<td
width=
"20%"
>
<b>
姓名:
</b>
</td>
<td>
{{ user.name }}
</td>
<td
width=
"20%"
>
姓名:
</td>
<td>
<b>
{{ user.name }}
</b>
</td>
</tr>
<tr>
<td>
<b>
用户名:
</b>
</td>
<td>
{{ user.username }}
</td>
<td>
用户名:
</td>
<td>
<b>
{{ user.username }}
</b>
</td>
</tr>
<tr>
<td>
<b>
邮件:
</b>
</td>
<td>
{{ user.email }}
</td>
<td>
邮件:
</td>
<td>
<b>
{{ user.email }}
</b>
</td>
</tr>
{% if user.phone %}
<tr>
<td><b>
手机:
</b>
</td>
<td>
{{ user.phone }}
</td>
<td>
手机:
</td>
<td><b>
{{ user.phone }}
</b>
</td>
</tr>
{% endif %}
{% if user.wechat %}
<tr>
<td><b>
微信:
</b>
</td>
<td>
{{ user.wechat }}
</td>
<td>
微信:
</td>
<td><b>
{{ user.wechat }}
</b>
</td>
</tr>
{% endif %}
<tr>
<td>
<b>
角色:
</b>
</td>
<td>
{{ user.role.name }}
</td>
<td>
角色:
</td>
<td>
<b>
{{ user.role.name }}
</b>
</td>
</tr>
<tr>
<td>
<b>
有效期:
</b>
</td>
<td>
{{ user.date_expired|date:"Y-m-j H:i:s" }}
</td>
<td>
有效期:
</td>
<td>
<b>
{{ user.date_expired|date:"Y-m-j H:i:s" }}
</b>
</td>
</tr>
<tr>
<td>
<b>
创建者:
</b>
</td>
<td>
{{ user.created_by }}
</td>
<td>
创建者:
</td>
<td>
<b>
{{ user.created_by }}
</b>
</td>
</tr>
<tr>
<td>
<b>
创建日期:
</b>
</td>
<td>
{{ user.date_joined|date:"Y-m-j H:i:s" }}
</td>
<td>
创建日期:
</td>
<td>
<b>
{{ user.date_joined|date:"Y-m-j H:i:s" }}
</b>
</td>
</tr>
<tr>
<td>
<b>
最后登录:
</b>
</td>
<td>
{{ user.last_login|date:"Y-m-j H:i:s" }}
</td>
<td>
最后登录:
</td>
<td>
<b>
{{ user.last_login|date:"Y-m-j H:i:s" }}
</b>
</td>
</tr>
<tr>
<td>
<b>
描述:
</b>
</td>
<td>
{{ user.comment }}
</td>
<td>
描述:
</td>
<td>
<b>
{{ user.comment }}
</b>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
...
...
@@ -119,21 +122,54 @@
<div
class=
"ibox-tools"
>
</div>
</div>
<div
class=
"ibox-content primary-panel"
>
<div
class=
"ibox-content primary-panel"
>
<table
class=
"table"
>
<tbody>
<tr>
<td
colspan=
"2"
>
<img
src=
"{% static "
img
/
root
.
png
"
%}"
class=
"img-circle"
width=
"64"
height=
"64"
>
</td>
<td
width=
"50%"
>
Active:
</td>
<td><span
style=
"float: right"
>
<div
class=
"switch"
>
<div
class=
"onoffswitch"
>
<input
type=
"checkbox"
checked
class=
"onoffswitch-checkbox"
id=
"example1"
>
<label
class=
"onoffswitch-label"
for=
"example1"
>
<span
class=
"onoffswitch-inner"
></span>
<span
class=
"onoffswitch-switch"
></span>
</label>
</div>
</div>
</span></td>
</tr>
<tr>
<td
width=
"20%"
><b>
姓名:
</b></td>
<td>
{{ user.name }}
</td>
<td>
二次验证:
</td>
<td><span
style=
"float: right"
>
<div
class=
"switch"
>
<div
class=
"onoffswitch"
>
<input
type=
"checkbox"
class=
"onoffswitch-checkbox"
id=
"example2"
>
<label
class=
"onoffswitch-label"
for=
"example2"
>
<span
class=
"onoffswitch-inner"
></span>
<span
class=
"onoffswitch-switch"
></span>
</label>
</div>
</div>
</span></td>
</tr>
<tr>
<td><b>
描述:
</b></td>
<td>
{{ user.comment }}
</td>
<td>
重置密码:
</td>
<td>
<span
style=
"float: right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
>
重置
</button>
</span>
</td>
</tr>
<tr>
<td
class=
"no-borders"
>
重置密钥:
</td>
<td
class=
"no-borders"
>
<span
style=
"float: right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px;"
>
重置
</button>
</span>
</td>
</tr>
</tbody>
</table>
...
...
@@ -150,16 +186,17 @@
<table
class=
"table"
>
<tbody>
<tr>
<td
colspan=
"2"
>
<img
src=
"{% static "
img
/
root
.
png
"
%}"
class=
"img-circle"
,
width=
"64"
height=
"64"
>
<td>
</td>
</tr>
<tr>
<td
width=
"20%"
>
<b>
姓名:
</b>
</td>
<td
width=
"20%"
>
姓名:
</td>
<td>
{{ user.name }}
</td>
</tr>
<tr>
<td>
<b>
描述:
</b>
</td>
<td>
描述:
</td>
<td>
{{ user.comment }}
</td>
</tr>
</tbody>
...
...
@@ -172,6 +209,12 @@
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block custom_footer_js %}
<script>
$
(
document
).
ready
(
function
()
{
})
</script>
{% endblock %}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
apps/users/templates/users/user_edit.html
View file @
824b1c7f
...
...
@@ -3,7 +3,7 @@
<div
class=
"form-group"
>
<label
for=
"{{ form.username.id_for_label }}"
class=
"col-sm-2 control-label"
>
用户名
</label>
<div
class=
"col-sm-9 controls"
>
<input
id=
"{{ form.username.id_for_label }}"
name=
"username"
type=
"text"
value=
"{{
form.username.valu
e }}"
readonly
class=
"form-control"
>
<input
id=
"{{ form.username.id_for_label }}"
name=
"username"
type=
"text"
value=
"{{
user.usernam
e }}"
readonly
class=
"form-control"
>
</div>
</div>
{% endblock %}
...
...
This diff is collapsed.
Click to expand it.
apps/users/templatetags/
example_tags
.py
→
apps/users/templatetags/
__init__
.py
View file @
824b1c7f
File moved
This diff is collapsed.
Click to expand it.
apps/users/templatetags/users/example_tags.py
deleted
100644 → 0
View file @
bcae7bea
This diff is collapsed.
Click to expand it.
apps/users/templatetags/users_tags.py
0 → 100644
View file @
824b1c7f
# ~*~ coding: utf-8 ~*~
import
urllib
import
hashlib
from
django
import
template
from
django.utils
import
timezone
from
django.conf
import
settings
from
django.conf.urls.static
import
static
register
=
template
.
Library
()
@register.filter
def
join_queryset_attr
(
queryset
,
attr
,
delimiter
=
', '
):
return
delimiter
.
join
([
getattr
(
obj
,
attr
,
''
)
for
obj
in
queryset
])
@register.filter
def
is_expired
(
datetime
):
if
datetime
>
timezone
.
now
():
return
False
else
:
return
True
@register.filter
def
user_avatar_url
(
user
,
size
=
64
):
if
user
.
avatar
:
return
user
.
avatar
.
url
gravatar_url
=
"https://www.gravatar.com/avatar/"
\
+
hashlib
.
md5
(
user
.
email
.
lower
())
.
hexdigest
()
+
"?"
gravatar_url
+=
urllib
.
urlencode
({
'd'
:
'identicon'
,
's'
:
str
(
size
)})
return
gravatar_url
This diff is collapsed.
Click to expand it.
apps/users/views.py
View file @
824b1c7f
...
...
@@ -7,7 +7,7 @@ from django.views.generic.edit import CreateView, DeleteView, UpdateView
from
django.views.generic.detail
import
DetailView
from
.models
import
User
,
UserGroup
,
Role
from
.forms
import
UserForm
from
.forms
import
User
AddForm
,
UserUpdate
Form
class
UserListView
(
ListView
):
...
...
@@ -33,7 +33,7 @@ class UserListView(ListView):
class
UserAddView
(
CreateView
):
model
=
User
form_class
=
UserForm
form_class
=
User
Add
Form
initial
=
{
'role'
:
Role
.
objects
.
get
(
name
=
'User'
)}
template_name
=
'users/user_add.html'
success_url
=
reverse_lazy
(
'users:user-list'
)
...
...
@@ -52,17 +52,27 @@ class UserAddView(CreateView):
class
UserUpdateView
(
UpdateView
):
model
=
User
form_class
=
UserForm
form_class
=
User
Update
Form
template_name
=
'users/user_edit.html'
context_object_name
=
'user'
success_url
=
reverse_lazy
(
'users:user-list'
)
def
form_valid
(
self
,
form
):
user
=
form
.
save
()
username
=
self
.
object
.
username
user
=
form
.
save
(
commit
=
False
)
user
.
username
=
username
user
.
save
()
password
=
self
.
request
.
POST
.
get
(
'password'
,
''
)
if
password
:
user
.
set_password
(
password
)
return
super
(
UserUpdateView
,
self
)
.
form_valid
(
form
)
def
form_invalid
(
self
,
form
):
print
(
self
.
request
.
FILES
)
print
(
form
[
'avatar'
]
.
value
())
print
(
form
.
errors
)
return
super
(
UserUpdateView
,
self
)
.
form_invalid
(
form
)
class
UserDeleteView
(
DeleteView
):
model
=
User
...
...
@@ -70,7 +80,7 @@ class UserDeleteView(DeleteView):
template_name
=
'users/user_delete_confirm.html'
class
UserDetailView
(
De
lete
View
):
class
UserDetailView
(
De
tail
View
):
model
=
User
template_name
=
'users/user_detail.html'
context_object_name
=
"user"
...
...
This diff is collapsed.
Click to expand it.
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