Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a7ae6242
authored
May 27, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add UserCreationView
parent
e6f7e48a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
0 deletions
+70
-0
circle/dashboard/forms.py
+23
-0
circle/dashboard/templates/dashboard/group-detail.html
+5
-0
circle/dashboard/templates/dashboard/user-create.html
+7
-0
circle/dashboard/urls.py
+4
-0
circle/dashboard/views.py
+31
-0
No files found.
circle/dashboard/forms.py
View file @
a7ae6242
...
...
@@ -32,6 +32,7 @@ from crispy_forms.layout import (
from
crispy_forms.utils
import
render_field
from
django
import
forms
from
django.contrib.auth.forms
import
UserCreationForm
as
OrgUserCreationForm
from
django.forms.widgets
import
TextInput
from
django.template
import
Context
from
django.template.loader
import
render_to_string
...
...
@@ -1086,3 +1087,25 @@ class CirclePasswordChangeForm(PasswordChangeForm):
css_class
=
"btn btn-primary"
,
css_id
=
"submit-password-button"
))
return
helper
class
UserCreationForm
(
OrgUserCreationForm
):
class
Meta
:
model
=
User
fields
=
(
"username"
,
'email'
,
'first_name'
,
'last_name'
)
@property
def
helper
(
self
):
helper
=
FormHelper
()
helper
.
layout
=
Layout
(
'username'
,
'password1'
,
'password2'
,
'email'
,
'first_name'
,
'last_name'
)
helper
.
add_input
(
Submit
(
"submit"
,
_
(
"Save"
)))
return
helper
def
save
(
self
,
commit
=
True
):
user
=
super
(
UserCreationForm
,
self
)
.
save
(
commit
=
False
)
user
.
set_password
(
self
.
cleaned_data
[
"password1"
])
if
commit
:
user
.
save
()
return
user
circle/dashboard/templates/dashboard/group-detail.html
View file @
a7ae6242
...
...
@@ -42,6 +42,11 @@
<form
action=
""
method=
"post"
>
{% csrf_token %}
<table
class=
"table table-striped table-with-form-fields table-bordered"
id=
"group-detail-user-table"
>
<tbody>
{% if perms.auth.add_user %}
<p
class=
"pull-right"
>
<a
href=
"{% url "
dashboard
.
views
.
create-user
"
group
.
pk
%}"
class=
"btn btn-success"
>
{% trans "Create user" %}
</a>
</p>
{% endif %}
<thead><tr><th></th><th>
{% trans "Who" %}
</th><th>
{% trans "Remove" %}
</th></tr></thead>
{% for i in users %}
<tr>
...
...
circle/dashboard/templates/dashboard/user-create.html
0 → 100644
View file @
a7ae6242
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block content %}
{% crispy form %}
{% endblock %}
circle/dashboard/urls.py
View file @
a7ae6242
...
...
@@ -33,6 +33,7 @@ from .views import (
GroupRemoveAclUserView
,
GroupRemoveAclGroupView
,
GroupRemoveUserView
,
GroupCreate
,
TemplateChoose
,
UserCreationView
,
)
urlpatterns
=
patterns
(
...
...
@@ -144,4 +145,7 @@ urlpatterns = patterns(
name
=
"dashboard.views.remove-user"
),
url
(
r'^group/create/$'
,
GroupCreate
.
as_view
(),
name
=
'dashboard.views.group-create'
),
url
(
r'^group/(?P<group_pk>\d+)/create/$'
,
UserCreationView
.
as_view
(),
name
=
"dashboard.views.create-user"
),
)
circle/dashboard/views.py
View file @
a7ae6242
...
...
@@ -54,6 +54,7 @@ from braces.views._access import AccessMixin
from
.forms
import
(
CircleAuthenticationForm
,
DiskAddForm
,
HostForm
,
LeaseForm
,
MyProfileForm
,
NodeForm
,
TemplateForm
,
TraitForm
,
VmCustomizeForm
,
GroupCreateForm
,
UserCreationForm
,
CirclePasswordChangeForm
)
...
...
@@ -2576,6 +2577,36 @@ class InstanceActivityDetail(SuperuserRequiredMixin, DetailView):
return
ctx
class
UserCreationView
(
CreateView
):
form_class
=
UserCreationForm
model
=
User
template_name
=
'dashboard/user-create.html'
def
get_group
(
self
,
group_pk
):
self
.
group
=
get_object_or_404
(
Group
,
pk
=
group_pk
)
if
not
self
.
group
.
profile
.
has_level
(
self
.
request
.
user
,
'owner'
):
raise
PermissionDenied
()
def
get
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
request
.
user
.
has_perm
(
'auth.add_user'
):
raise
PermissionDenied
()
self
.
get_group
(
kwargs
.
pop
(
'group_pk'
))
return
super
(
UserCreationView
,
self
)
.
get
(
*
args
,
**
kwargs
)
def
post
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
request
.
user
.
has_perm
(
'auth.add_user'
):
raise
PermissionDenied
()
group_pk
=
kwargs
.
pop
(
'group_pk'
)
self
.
get_group
(
group_pk
)
ret
=
super
(
UserCreationView
,
self
)
.
post
(
*
args
,
**
kwargs
)
if
self
.
object
:
self
.
object
.
groups
.
add
(
self
.
group
)
return
redirect
(
reverse
(
'dashboard.views.group-detail'
,
args
=
[
group_pk
]))
else
:
return
ret
class
InterfaceDeleteView
(
DeleteView
):
model
=
Interface
...
...
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