Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
18d3d7d9
authored
Jan 21, 2015
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: rewrite UserCreationView
parent
0df9f5df
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
28 deletions
+35
-28
circle/dashboard/forms.py
+13
-2
circle/dashboard/templates/dashboard/group-detail.html
+1
-1
circle/dashboard/templates/dashboard/user-list.html
+1
-1
circle/dashboard/urls.py
+3
-3
circle/dashboard/views/user.py
+17
-21
No files found.
circle/dashboard/forms.py
View file @
18d3d7d9
...
@@ -59,7 +59,7 @@ from django.utils.translation import string_concat
...
@@ -59,7 +59,7 @@ from django.utils.translation import string_concat
from
.validators
import
domain_validator
from
.validators
import
domain_validator
from
dashboard.models
import
ConnectCommand
from
dashboard.models
import
ConnectCommand
,
create_profile
LANGUAGES_WITH_CODE
=
((
l
[
0
],
string_concat
(
l
[
1
],
" ("
,
l
[
0
],
")"
))
LANGUAGES_WITH_CODE
=
((
l
[
0
],
string_concat
(
l
[
1
],
" ("
,
l
[
0
],
")"
))
for
l
in
LANGUAGES
)
for
l
in
LANGUAGES
)
...
@@ -1254,10 +1254,19 @@ class CirclePasswordChangeForm(PasswordChangeForm):
...
@@ -1254,10 +1254,19 @@ class CirclePasswordChangeForm(PasswordChangeForm):
class
UserCreationForm
(
OrgUserCreationForm
):
class
UserCreationForm
(
OrgUserCreationForm
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
choices
=
kwargs
.
pop
(
'choices'
)
group
=
kwargs
.
pop
(
'default'
)
super
(
UserCreationForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'groups'
]
=
forms
.
ModelMultipleChoiceField
(
queryset
=
choices
,
initial
=
[
group
],
required
=
False
,
label
=
_
(
'Groups'
))
class
Meta
:
class
Meta
:
model
=
User
model
=
User
fields
=
(
"username"
,
'email'
,
'first_name'
,
'last_name'
)
fields
=
(
"username"
,
'email'
,
'first_name'
,
'last_name'
,
'groups'
)
@property
@property
def
helper
(
self
):
def
helper
(
self
):
...
@@ -1272,6 +1281,8 @@ class UserCreationForm(OrgUserCreationForm):
...
@@ -1272,6 +1281,8 @@ class UserCreationForm(OrgUserCreationForm):
user
.
set_password
(
self
.
cleaned_data
[
"password1"
])
user
.
set_password
(
self
.
cleaned_data
[
"password1"
])
if
commit
:
if
commit
:
user
.
save
()
user
.
save
()
create_profile
(
user
)
user
.
groups
.
add
(
*
self
.
cleaned_data
[
"groups"
])
return
user
return
user
...
...
circle/dashboard/templates/dashboard/group-detail.html
View file @
18d3d7d9
...
@@ -78,7 +78,7 @@
...
@@ -78,7 +78,7 @@
<h3>
<h3>
{% trans "User list" %}
{% trans "User list" %}
{% if perms.auth.add_user %}
{% if perms.auth.add_user %}
<a
href=
"{% url "
dashboard
.
views
.
create-user
"
group
.
pk
%
}"
class=
"btn btn-success pull-right"
>
<a
href=
"{% url "
dashboard
.
views
.
user-create
"
%}?
group_pk=
{{
group
.
pk
}
}"
class=
"btn btn-success pull-right"
>
{% trans "Create user" %}
{% trans "Create user" %}
</a>
</a>
{% endif %}
{% endif %}
...
...
circle/dashboard/templates/dashboard/user-list.html
View file @
18d3d7d9
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
<div
class=
"col-md-12"
>
<div
class=
"col-md-12"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<div
class=
"panel-heading"
>
<a
href=
"{% url "
dashboard
.
views
.
template-choos
e
"
%}"
class=
"pull-right btn btn-success btn-xs template-choose"
>
<a
href=
"{% url "
dashboard
.
views
.
user-creat
e
"
%}"
class=
"pull-right btn btn-success btn-xs template-choose"
>
<i
class=
"fa fa-plus"
></i>
{% trans "new user" %}
<i
class=
"fa fa-plus"
></i>
{% trans "new user" %}
</a>
</a>
<h3
class=
"no-margin"
><i
class=
"fa fa-user"
></i>
{% trans "Users" %}
</h3>
<h3
class=
"no-margin"
><i
class=
"fa fa-user"
></i>
{% trans "Users" %}
</h3>
...
...
circle/dashboard/urls.py
View file @
18d3d7d9
...
@@ -64,6 +64,9 @@ urlpatterns = patterns(
...
@@ -64,6 +64,9 @@ urlpatterns = patterns(
url
(
r'^$'
,
IndexView
.
as_view
(),
name
=
"dashboard.index"
),
url
(
r'^$'
,
IndexView
.
as_view
(),
name
=
"dashboard.index"
),
url
(
r"^profile/list/$"
,
UserList
.
as_view
(),
url
(
r"^profile/list/$"
,
UserList
.
as_view
(),
name
=
"dashboard.views.user-list"
),
name
=
"dashboard.views.user-list"
),
url
(
r'^profile/create/$'
,
UserCreationView
.
as_view
(),
name
=
"dashboard.views.user-create"
),
url
(
r'^lease/(?P<pk>\d+)/$'
,
LeaseDetail
.
as_view
(),
url
(
r'^lease/(?P<pk>\d+)/$'
,
LeaseDetail
.
as_view
(),
name
=
"dashboard.views.lease-detail"
),
name
=
"dashboard.views.lease-detail"
),
url
(
r'^lease/create/$'
,
LeaseCreate
.
as_view
(),
url
(
r'^lease/create/$'
,
LeaseCreate
.
as_view
(),
...
@@ -177,9 +180,6 @@ urlpatterns = patterns(
...
@@ -177,9 +180,6 @@ urlpatterns = patterns(
name
=
"dashboard.views.remove-future-user"
),
name
=
"dashboard.views.remove-future-user"
),
url
(
r'^group/create/$'
,
GroupCreate
.
as_view
(),
url
(
r'^group/create/$'
,
GroupCreate
.
as_view
(),
name
=
'dashboard.views.group-create'
),
name
=
'dashboard.views.group-create'
),
url
(
r'^group/(?P<group_pk>\d+)/create/$'
,
UserCreationView
.
as_view
(),
name
=
"dashboard.views.create-user"
),
url
(
r'^group/(?P<group_pk>\d+)/permissions/$'
,
url
(
r'^group/(?P<group_pk>\d+)/permissions/$'
,
GroupPermissionsView
.
as_view
(),
GroupPermissionsView
.
as_view
(),
name
=
"dashboard.views.group-permissions"
),
name
=
"dashboard.views.group-permissions"
),
...
...
circle/dashboard/views/user.py
View file @
18d3d7d9
...
@@ -52,7 +52,7 @@ from ..forms import (
...
@@ -52,7 +52,7 @@ from ..forms import (
UserKeyForm
,
CirclePasswordChangeForm
,
ConnectCommandForm
,
UserKeyForm
,
CirclePasswordChangeForm
,
ConnectCommandForm
,
UserListSearchForm
,
UserListSearchForm
,
)
)
from
..models
import
Profile
,
GroupProfile
,
ConnectCommand
,
create_profile
from
..models
import
Profile
,
GroupProfile
,
ConnectCommand
from
..tables
import
(
from
..tables
import
(
UserKeyListTable
,
ConnectCommandListTable
,
UserListTable
,
UserKeyListTable
,
ConnectCommandListTable
,
UserListTable
,
)
)
...
@@ -274,28 +274,24 @@ class UserCreationView(LoginRequiredMixin, PermissionRequiredMixin,
...
@@ -274,28 +274,24 @@ class UserCreationView(LoginRequiredMixin, PermissionRequiredMixin,
permission_required
=
"auth.add_user"
permission_required
=
"auth.add_user"
def
get_success_url
(
self
):
def
get_success_url
(
self
):
re
verse
(
'dashboard.views.group-detail'
,
args
=
[
self
.
group
.
pk
])
re
turn
reverse
(
'dashboard.views.profile'
,
args
=
[
self
.
object
.
username
])
def
get_group
(
self
,
group_pk
):
def
get_form_kwargs
(
self
):
self
.
group
=
get_object_or_404
(
Group
,
pk
=
group_pk
)
profiles
=
GroupProfile
.
get_objects_with_level
(
if
not
self
.
group
.
profile
.
has_level
(
self
.
request
.
user
,
'owner'
):
'owner'
,
self
.
request
.
user
)
raise
PermissionDenied
()
choices
=
Group
.
objects
.
filter
(
groupprofile__in
=
profiles
)
group_pk
=
self
.
request
.
GET
.
get
(
'group_pk'
)
def
get
(
self
,
*
args
,
**
kwargs
):
if
group_pk
:
self
.
get_group
(
kwargs
.
pop
(
'group_pk'
))
try
:
return
super
(
UserCreationView
,
self
)
.
get
(
*
args
,
**
kwargs
)
default
=
choices
.
get
(
pk
=
group_pk
)
except
(
ValueError
,
Group
.
DoesNotExist
):
def
post
(
self
,
*
args
,
**
kwargs
):
raise
Http404
()
group_pk
=
kwargs
.
pop
(
'group_pk'
)
self
.
get_group
(
group_pk
)
ret
=
super
(
UserCreationView
,
self
)
.
post
(
*
args
,
**
kwargs
)
if
self
.
object
:
create_profile
(
self
.
object
)
self
.
object
.
groups
.
add
(
self
.
group
)
return
redirect
(
reverse
(
'dashboard.views.group-detail'
,
args
=
[
group_pk
]))
else
:
else
:
return
ret
default
=
None
val
=
super
(
UserCreationView
,
self
)
.
get_form_kwargs
()
val
.
update
({
'choices'
:
choices
,
'default'
:
default
})
return
val
class
ProfileView
(
LoginRequiredMixin
,
DetailView
):
class
ProfileView
(
LoginRequiredMixin
,
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