Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
a4126adf
authored
Jun 06, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add FormOperationMixin
parent
e4141022
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
4 deletions
+37
-4
circle/dashboard/templates/dashboard/operate.html
+6
-1
circle/dashboard/views.py
+31
-3
No files found.
circle/dashboard/templates/dashboard/operate.html
View file @
a4126adf
{% load i18n %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block question %}
{% block question %}
<p>
<p>
...
@@ -10,7 +11,11 @@ Do you want to do the following operation on {{obj}}:
...
@@ -10,7 +11,11 @@ Do you want to do the following operation on {{obj}}:
<p
class=
"text-info"
>
{{op.name}}: {{op.description}}
</p>
<p
class=
"text-info"
>
{{op.name}}: {{op.description}}
</p>
{% endblock %}
{% endblock %}
<form
method=
"POST"
action=
"{{url}}"
>
{% csrf_token %}
<form
method=
"POST"
action=
"{{url}}"
>
{% csrf_token %}
{% block formfields %}{% endblock %}
{% block formfields %}
{% if form %}
{% crispy form %}
{% endif %}
{% endblock %}
<div
class=
"pull-right"
>
<div
class=
"pull-right"
>
<a
class=
"btn btn-default"
href=
"{{object.get_absolute_url}}"
<a
class=
"btn btn-default"
href=
"{{object.get_absolute_url}}"
data-dismiss=
"modal"
>
{% trans "Cancel" %}
</a>
data-dismiss=
"modal"
>
{% trans "Cancel" %}
</a>
...
...
circle/dashboard/views.py
View file @
a4126adf
...
@@ -258,11 +258,13 @@ class VmDetailView(CheckedDetailView):
...
@@ -258,11 +258,13 @@ class VmDetailView(CheckedDetailView):
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
VmDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
context
=
super
(
VmDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
instance
=
context
[
'instance'
]
instance
=
context
[
'instance'
]
ops
=
get_operations
(
instance
,
self
.
request
.
user
)
context
.
update
({
context
.
update
({
'graphite_enabled'
:
VmGraphView
.
get_graphite_url
()
is
not
None
,
'graphite_enabled'
:
VmGraphView
.
get_graphite_url
()
is
not
None
,
'vnc_url'
:
reverse_lazy
(
"dashboard.views.detail-vnc"
,
'vnc_url'
:
reverse_lazy
(
"dashboard.views.detail-vnc"
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}),
kwargs
=
{
'pk'
:
self
.
object
.
pk
}),
'ops'
:
get_operations
(
instance
,
self
.
request
.
user
),
'ops'
:
ops
,
'op'
:
{
i
.
op
:
i
for
i
in
ops
},
})
})
# activity data
# activity data
...
@@ -501,6 +503,7 @@ class VmDetailView(CheckedDetailView):
...
@@ -501,6 +503,7 @@ class VmDetailView(CheckedDetailView):
class
OperationView
(
DetailView
):
class
OperationView
(
DetailView
):
template_name
=
'dashboard/operate.html'
template_name
=
'dashboard/operate.html'
show_in_toolbar
=
True
@property
@property
def
name
(
self
):
def
name
(
self
):
...
@@ -575,6 +578,30 @@ class VmOperationView(OperationView):
...
@@ -575,6 +578,30 @@ class VmOperationView(OperationView):
context_object_name
=
'instance'
# much simpler to mock object
context_object_name
=
'instance'
# much simpler to mock object
class
FormOperationMixin
(
object
):
form_class
=
None
def
get_context_data
(
self
,
**
kwargs
):
ctx
=
super
(
FormOperationMixin
,
self
)
.
get_context_data
(
**
kwargs
)
if
self
.
request
.
method
==
'POST'
:
ctx
[
'form'
]
=
self
.
form_class
(
self
.
request
.
POST
)
else
:
ctx
[
'form'
]
=
self
.
form_class
()
return
ctx
def
post
(
self
,
request
,
extra
=
None
,
*
args
,
**
kwargs
):
if
extra
is
None
:
extra
=
{}
form
=
self
.
form_class
(
self
.
request
.
POST
)
if
form
.
is_valid
():
extra
.
update
(
form
.
cleaned_data
)
return
super
(
FormOperationMixin
,
self
)
.
post
(
request
,
extra
,
*
args
,
**
kwargs
)
else
:
return
self
.
get
(
request
)
class
VmMigrateView
(
VmOperationView
):
class
VmMigrateView
(
VmOperationView
):
op
=
'migrate'
op
=
'migrate'
...
@@ -638,8 +665,9 @@ def get_operations(instance, user):
...
@@ -638,8 +665,9 @@ def get_operations(instance, user):
op
=
v
.
get_op_by_object
(
instance
)
op
=
v
.
get_op_by_object
(
instance
)
op
.
check_auth
(
user
)
op
.
check_auth
(
user
)
op
.
check_precond
()
op
.
check_precond
()
except
:
except
Exception
as
e
:
pass
# unavailable
logger
.
debug
(
'Not showing operation
%
s for
%
s:
%
s'
,
k
,
instance
,
unicode
(
e
))
else
:
else
:
ops
.
append
(
v
.
bind_to_object
(
instance
))
ops
.
append
(
v
.
bind_to_object
(
instance
))
return
ops
return
ops
...
...
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