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
3b0c7f0a
authored
Nov 13, 2013
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: generic delete view for vm deletion
parent
eb728978
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
12 deletions
+51
-12
circle/dashboard/templates/dashboard/confirm/base_delete.html
+23
-0
circle/dashboard/urls.py
+2
-2
circle/dashboard/views.py
+26
-10
No files found.
circle/dashboard/templates/dashboard/confirm/base_delete.html
0 → 100644
View file @
3b0c7f0a
{% extends "dashboard/base.html" %}
{% block content %}
<div
class=
"body-content"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<h3
class=
"no-margin"
>
Delete confirmation
</h3>
</div>
<div
class=
"panel-body"
>
Are you sure you want to delete
<strong>
{{ object }}
</strong>
?
<div
class=
"pull-right"
>
<form
action=
""
method=
"POST"
>
{% csrf_token %}
<a
class=
"btn btn-default"
>
Back
</a>
<input
type=
"hidden"
name=
"next"
value=
"{{ request.GET.next }}"
/>
<button
class=
"btn btn-danger"
>
Yes, delete
</button>
</form>
</div>
</div>
</div>
{% endblock %}
circle/dashboard/urls.py
View file @
3b0c7f0a
...
...
@@ -3,7 +3,7 @@ from django.conf.urls import patterns, url
from
vm.models
import
Instance
from
.views
import
(
IndexView
,
VmDetailView
,
VmList
,
VmCreate
,
TemplateDetail
,
AclUpdateView
,
delete_vm
,
mass_delete_vm
)
VmDelete
,
mass_delete_vm
)
urlpatterns
=
patterns
(
''
,
...
...
@@ -17,7 +17,7 @@ urlpatterns = patterns(
url
(
r'^vm/list/$'
,
VmList
.
as_view
(),
name
=
'dashboard.views.vm-list'
),
url
(
r'^vm/create/$'
,
VmCreate
.
as_view
(),
name
=
'dashboard.views.vm-create'
),
url
(
r'^vm/delete/(?P<pk>\d+)/$'
,
delete_vm
,
url
(
r'^vm/delete/(?P<pk>\d+)/$'
,
VmDelete
.
as_view
()
,
name
=
"dashboard.views.delete-vm"
),
url
(
r'^vm/mass-delete/'
,
mass_delete_vm
,
name
=
'dashboard.view.mass-delete-vm'
)
...
...
circle/dashboard/views.py
View file @
3b0c7f0a
...
...
@@ -8,11 +8,11 @@ from django.contrib.messages import warning
from
django.core.exceptions
import
PermissionDenied
from
django.core
import
signing
from
django.core.urlresolvers
import
reverse
,
reverse_lazy
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
,
HttpResponseRedirect
from
django.shortcuts
import
redirect
from
django.views.decorators.http
import
require_POST
from
django.views.generic.detail
import
SingleObjectMixin
from
django.views.generic
import
TemplateView
,
DetailView
,
View
from
django.views.generic
import
TemplateView
,
DetailView
,
View
,
DeleteView
from
django.contrib
import
messages
from
django.utils.translation
import
ugettext
as
_
...
...
@@ -239,16 +239,26 @@ class VmCreate(TemplateView):
return
redirect
(
reverse_lazy
(
'dashboard.views.detail'
,
resp
))
@require_POST
def
delete_vm
(
request
,
**
kwargs
):
vm_pk
=
kwargs
[
'pk'
]
class
VmDelete
(
DeleteView
):
model
=
Instance
template_name
=
"dashboard/confirm/base_delete.html"
def
get_context_data
(
self
,
**
kwargs
):
# this is redundant now, but if we wanna add more to print
# we'll need this
context
=
super
(
VmDelete
,
self
)
.
get_context_data
(
**
kwargs
)
return
context
vm
=
Instance
.
objects
.
get
(
pk
=
vm_pk
)
if
not
vm
.
has_level
(
request
.
user
,
'owner'
):
# github.com/django/django/blob/master/django/views/generic/edit.py#L245
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
object
=
self
.
get_object
()
if
not
object
.
has_level
(
request
.
user
,
'owner'
):
raise
PermissionDenied
()
vm
.
destroy_async
()
object
.
destroy_async
()
success_url
=
self
.
get_success_url
()
success_message
=
_
(
"VM successfully deleted!"
)
if
request
.
is_ajax
():
return
HttpResponse
(
json
.
dumps
({
'message'
:
success_message
}),
...
...
@@ -256,8 +266,14 @@ def delete_vm(request, **kwargs):
)
else
:
messages
.
success
(
request
,
success_message
)
next
=
request
.
GET
.
get
(
'next'
)
return
redirect
(
next
if
next
else
reverse_lazy
(
'dashboard.index'
))
return
HttpResponseRedirect
(
success_url
)
def
get_success_url
(
self
):
next
=
self
.
request
.
POST
.
get
(
'next'
)
if
next
:
return
next
else
:
return
reverse_lazy
(
'dashboard.index'
)
@require_POST
...
...
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