Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
b8c96939
authored
Mar 05, 2014
by
Oláh István Gergely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add trait with view
parent
2972e5cb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
34 deletions
+101
-34
circle/dashboard/forms.py
+14
-2
circle/dashboard/templates/dashboard/node-add-trait.html
+31
-0
circle/dashboard/templates/dashboard/node-detail-home.html
+11
-9
circle/dashboard/urls.py
+3
-1
circle/dashboard/views.py
+42
-22
No files found.
circle/dashboard/forms.py
View file @
b8c96939
...
@@ -815,8 +815,20 @@ class TraitForm(forms.ModelForm):
...
@@ -815,8 +815,20 @@ class TraitForm(forms.ModelForm):
self
.
helper
.
form_show_labels
=
False
self
.
helper
.
form_show_labels
=
False
self
.
helper
.
layout
=
Layout
(
self
.
helper
.
layout
=
Layout
(
Div
(
Div
(
'name'
,
Div
(
css_class
=
"col-sm-2"
,
Field
(
'name'
,
id
=
"node-details-traits-input"
,
css_class
=
"input-sm input-traits"
),
Div
(
HTML
(
'<input type="submit" '
'class="btn btn-default btn-sm input-traits" '
'value="Add trait"/>'
,
),
css_class
=
"input-group-btn"
,
),
css_class
=
"input-group"
,
id
=
"node-details-traits-form"
,
),
css_class
=
"row"
,
),
),
)
)
...
...
circle/dashboard/templates/dashboard/node-add-trait.html
0 → 100644
View file @
b8c96939
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block content %}
<style>
.help-block
{
display
:
none
;
}
.row
{
margin-bottom
:
15px
;
}
</style>
<div
class=
"row"
>
<div
class=
"col-md-12"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<h3
class=
"no-margin"
><i
class=
"icon-plus"
></i>
{% trans "Add Trait" %}
</h3>
</div>
<div
class=
"panel-body"
>
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% crispy form %}
</div>
</div>
</div>
</div>
{% endblock %}
circle/dashboard/templates/dashboard/node-detail-home.html
View file @
b8c96939
...
@@ -21,15 +21,17 @@
...
@@ -21,15 +21,17 @@
<small>
{% trans "No trait added!" %}
</small>
<small>
{% trans "No trait added!" %}
</small>
{% endif %}
{% endif %}
</div>
</div>
<form
action=
""
method=
"POST"
>
{% load crispy_forms_tags %}
{% csrf_token %}
<style>
<div
class=
"input-group"
id=
"node-details-traits-form"
>
.row
{
<input
type=
"text"
class=
"form-control input-sm input-traits"
name=
"new_trait"
id=
"node-details-traits-input"
/>
margin-bottom
:
15px
;
<div
class=
"input-group-btn"
>
}
<input
type=
"submit"
class=
"btn btn-default btn-sm input-traits"
value=
"{% trans "
Add
trait
"
%}"
/>
</style>
</div>
</div>
<form
action=
"{% url "
dashboard
.
views
.
node-addtrait
"
node
.
pk
%}"
method=
"POST"
>
</form>
{% csrf_token %}
{% crispy trait_form %}
</form>
</div>
<!-- id:node-details-traits -->
</div>
<!-- id:node-details-traits -->
</div>
</div>
<div
class=
"col-md-8"
>
<div
class=
"col-md-8"
>
...
...
circle/dashboard/urls.py
View file @
b8c96939
...
@@ -8,7 +8,7 @@ from .views import (
...
@@ -8,7 +8,7 @@ from .views import (
TemplateList
,
LeaseDetail
,
NodeCreate
,
LeaseCreate
,
TemplateCreate
,
TemplateList
,
LeaseDetail
,
NodeCreate
,
LeaseCreate
,
TemplateCreate
,
FavouriteView
,
NodeStatus
,
GroupList
,
TemplateDelete
,
LeaseDelete
,
FavouriteView
,
NodeStatus
,
GroupList
,
TemplateDelete
,
LeaseDelete
,
VmGraphView
,
TemplateAclUpdateView
,
GroupDetailView
,
GroupDelete
,
VmGraphView
,
TemplateAclUpdateView
,
GroupDetailView
,
GroupDelete
,
GroupAclUpdateView
,
GroupUserDelete
,
GroupAclUpdateView
,
GroupUserDelete
,
NodeAddTraitView
,
)
)
urlpatterns
=
patterns
(
urlpatterns
=
patterns
(
...
@@ -52,6 +52,8 @@ urlpatterns = patterns(
...
@@ -52,6 +52,8 @@ urlpatterns = patterns(
url
(
r'^node/list/$'
,
NodeList
.
as_view
(),
name
=
'dashboard.views.node-list'
),
url
(
r'^node/list/$'
,
NodeList
.
as_view
(),
name
=
'dashboard.views.node-list'
),
url
(
r'^node/(?P<pk>\d+)/$'
,
NodeDetailView
.
as_view
(),
url
(
r'^node/(?P<pk>\d+)/$'
,
NodeDetailView
.
as_view
(),
name
=
'dashboard.views.node-detail'
),
name
=
'dashboard.views.node-detail'
),
url
(
r'^node/(?P<pk>\d+)/add-trait/$'
,
NodeAddTraitView
.
as_view
(),
name
=
'dashboard.views.node-addtrait'
),
url
(
r'^tx/$'
,
TransferOwnershipConfirmView
.
as_view
(),
url
(
r'^tx/$'
,
TransferOwnershipConfirmView
.
as_view
(),
name
=
'dashboard.views.vm-transfer-ownership-confirm'
),
name
=
'dashboard.views.vm-transfer-ownership-confirm'
),
url
(
r'^node/delete/(?P<pk>\d+)/$'
,
NodeDelete
.
as_view
(),
url
(
r'^node/delete/(?P<pk>\d+)/$'
,
NodeDelete
.
as_view
(),
...
...
circle/dashboard/views.py
View file @
b8c96939
...
@@ -29,11 +29,12 @@ from braces.views import LoginRequiredMixin, SuperuserRequiredMixin
...
@@ -29,11 +29,12 @@ from braces.views import LoginRequiredMixin, SuperuserRequiredMixin
from
.forms
import
(
from
.forms
import
(
VmCreateForm
,
TemplateForm
,
LeaseForm
,
NodeForm
,
HostForm
,
DiskAddForm
,
VmCreateForm
,
TemplateForm
,
LeaseForm
,
NodeForm
,
HostForm
,
DiskAddForm
,
TraitForm
,
)
)
from
.tables
import
(
VmListTable
,
NodeListTable
,
NodeVmListTable
,
from
.tables
import
(
VmListTable
,
NodeListTable
,
NodeVmListTable
,
TemplateListTable
,
LeaseListTable
,
GroupListTable
,)
TemplateListTable
,
LeaseListTable
,
GroupListTable
,)
from
vm.models
import
(
Instance
,
InstanceTemplate
,
InterfaceTemplate
,
from
vm.models
import
(
Instance
,
InstanceTemplate
,
InterfaceTemplate
,
InstanceActivity
,
Node
,
instance_activity
,
Lease
,
InstanceActivity
,
Node
,
Trait
,
instance_activity
,
Lease
,
Interface
,
NodeActivity
,
)
Interface
,
NodeActivity
,
)
from
firewall.models
import
Vlan
,
Host
,
Rule
from
firewall.models
import
Vlan
,
Host
,
Rule
from
storage.models
import
Disk
from
storage.models
import
Disk
...
@@ -439,8 +440,12 @@ class VmDetailView(CheckedDetailView):
...
@@ -439,8 +440,12 @@ class VmDetailView(CheckedDetailView):
class
NodeDetailView
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
DetailView
):
class
NodeDetailView
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
DetailView
):
template_name
=
"dashboard/node-detail.html"
template_name
=
"dashboard/node-detail.html"
model
=
Node
model
=
Node
form
=
None
form_class
=
TraitForm
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
form
=
None
,
**
kwargs
):
if
form
is
None
:
form
=
self
.
form_class
()
context
=
super
(
NodeDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
context
=
super
(
NodeDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
instances
=
Instance
.
active
.
filter
(
node
=
self
.
object
)
instances
=
Instance
.
active
.
filter
(
node
=
self
.
object
)
context
[
'table'
]
=
NodeVmListTable
(
instances
)
context
[
'table'
]
=
NodeVmListTable
(
instances
)
...
@@ -448,6 +453,7 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
...
@@ -448,6 +453,7 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
node
=
self
.
object
,
parent
=
None
node
=
self
.
object
,
parent
=
None
)
.
order_by
(
'-started'
)
.
select_related
()
)
.
order_by
(
'-started'
)
.
select_related
()
context
[
'activities'
]
=
ia
context
[
'activities'
]
=
ia
context
[
'trait_form'
]
=
form
return
context
return
context
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
...
@@ -455,8 +461,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
...
@@ -455,8 +461,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return
self
.
__set_name
(
request
)
return
self
.
__set_name
(
request
)
if
request
.
POST
.
get
(
'new_status'
):
if
request
.
POST
.
get
(
'new_status'
):
return
self
.
__set_status
(
request
)
return
self
.
__set_status
(
request
)
if
request
.
POST
.
get
(
'new_trait'
):
return
self
.
__add_trait
(
request
)
if
request
.
POST
.
get
(
'to_remove'
):
if
request
.
POST
.
get
(
'to_remove'
):
return
self
.
__remove_trait
(
request
)
return
self
.
__remove_trait
(
request
)
...
@@ -508,24 +512,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
...
@@ -508,24 +512,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return
redirect
(
reverse_lazy
(
"dashboard.views.node-detail"
,
return
redirect
(
reverse_lazy
(
"dashboard.views.node-detail"
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}))
kwargs
=
{
'pk'
:
self
.
object
.
pk
}))
def
__add_trait
(
self
,
request
):
new_trait_name
=
request
.
POST
.
get
(
'new_trait'
)
self
.
object
=
self
.
get_object
()
if
len
(
new_trait_name
)
<
1
:
message
=
u"Please input something!"
elif
len
(
new_trait_name
)
>
20
:
message
=
u"Trait name is too long!"
else
:
self
.
object
.
traits
.
create
(
name
=
new_trait_name
)
try
:
messages
.
error
(
request
,
message
)
except
:
pass
return
redirect
(
self
.
object
.
get_absolute_url
())
def
__remove_trait
(
self
,
request
):
def
__remove_trait
(
self
,
request
):
try
:
try
:
to_remove
=
request
.
POST
.
get
(
'to_remove'
)
to_remove
=
request
.
POST
.
get
(
'to_remove'
)
...
@@ -1230,6 +1216,40 @@ class NodeDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
...
@@ -1230,6 +1216,40 @@ class NodeDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
return
reverse_lazy
(
'dashboard.index'
)
return
reverse_lazy
(
'dashboard.index'
)
class
NodeAddTraitView
(
SuperuserRequiredMixin
,
DetailView
):
model
=
Node
template_name
=
"dashboard/node-add-trait.html"
def
get_success_url
(
self
):
next
=
self
.
request
.
GET
.
get
(
'next'
)
if
next
:
return
next
else
:
return
reverse_lazy
(
"dashboard.views.node-detail"
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
def
get_context_data
(
self
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
context
=
super
(
NodeAddTraitView
,
self
)
.
get_context_data
(
**
kwargs
)
context
[
'form'
]
=
(
TraitForm
(
self
.
request
.
POST
)
if
self
.
request
.
POST
else
TraitForm
())
return
context
def
post
(
self
,
request
,
pk
,
*
args
,
**
kwargs
):
context
=
self
.
get_context_data
(
**
kwargs
)
form
=
context
[
'form'
]
if
form
.
is_valid
():
node
=
self
.
object
n
=
form
.
cleaned_data
[
'name'
]
trait
,
created
=
Trait
.
objects
.
get_or_create
(
name
=
n
)
node
.
traits
.
add
(
trait
)
success_message
=
_
(
"Trait successfully added to node."
)
messages
.
success
(
request
,
success_message
)
return
redirect
(
self
.
get_success_url
())
else
:
return
self
.
get
(
self
,
request
,
pk
,
*
args
,
**
kwargs
)
class
NodeStatus
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
DetailView
):
class
NodeStatus
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
DetailView
):
template_name
=
"dashboard/confirm/node-status.html"
template_name
=
"dashboard/confirm/node-status.html"
model
=
Node
model
=
Node
...
...
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