Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
12f405e8
authored
Feb 21, 2014
by
Oláh István Gergely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: create group form, view
parent
de9e099a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
122 additions
and
10 deletions
+122
-10
circle/dashboard/forms.py
+50
-1
circle/dashboard/models.py
+6
-1
circle/dashboard/templates/dashboard/group-detail.html
+9
-3
circle/dashboard/templates/dashboard/index-groups.html
+1
-1
circle/dashboard/urls.py
+4
-1
circle/dashboard/views.py
+52
-3
No files found.
circle/dashboard/forms.py
View file @
12f405e8
from
datetime
import
timedelta
from
django.contrib.auth.models
import
User
from
django.contrib.auth.forms
import
(
AuthenticationForm
,
PasswordResetForm
,
SetPasswordForm
,
)
from
django.contrib.auth.models
import
User
,
Group
from
crispy_forms.helper
import
FormHelper
from
crispy_forms.layout
import
(
...
...
@@ -279,6 +279,55 @@ class VmCustomizeForm(forms.Form):
)
class
GroupCreateForm
(
forms
.
ModelForm
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
GroupCreateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
helper
=
FormHelper
(
self
)
self
.
helper
.
form_show_labels
=
False
self
.
helper
.
layout
=
Layout
(
Div
(
Div
(
AnyTag
(
'h4'
,
HTML
(
_
(
"Name"
)),
),
css_class
=
"col-sm-10"
,
),
css_class
=
"row"
,
),
Div
(
Div
(
Field
(
'name'
,
id
=
"group-create-name"
),
css_class
=
"col-sm-10"
,
),
css_class
=
"row"
,
),
Div
(
# buttons
Div
(
AnyTag
(
# tip: don't try to use Button class
"button"
,
AnyTag
(
"i"
,
css_class
=
"icon-play"
),
HTML
(
" Create"
),
css_id
=
"vm-create-submit"
,
css_class
=
"btn btn-success"
,
),
css_class
=
"col-sm-5"
,
),
css_class
=
"row"
,
),
)
class
Meta
:
model
=
Group
fields
=
[
'name'
,
]
class
HostForm
(
forms
.
ModelForm
):
def
setowner
(
self
,
user
):
...
...
circle/dashboard/models.py
View file @
12f405e8
...
...
@@ -7,7 +7,7 @@ from django.contrib.auth.signals import user_logged_in
from
django.core.urlresolvers
import
reverse
from
django.db.models
import
(
Model
,
ForeignKey
,
OneToOneField
,
CharField
,
IntegerField
,
TextField
,
DateTimeField
,
DateTimeField
,
permalink
,
)
from
django.template.loader
import
render_to_string
from
django.utils.translation
import
ugettext_lazy
as
_
,
override
...
...
@@ -93,6 +93,11 @@ class GroupProfile(AclBase):
except
cls
.
DoesNotExist
:
return
Group
.
objects
.
get
(
name
=
name
)
@permalink
def
get_absolute_url
(
self
):
return
(
'dashboard.views.group-detail'
,
None
,
{
'pk'
:
self
.
group
.
pk
})
def
get_or_create_profile
(
self
):
obj
,
created
=
GroupProfile
.
objects
.
get_or_create
(
group_id
=
self
.
pk
)
...
...
circle/dashboard/templates/dashboard/group-detail.html
View file @
12f405e8
...
...
@@ -33,7 +33,8 @@
<div
class=
"panel panel-default"
id=
"group-detail-panel"
>
<div
class=
"tab-content panel-body"
>
<h3>
{% trans "User list"|capfirst %}
</h3>
<h3>
{% trans "User list"|capfirst %}
</h3>
<form
action=
""
method=
"post"
>
{% csrf_token %}
<table
class=
"table table-striped table-with-form-fields"
>
<tbody>
<thead><tr><th></th><th>
{% trans "Who" %}
</th><th></th><th></th></tr></thead>
...
...
@@ -43,10 +44,15 @@
{% endfor %}
<tr><td><i
class=
"icon-plus"
></i></td>
<td><input
type=
"text"
class=
"form-control"
name=
"perm-new-name"
placeholder=
"{% trans "
Name
of
group
or
user
"
%}"
></td>
placeholder=
"{% trans "
Name
of
user
"
%}"
></td>
</tr>
</tbody>
</table>
<div
class=
"form-actions"
>
<button
type=
"submit"
class=
"btn btn-success"
>
{% trans "Save" %}
</button>
</div>
</form>
<h3>
{% trans "Permissions"|capfirst %}
</h3>
<form
action=
"{{acl.url}}"
method=
"post"
>
{% csrf_token %}
...
...
@@ -84,7 +90,7 @@
</table>
<textarea
class=
"form-control"
></textarea>
<div
class=
"form-actions
panel-body
"
>
<div
class=
"form-actions"
>
<button
type=
"submit"
class=
"btn btn-success"
>
{% trans "Save" %}
</button>
</div>
</form>
...
...
circle/dashboard/templates/dashboard/index-groups.html
View file @
12f405e8
...
...
@@ -26,7 +26,7 @@
<i
class=
"icon-chevron-sign-right"
></i>
<strong>
{{ more_groups }}
</strong>
more
</a>
{% endif %}
<a
class=
"btn btn-success btn-xs group-create"
href=
"
#
"
><i
class=
"icon-upload-alt"
></i>
upload
</a>
<a
class=
"btn btn-success btn-xs group-create"
href=
"
{% url "
dashboard
.
views
.
group-create
"
%}
"
><i
class=
"icon-upload-alt"
></i>
upload
</a>
</div>
</div>
</div>
...
...
circle/dashboard/urls.py
View file @
12f405e8
...
...
@@ -10,8 +10,9 @@ from .views import (
TransferOwnershipConfirmView
,
TransferOwnershipView
,
vm_activity
,
VmCreate
,
VmDelete
,
VmDetailView
,
VmDetailVncTokenView
,
VmGraphView
,
VmList
,
VmMassDelete
,
VmMigrateView
,
VmRenewView
,
GroupRemoveAclUserView
,
GroupRemoveAclGroupView
,
GroupRemoveUserView
GroupRemoveAclGroupView
,
GroupRemoveUserView
,
GroupCreate
,
)
from
vm.models
import
Instance
...
...
@@ -111,4 +112,6 @@ urlpatterns = patterns(
url
(
r'^group/(?P<group_pk>\d+)/remove/user/(?P<user_pk>\d+)/$'
,
GroupRemoveUserView
.
as_view
(),
name
=
"dashboard.views.remove-user"
),
url
(
r'^group/create/$'
,
GroupCreate
.
as_view
(),
name
=
'dashboard.views.group-create'
),
)
circle/dashboard/views.py
View file @
12f405e8
...
...
@@ -35,10 +35,13 @@ from braces.views import (
from
.forms
import
(
CircleAuthenticationForm
,
DiskAddForm
,
HostForm
,
LeaseForm
,
MyProfileForm
,
NodeForm
,
TemplateForm
,
TraitForm
,
VmCustomizeForm
,
NodeForm
,
TraitForm
,
VmCustomizeForm
,
TemplateForm
,
GroupCreateForm
,
)
from
.tables
import
(
NodeListTable
,
NodeVmListTable
,
TemplateListTable
,
LeaseListTable
,
GroupListTable
,
)
from
.tables
import
(
NodeListTable
,
NodeVmListTable
,
TemplateListTable
,
LeaseListTable
,
GroupListTable
,)
from
vm.models
import
(
Instance
,
instance_activity
,
InstanceActivity
,
InstanceTemplate
,
Interface
,
InterfaceTemplate
,
Lease
,
Node
,
NodeActivity
,
Trait
,
...
...
@@ -1278,6 +1281,52 @@ class NodeCreate(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView):
return
redirect
(
path
)
class
GroupCreate
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
TemplateView
):
form_class
=
GroupCreateForm
form
=
None
def
get_template_names
(
self
):
if
self
.
request
.
is_ajax
():
return
[
'dashboard/modal-wrapper.html'
]
else
:
return
[
'dashboard/nojs-wrapper.html'
]
def
get
(
self
,
request
,
form
=
None
,
*
args
,
**
kwargs
):
if
form
is
None
:
form
=
self
.
form_class
()
context
=
self
.
get_context_data
(
**
kwargs
)
context
.
update
({
'template'
:
'dashboard/group-create.html'
,
'box_title'
:
'Create a Group'
,
'form'
:
form
,
})
return
self
.
render_to_response
(
context
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
GroupCreate
,
self
)
.
get_context_data
(
**
kwargs
)
# TODO acl
context
.
update
({
})
return
context
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
form
=
self
.
form_class
(
request
.
POST
)
if
not
form
.
is_valid
():
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
form
.
cleaned_data
savedform
=
form
.
save
()
messages
.
success
(
request
,
_
(
'Group successfully created!'
))
if
request
.
is_ajax
():
return
HttpResponse
(
json
.
dumps
({
'redirect'
:
savedform
.
profile
.
get_absolute_url
()}),
content_type
=
"application/json"
)
else
:
return
redirect
(
savedform
.
profile
.
get_absolute_url
())
class
VmDelete
(
LoginRequiredMixin
,
DeleteView
):
model
=
Instance
template_name
=
"dashboard/confirm/base-delete.html"
...
...
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