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
02b5483d
Commit
02b5483d
authored
8 years ago
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update add->create edit->update and assetgrou->asset-grou etc format
parent
b8c10a03
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
94 additions
and
128 deletions
+94
-128
forms.py
apps/assets/forms.py
+5
-3
0001_initial.py
apps/assets/migrations/0001_initial.py
+0
-0
0002_auto_20160821_1757.py
apps/assets/migrations/0002_auto_20160821_1757.py
+0
-20
0003_auto_20160821_1759.py
apps/assets/migrations/0003_auto_20160821_1759.py
+0
-20
models.py
apps/assets/models.py
+1
-1
asset_create.html
apps/assets/templates/assets/asset_create.html
+0
-0
asset_group_create.html
apps/assets/templates/assets/asset_group_create.html
+0
-0
asset_group_list.html
apps/assets/templates/assets/asset_group_list.html
+11
-13
asset_list.html
apps/assets/templates/assets/asset_list.html
+2
-1
urls.py
apps/assets/urls.py
+7
-7
views.py
apps/assets/views.py
+18
-14
_nav.html
apps/templates/_nav.html
+2
-2
_user_profile.html
apps/templates/_user_profile.html
+1
-1
forms.py
apps/users/forms.py
+1
-1
models.py
apps/users/models.py
+1
-1
serializers.py
apps/users/serializers.py
+1
-1
user_create.html
apps/users/templates/users/user_create.html
+0
-0
user_group_create.html
apps/users/templates/users/user_group_create.html
+0
-0
user_group_list.html
apps/users/templates/users/user_group_list.html
+10
-10
user_list.html
apps/users/templates/users/user_list.html
+2
-2
user_update.html
apps/users/templates/users/user_update.html
+0
-0
test_views.py
apps/users/tests/test_views.py
+1
-1
urls.py
apps/users/urls.py
+9
-9
views.py
apps/users/views.py
+19
-19
python_style_guide.md
docs/python_style_guide.md
+3
-2
No files found.
apps/assets/forms.py
View file @
02b5483d
...
...
@@ -22,9 +22,11 @@ class AssetForm(forms.ModelForm):
class
AssetGroupForm
(
forms
.
ModelForm
):
assets
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Asset
.
objects
.
all
(),
widget
=
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select assets'
)}))
label
=
_
(
'Asset'
),
required
=
False
,
widget
=
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select assets'
)})
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
if
kwargs
.
get
(
'instance'
):
...
...
This diff is collapsed.
Click to expand it.
apps/assets/migrations/0001_initial.py
View file @
02b5483d
This diff is collapsed.
Click to expand it.
apps/assets/migrations/0002_auto_20160821_1757.py
deleted
100644 → 0
View file @
b8c10a03
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-21 09:57
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'assets'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'asset'
,
name
=
'cabinet_pos'
,
field
=
models
.
IntegerField
(
blank
=
True
,
max_length
=
4
,
verbose_name
=
'
\u673a\u5668\u4f4d\u7f6e
'
),
),
]
This diff is collapsed.
Click to expand it.
apps/assets/migrations/0003_auto_20160821_1759.py
deleted
100644 → 0
View file @
b8c10a03
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-21 09:59
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'assets'
,
'0002_auto_20160821_1757'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'asset'
,
name
=
'cabinet_pos'
,
field
=
models
.
IntegerField
(
blank
=
True
,
max_length
=
4
,
null
=
True
,
verbose_name
=
'
\u673a\u5668\u4f4d\u7f6e
'
),
),
]
This diff is collapsed.
Click to expand it.
apps/assets/models.py
View file @
02b5483d
...
...
@@ -14,7 +14,7 @@ class AssetGroup(models.Model):
return
self
.
name
class
Meta
:
db_table
=
'assetgroup'
db_table
=
'asset
_
group'
class
IDC
(
models
.
Model
):
...
...
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/asset_
add
.html
→
apps/assets/templates/assets/asset_
create
.html
View file @
02b5483d
File moved
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/asset
group_add
.html
→
apps/assets/templates/assets/asset
_group_create
.html
View file @
02b5483d
File moved
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/assetgroup_list.html
→
apps/assets/templates/assets/asset
_
group_list.html
View file @
02b5483d
...
...
@@ -2,35 +2,35 @@
{% load i18n %}
{% load common_tags %}
{% block content_left_head %}
<a
href=
"{% url 'assets:asset
group-add
' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create asset group" %}
</a>
<a
href=
"{% url 'assets:asset
-group-create
' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create asset group" %}
</a>
{% endblock %}
{% block table_head %}
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
onclick=
"checkAll('check_all', 'checked')"
>
</th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:assetgroup-list' %}?sort=name"
>
{% trans 'Name' %}
</a></th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset
-
group-list' %}?sort=name"
>
{% trans 'Name' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:assetgroup-list' %}?sort=date_expired"
>
{% trans 'Comment' %}
</a></th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset
-
group-list' %}?sort=date_expired"
>
{% trans 'Comment' %}
</a></th>
<th
class=
"text-center"
></th>
{% endblock %}
{% block table_body %}
{% for asset
group in assetgroups
%}
{% for asset
_group in asset_group_list
%}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ assetgroup.id }}"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ asset
_
group.id }}"
>
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset
group-detail' pk=asset
group.id %}"
>
{{ assetgroup.name }}
<a
href=
"{% url 'assets:asset
-group-detail' pk=asset_
group.id %}"
>
{{ asset
_
group.name }}
</a>
</td>
<td
class=
"text-center"
>
{{ assetgroup.assets.count }}
</td>
<td
class=
"text-center"
>
{{ assetgroup.comment }}
</td>
<td
class=
"text-center"
>
{{ asset
_
group.assets.count }}
</td>
<td
class=
"text-center"
>
{{ asset
_
group.comment }}
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset
group-edit' pk=asset
group.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Edit' %}
</a>
<a
href=
"{% url 'assets:asset
group-delete' pk=asset
group.id %}"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
<a
href=
"{% url 'assets:asset
-group-update' pk=asset_
group.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Edit' %}
</a>
<a
href=
"{% url 'assets:asset
-group-delete' pk=asset_
group.id %}"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
{% endfor %}
...
...
@@ -55,5 +55,3 @@
</div>
</form>
{% endblock %}
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/asset_list.html
View file @
02b5483d
{% extends 'base.html' %}
{% load i18n %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
...
...
@@ -23,7 +24,7 @@
<div
class=
"ibox-content"
>
<form
id=
"asset_form"
>
<div
class=
"col-sm-1"
style=
"padding-left: 0"
>
<a
href=
"{% url 'assets:asset-
add' %}"
class=
"btn btn-sm btn-primary "
>
添加资产
</a>
<a
href=
"{% url 'assets:asset-
create' %}"
class=
"btn btn-sm btn-primary "
>
{% trans 'Create asset' %}
</a>
</div>
<div
class=
"col-sm-7"
style=
"padding-left: 0px"
>
...
...
This diff is collapsed.
Click to expand it.
apps/assets/urls.py
View file @
02b5483d
...
...
@@ -14,14 +14,14 @@ app_name = 'assets'
urlpatterns
=
[
url
(
r'^$'
,
views
.
AssetListView
.
as_view
(),
name
=
'asset-index'
),
url
(
r'^asset$'
,
views
.
AssetListView
.
as_view
(),
name
=
'asset-list'
),
url
(
r'^asset/
add$'
,
views
.
AssetAddView
.
as_view
(),
name
=
'asset-add
'
),
url
(
r'^asset/
create$'
,
views
.
AssetCreateView
.
as_view
(),
name
=
'asset-create
'
),
url
(
r'^asset/(?P<pk>[0-9]+)$'
,
views
.
AssetDetailView
.
as_view
(),
name
=
'asset-detail'
),
url
(
r'^asset/(?P<pk>[0-9]+)$/
edit'
,
views
.
AssetEditView
.
as_view
(),
name
=
'asset-edit
'
),
url
(
r'^asset/(?P<pk>[0-9]+)$/
update'
,
views
.
AssetUpdateView
.
as_view
(),
name
=
'asset-update
'
),
url
(
r'^asset/(?P<pk>[0-9]+)/delete$'
,
views
.
AssetDeleteView
.
as_view
(),
name
=
'asset-delete'
),
url
(
r'^asset
group$'
,
views
.
AssetGroupListView
.
as_view
(),
name
=
'asset
group-list'
),
url
(
r'^asset
group/add$'
,
views
.
AssetGroupAddView
.
as_view
(),
name
=
'assetgroup-add
'
),
url
(
r'^asset
group/(?P<pk>[0-9]+)$'
,
views
.
AssetGroupDetailView
.
as_view
(),
name
=
'asset
group-detail'
),
url
(
r'^asset
group/(?P<pk>[0-9]+)/edit$'
,
views
.
AssetGroupEditView
.
as_view
(),
name
=
'assetgroup-edit
'
),
url
(
r'^asset
group/(?P<pk>[0-9]+)/delete$'
,
views
.
AssetGroupDeleteView
.
as_view
(),
name
=
'asset
group-delete'
),
url
(
r'^asset
-group$'
,
views
.
AssetGroupListView
.
as_view
(),
name
=
'asset-
group-list'
),
url
(
r'^asset
-group/create$'
,
views
.
AssetGroupCreateView
.
as_view
(),
name
=
'asset-group-create
'
),
url
(
r'^asset
-group/(?P<pk>[0-9]+)$'
,
views
.
AssetGroupDetailView
.
as_view
(),
name
=
'asset-
group-detail'
),
url
(
r'^asset
-group/(?P<pk>[0-9]+)/update$'
,
views
.
AssetGroupUpdateView
.
as_view
(),
name
=
'asset-group-update
'
),
url
(
r'^asset
-group/(?P<pk>[0-9]+)/delete$'
,
views
.
AssetGroupDeleteView
.
as_view
(),
name
=
'asset-
group-delete'
),
# url(r'^api/v1.0/', include(router.urls)),
]
This diff is collapsed.
Click to expand it.
apps/assets/views.py
View file @
02b5483d
...
...
@@ -16,18 +16,18 @@ from .forms import AssetForm, AssetGroupForm
from
.utils
import
AdminUserRequiredMixin
class
Asset
Add
View
(
CreateView
):
class
Asset
Create
View
(
CreateView
):
model
=
Asset
form_class
=
AssetForm
template_name
=
'assets/asset_
add
.html'
template_name
=
'assets/asset_
create
.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
return
super
(
Asset
Add
View
,
self
)
.
form_invalid
(
form
)
return
super
(
Asset
Create
View
,
self
)
.
form_invalid
(
form
)
class
Asset
Edit
View
(
UpdateView
):
class
Asset
Update
View
(
UpdateView
):
pass
...
...
@@ -48,11 +48,11 @@ class AssetDetailView(DetailView):
template_name
=
'assets/asset_detail.html'
class
AssetGroup
Add
View
(
CreateView
):
class
AssetGroup
Create
View
(
CreateView
):
model
=
AssetGroup
form_class
=
AssetGroupForm
template_name
=
'assets/asset
group_add
.html'
success_url
=
reverse_lazy
(
'assets:assetgroup-list'
)
template_name
=
'assets/asset
_group_create
.html'
success_url
=
reverse_lazy
(
'assets:asset
-
group-list'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -61,13 +61,17 @@ class AssetGroupAddView(CreateView):
'assets'
:
Asset
.
objects
.
all
(),
}
kwargs
.
update
(
context
)
return
super
(
AssetGroupAddView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
AssetGroupCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
form_valid
(
self
,
form
):
print
(
form
.
data
)
return
super
(
AssetGroupCreateView
,
self
)
.
form_valid
(
form
)
class
AssetGroupListView
(
ListView
):
model
=
AssetGroup
context_object_name
=
'asset
groups
'
template_name
=
'assets/assetgroup_list.html'
context_object_name
=
'asset
_group_list
'
template_name
=
'assets/asset
_
group_list.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -82,11 +86,11 @@ class AssetGroupDetailView(DetailView):
pass
class
AssetGroup
Edit
View
(
UpdateView
):
class
AssetGroup
Update
View
(
UpdateView
):
model
=
AssetGroup
form_class
=
AssetGroupForm
template_name
=
'assets/asset
group_add
.html'
success_url
=
reverse_lazy
(
'assets:assetgroup-list'
)
template_name
=
'assets/asset
_group_create
.html'
success_url
=
reverse_lazy
(
'assets:asset
-
group-list'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -95,7 +99,7 @@ class AssetGroupEditView(UpdateView):
'assets'
:
Asset
.
objects
.
all
(),
}
kwargs
.
update
(
context
)
return
super
(
AssetGroup
Edit
View
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
AssetGroup
Update
View
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetGroupDeleteView
(
DeleteView
):
...
...
This diff is collapsed.
Click to expand it.
apps/templates/_nav.html
View file @
02b5483d
...
...
@@ -10,7 +10,7 @@
</a>
<ul
class=
"nav nav-second-level active"
>
<li
id=
"user"
><a
href=
"{% url 'users:user-list' %}"
>
{% trans 'User' %}
</a></li>
<li
id=
"user
group"
><a
href=
"{% url 'users:user
group-list' %}"
>
{% trans 'User group' %}
</a></li>
<li
id=
"user
-group"
><a
href=
"{% url 'users:user-
group-list' %}"
>
{% trans 'User group' %}
</a></li>
</ul>
</li>
<li
id=
"assets"
>
...
...
@@ -19,7 +19,7 @@
</a>
<ul
class=
"nav nav-second-level"
>
<li
id=
"asset"
><a
href=
"{% url 'assets:asset-list' %}"
>
{% trans 'Asset' %}
</a></li>
<li
id=
"asset
group"
><a
href=
"{% url 'assets:asset
group-list' %}"
>
{% trans 'Asset group' %}
</a></li>
<li
id=
"asset
-group"
><a
href=
"{% url 'assets:asset-
group-list' %}"
>
{% trans 'Asset group' %}
</a></li>
<li
id=
"idc"
><a
href=
""
>
{% trans 'IDC' %}
</a></li>
<li
id=
"admin-user"
><a
href=
""
>
{% trans 'Admin user' %}
</a></li>
<li
id=
"system-user"
><a
href=
""
>
{% trans 'System user' %}
</a></li>
...
...
This diff is collapsed.
Click to expand it.
apps/templates/_user_profile.html
View file @
02b5483d
...
...
@@ -11,7 +11,7 @@
<strong
class=
"font-bold"
>
{{ request.user.name }}
<span
style=
"color: #8095a8"
></span></strong>
</span>
<span
class=
"text-muted text-xs block"
>
{{ request.user.get_role_display | default:
"{% trans 'User' %}"
}}
<b
class=
"caret"
></b>
{{ request.user.get_role_display | default:
_('User')
}}
<b
class=
"caret"
></b>
</span>
</span>
</a>
...
...
This diff is collapsed.
Click to expand it.
apps/users/forms.py
View file @
02b5483d
...
...
@@ -14,7 +14,7 @@ class UserLoginForm(forms.Form):
captcha
=
CaptchaField
()
class
User
Add
Form
(
ModelForm
):
class
User
Create
Form
(
ModelForm
):
class
Meta
:
model
=
User
fields
=
[
...
...
This diff is collapsed.
Click to expand it.
apps/users/models.py
View file @
02b5483d
...
...
@@ -66,7 +66,7 @@ class UserGroup(models.Model):
return
self
.
name
class
Meta
:
db_table
=
'usergroup'
db_table
=
'user
-
group'
@classmethod
def
initial
(
cls
):
...
...
This diff is collapsed.
Click to expand it.
apps/users/serializers.py
View file @
02b5483d
...
...
@@ -7,7 +7,7 @@ from .models import User, UserGroup
class
UserSerializer
(
serializers
.
ModelSerializer
):
groups
=
serializers
.
HyperlinkedRelatedField
(
many
=
True
,
read_only
=
True
,
view_name
=
'users:usergroup-detail-api'
)
groups
=
serializers
.
HyperlinkedRelatedField
(
many
=
True
,
read_only
=
True
,
view_name
=
'users:user
-
group-detail-api'
)
class
Meta
:
model
=
User
...
...
This diff is collapsed.
Click to expand it.
apps/users/templates/users/user_
add
.html
→
apps/users/templates/users/user_
create
.html
View file @
02b5483d
File moved
This diff is collapsed.
Click to expand it.
apps/users/templates/users/user
group_add
.html
→
apps/users/templates/users/user
_group_create
.html
View file @
02b5483d
File moved
This diff is collapsed.
Click to expand it.
apps/users/templates/users/usergroup_list.html
→
apps/users/templates/users/user
_
group_list.html
View file @
02b5483d
...
...
@@ -2,14 +2,14 @@
{% load i18n %}
{% load common_tags %}
{% block content_left_head %}
<a
href=
"{% url 'users:user
group-add
' %}"
class=
"btn btn-sm btn-primary "
>
添加用户组
</a>
<a
href=
"{% url 'users:user
-group-create
' %}"
class=
"btn btn-sm btn-primary "
>
添加用户组
</a>
{% endblock %}
{% block table_head %}
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
onclick=
"checkAll('check_all', 'checked')"
>
</th>
<th
class=
"text-center"
><a
href=
"{% url 'users:usergroup-list' %}?sort=name"
>
名称
</a></th>
<th
class=
"text-center"
><a
href=
"{% url 'users:user
-
group-list' %}?sort=name"
>
名称
</a></th>
<th
class=
"text-center"
>
用户数量
</th>
<th
class=
"text-center"
>
资产数量
</th>
<th
class=
"text-center"
>
描述
</th>
...
...
@@ -17,22 +17,22 @@
{% endblock %}
{% block table_body %}
{% for user
group in user
group_list %}
{% for user
_group in user_
group_list %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ usergroup.id }}"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ user
_
group.id }}"
>
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'users:user
group-detail' pk=user
group.id %}"
>
{{ usergroup.name }}
<a
href=
"{% url 'users:user
-group-detail' pk=user_
group.id %}"
>
{{ user
_
group.name }}
</a>
</td>
<td
class=
"text-center"
>
{{ usergroup.users.all|length }}
</td>
<td
class=
"text-center"
>
{{ user
_
group.users.all|length }}
</td>
<td
class=
"text-center"
>
数量
</td>
<th
class=
"text-center"
>
{{ usergroup.comment|truncatewords:8 }}
</th>
<th
class=
"text-center"
>
{{ user
_
group.comment|truncatewords:8 }}
</th>
<td
class=
"text-center"
>
<a
href=
"{% url 'users:user
group-edit' pk=user
group.id %}"
class=
"btn btn-xs btn-info"
>
编辑
</a>
<a
href=
"{% url 'users:user
group-delete' pk=user
group.id %}"
class=
"btn btn-xs btn-danger del"
>
删除
</a>
<a
href=
"{% url 'users:user
-group-update' pk=user_
group.id %}"
class=
"btn btn-xs btn-info"
>
编辑
</a>
<a
href=
"{% url 'users:user
-group-delete' pk=user_
group.id %}"
class=
"btn btn-xs btn-danger del"
>
删除
</a>
</td>
</tr>
{% endfor %}
...
...
This diff is collapsed.
Click to expand it.
apps/users/templates/users/user_list.html
View file @
02b5483d
...
...
@@ -2,7 +2,7 @@
{% load i18n %}
{% load common_tags %}
{% block content_left_head %}
<a
href=
"{% url 'users:user-
add
' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create user" %}
</a>
<a
href=
"{% url 'users:user-
create
' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create user" %}
</a>
{% endblock %}
{% block table_head %}
...
...
@@ -41,7 +41,7 @@
{% endif %}
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'users:user-
edit
' pk=user.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Edit' %}
</a>
<a
href=
"{% url 'users:user-
update
' pk=user.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Edit' %}
</a>
<a
href=
"{% url 'users:user-delete' pk=user.id %}"
class=
"btn btn-xs btn-danger del {% if user.id == request.user.id or user.username == 'admin' %} disabled {% endif %}"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
...
...
This diff is collapsed.
Click to expand it.
apps/users/templates/users/user_
edit
.html
→
apps/users/templates/users/user_
update
.html
View file @
02b5483d
File moved
This diff is collapsed.
Click to expand it.
apps/users/tests/test_views.py
View file @
02b5483d
...
...
@@ -54,7 +54,7 @@ class UserAddTests(TestCase):
'date_expired'
:
'2086-08-06 19:12:22'
,
}
response
=
self
.
client
.
post
(
reverse
(
'users:user-
add
'
),
data
)
response
=
self
.
client
.
post
(
reverse
(
'users:user-
create
'
),
data
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
response
[
'location'
],
reverse
(
'users:user-list'
))
...
...
This diff is collapsed.
Click to expand it.
apps/users/urls.py
View file @
02b5483d
...
...
@@ -17,14 +17,14 @@ urlpatterns = [
url
(
r'^password/reset/success$'
,
views
.
UserResetPasswordSuccessView
.
as_view
(),
name
=
'reset-password-success'
),
url
(
r'^user$'
,
views
.
UserListView
.
as_view
(),
name
=
'user-list'
),
url
(
r'^user/(?P<pk>[0-9]+)$'
,
views
.
UserDetailView
.
as_view
(),
name
=
'user-detail'
),
url
(
r'^user/
add$'
,
views
.
UserAddView
.
as_view
(),
name
=
'user-add
'
),
url
(
r'^user/(?P<pk>[0-9]+)/
edit$'
,
views
.
UserUpdateView
.
as_view
(),
name
=
'user-edit
'
),
url
(
r'^user/
create$'
,
views
.
UserCreateView
.
as_view
(),
name
=
'user-create
'
),
url
(
r'^user/(?P<pk>[0-9]+)/
update$'
,
views
.
UserUpdateView
.
as_view
(),
name
=
'user-update
'
),
url
(
r'^user/(?P<pk>[0-9]+)/delete$'
,
views
.
UserDeleteView
.
as_view
(),
name
=
'user-delete'
),
url
(
r'^user
group$'
,
views
.
UserGroupListView
.
as_view
(),
name
=
'user
group-list'
),
url
(
r'^user
group/(?P<pk>[0-9]+)$'
,
views
.
UserGroupDetailView
.
as_view
(),
name
=
'user
group-detail'
),
url
(
r'^user
group/add/$'
,
views
.
UserGroupAddView
.
as_view
(),
name
=
'usergroup-add
'
),
url
(
r'^user
group/(?P<pk>[0-9]+)/edit$'
,
views
.
UserGroupUpdateView
.
as_view
(),
name
=
'usergroup-edit
'
),
url
(
r'^user
group/(?P<pk>[0-9]+)/delete$'
,
views
.
UserGroupDeleteView
.
as_view
(),
name
=
'user
group-delete'
),
url
(
r'^user
-group$'
,
views
.
UserGroupListView
.
as_view
(),
name
=
'user-
group-list'
),
url
(
r'^user
-group/(?P<pk>[0-9]+)$'
,
views
.
UserGroupDetailView
.
as_view
(),
name
=
'user-
group-detail'
),
url
(
r'^user
-group/create$'
,
views
.
UserGroupCreateView
.
as_view
(),
name
=
'user-group-create
'
),
url
(
r'^user
-group/(?P<pk>[0-9]+)/update$'
,
views
.
UserGroupUpdateView
.
as_view
(),
name
=
'user-group-update
'
),
url
(
r'^user
-group/(?P<pk>[0-9]+)/delete$'
,
views
.
UserGroupDeleteView
.
as_view
(),
name
=
'user-
group-delete'
),
]
...
...
@@ -32,6 +32,6 @@ urlpatterns += [
url
(
r'^v1/users$'
,
api
.
UserListAddApi
.
as_view
(),
name
=
'user-list-api'
),
url
(
r'^v1/users/(?P<pk>[0-9]+)$'
,
api
.
UserDetailDeleteUpdateApi
.
as_view
(),
name
=
'user-detail-api'
),
url
(
r'^v1/users/(?P<pk>[0-9]+)/active$'
,
api
.
UserActiveApi
.
as_view
(),
name
=
'user-active-api'
),
url
(
r'^v1/usergroups$'
,
api
.
UserGroupListAddApi
.
as_view
(),
name
=
'usergroup-list-api'
),
url
(
r'^v1/usergroups/(?P<pk>[0-9]+)$'
,
api
.
UserGroupDetailDeleteUpdateApi
.
as_view
(),
name
=
'usergroup-detail-api'
),
url
(
r'^v1/usergroups$'
,
api
.
UserGroupListAddApi
.
as_view
(),
name
=
'user
-
group-list-api'
),
url
(
r'^v1/usergroups/(?P<pk>[0-9]+)$'
,
api
.
UserGroupDetailDeleteUpdateApi
.
as_view
(),
name
=
'user
-
group-detail-api'
),
]
This diff is collapsed.
Click to expand it.
apps/users/views.py
View file @
02b5483d
...
...
@@ -20,7 +20,7 @@ from django.contrib.auth import views as auth_view, authenticate, login, logout
from
common.utils
import
get_object_or_none
from
.models
import
User
,
UserGroup
from
.forms
import
User
Add
Form
,
UserUpdateForm
,
UserGroupForm
,
UserLoginForm
from
.forms
import
User
Create
Form
,
UserUpdateForm
,
UserGroupForm
,
UserLoginForm
from
.utils
import
AdminUserRequiredMixin
,
ssh_key_gen
,
user_add_success_next
,
send_reset_password_mail
...
...
@@ -101,15 +101,15 @@ class UserListView(AdminUserRequiredMixin, ListView):
return
context
class
User
Add
View
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
class
User
Create
View
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
model
=
User
form_class
=
User
Add
Form
template_name
=
'users/user_
add
.html'
form_class
=
User
Create
Form
template_name
=
'users/user_
create
.html'
success_url
=
reverse_lazy
(
'users:user-list'
)
success_message
=
_
(
'Create user<a href="
%
s">
%
s</a> success.'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
User
Add
View
,
self
)
.
get_context_data
(
**
kwargs
)
context
=
super
(
User
Create
View
,
self
)
.
get_context_data
(
**
kwargs
)
context
.
update
({
'app'
:
_
(
'Users'
),
'action'
:
_
(
'Create user'
)})
return
context
...
...
@@ -118,7 +118,7 @@ class UserAddView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
user
.
created_by
=
self
.
request
.
user
.
username
or
'System'
user
.
save
()
user_add_success_next
(
user
)
return
super
(
User
Add
View
,
self
)
.
form_valid
(
form
)
return
super
(
User
Create
View
,
self
)
.
form_valid
(
form
)
def
get_success_message
(
self
,
cleaned_data
):
return
self
.
success_message
%
(
...
...
@@ -130,7 +130,7 @@ class UserAddView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
class
UserUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
model
=
User
form_class
=
UserUpdateForm
template_name
=
'users/user_
edit
.html'
template_name
=
'users/user_
update
.html'
context_object_name
=
'user'
success_url
=
reverse_lazy
(
'users:user-list'
)
...
...
@@ -175,8 +175,8 @@ class UserDetailView(AdminUserRequiredMixin, DetailView):
class
UserGroupListView
(
AdminUserRequiredMixin
,
ListView
):
model
=
UserGroup
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
context_object_name
=
'usergroup_list'
template_name
=
'users/usergroup_list.html'
context_object_name
=
'user
_
group_list'
template_name
=
'users/user
_
group_list.html'
ordering
=
'-date_added'
def
get_queryset
(
self
):
...
...
@@ -196,26 +196,26 @@ class UserGroupListView(AdminUserRequiredMixin, ListView):
return
context
class
UserGroup
Add
View
(
AdminUserRequiredMixin
,
CreateView
):
class
UserGroup
Create
View
(
AdminUserRequiredMixin
,
CreateView
):
model
=
UserGroup
form_class
=
UserGroupForm
template_name
=
'users/user
group_add
.html'
success_url
=
reverse_lazy
(
'users:usergroup-list'
)
template_name
=
'users/user
_group_create
.html'
success_url
=
reverse_lazy
(
'users:user
-
group-list'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
UserGroup
Add
View
,
self
)
.
get_context_data
(
**
kwargs
)
context
=
super
(
UserGroup
Create
View
,
self
)
.
get_context_data
(
**
kwargs
)
users
=
User
.
objects
.
all
()
context
.
update
({
'app'
:
_
(
'Users'
),
'action'
:
_
(
'Create usergroup'
),
'users'
:
users
})
context
.
update
({
'app'
:
_
(
'Users'
),
'action'
:
_
(
'Create user
group'
),
'users'
:
users
})
return
context
def
form_valid
(
self
,
form
):
usergroup
=
form
.
save
()
user
_
group
=
form
.
save
()
users_id_list
=
self
.
request
.
POST
.
getlist
(
'users'
,
[])
users
=
[
get_object_or_404
(
User
,
id
=
user_id
)
for
user_id
in
users_id_list
]
usergroup
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
usergroup
.
users
.
add
(
*
tuple
(
users
))
usergroup
.
save
()
return
super
(
UserGroup
Add
View
,
self
)
.
form_valid
(
form
)
user
_
group
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
user
_
group
.
users
.
add
(
*
tuple
(
users
))
user
_
group
.
save
()
return
super
(
UserGroup
Create
View
,
self
)
.
form_valid
(
form
)
class
UserGroupUpdateView
(
UpdateView
):
...
...
This diff is collapsed.
Click to expand it.
docs/python_style_guide.md
View file @
02b5483d
...
...
@@ -3,7 +3,7 @@
## 语言框架
1.
Python 2.7 由于ansible目前不支持python3
2.
Django 1.10 (最新版本)
3.
Terminal Websocket使用go实现
3.
Terminal Websocket使用go实现
(未来)
## Django规范
...
...
@@ -32,7 +32,8 @@ Python方面大致的风格,我们采用pocoo的[Style Guidance](http://www.po
#### 最大行长度
按PEP8规范,Python一般限制最大79个字符, 如果有必要最多84个字符
按PEP8规范,Python一般限制最大79个字符, 但是Django的命名,url等通常比较长,
而且21世纪都是宽屏了,所以我们限制最大120字符
**补充说明:HTML代码不受此规范约束。**
...
...
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