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
Aug 17, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update user update view
parent
bcae7bea
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
75 additions
and
12 deletions
+75
-12
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
+0
-0
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
(
'
\\
'
,
'/'
)
+
'/'
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
)
apps/media/avatar/广宏伟蓝底.jpg
0 → 100644
View file @
824b1c7f
98.2 KB
apps/static/css/style.css
View file @
824b1c7f
...
...
@@ -4583,3 +4583,4 @@ body.skin-3 {
border-style
:
solid
;
border-width
:
1px
}
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'
,
]
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
=
'启用二次验证'
)
...
...
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 %}
...
...
apps/users/templates/users/user_detail.html
View file @
824b1c7f
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 %}
...
...
apps/users/templatetags/
example_tags
.py
→
apps/users/templatetags/
__init__
.py
View file @
824b1c7f
File moved
apps/users/templatetags/users/example_tags.py
deleted
100644 → 0
View file @
bcae7bea
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
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"
...
...
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