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
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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
21 deletions
+60
-21
circle/dashboard/templates/dashboard/confirm/base_delete.html
+23
-0
circle/dashboard/urls.py
+2
-2
circle/dashboard/views.py
+35
-19
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
...
@@ -3,7 +3,7 @@ from django.conf.urls import patterns, url
from
vm.models
import
Instance
from
vm.models
import
Instance
from
.views
import
(
from
.views
import
(
IndexView
,
VmDetailView
,
VmList
,
VmCreate
,
TemplateDetail
,
AclUpdateView
,
IndexView
,
VmDetailView
,
VmList
,
VmCreate
,
TemplateDetail
,
AclUpdateView
,
delete_vm
,
mass_delete_vm
)
VmDelete
,
mass_delete_vm
)
urlpatterns
=
patterns
(
urlpatterns
=
patterns
(
''
,
''
,
...
@@ -17,7 +17,7 @@ urlpatterns = patterns(
...
@@ -17,7 +17,7 @@ urlpatterns = patterns(
url
(
r'^vm/list/$'
,
VmList
.
as_view
(),
name
=
'dashboard.views.vm-list'
),
url
(
r'^vm/list/$'
,
VmList
.
as_view
(),
name
=
'dashboard.views.vm-list'
),
url
(
r'^vm/create/$'
,
VmCreate
.
as_view
(),
url
(
r'^vm/create/$'
,
VmCreate
.
as_view
(),
name
=
'dashboard.views.vm-create'
),
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"
),
name
=
"dashboard.views.delete-vm"
),
url
(
r'^vm/mass-delete/'
,
mass_delete_vm
,
url
(
r'^vm/mass-delete/'
,
mass_delete_vm
,
name
=
'dashboard.view.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
...
@@ -8,11 +8,11 @@ from django.contrib.messages import warning
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
PermissionDenied
from
django.core
import
signing
from
django.core
import
signing
from
django.core.urlresolvers
import
reverse
,
reverse_lazy
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.shortcuts
import
redirect
from
django.views.decorators.http
import
require_POST
from
django.views.decorators.http
import
require_POST
from
django.views.generic.detail
import
SingleObjectMixin
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.contrib
import
messages
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
...
@@ -239,25 +239,41 @@ class VmCreate(TemplateView):
...
@@ -239,25 +239,41 @@ class VmCreate(TemplateView):
return
redirect
(
reverse_lazy
(
'dashboard.views.detail'
,
resp
))
return
redirect
(
reverse_lazy
(
'dashboard.views.detail'
,
resp
))
@require_POST
class
VmDelete
(
DeleteView
):
def
delete_vm
(
request
,
**
kwargs
):
model
=
Instance
vm_pk
=
kwargs
[
'pk'
]
template_name
=
"dashboard/confirm/base_delete.html"
vm
=
Instance
.
objects
.
get
(
pk
=
vm_pk
)
def
get_context_data
(
self
,
**
kwargs
):
if
not
vm
.
has_level
(
request
.
user
,
'owner'
):
# this is redundant now, but if we wanna add more to print
raise
PermissionDenied
()
# we'll need this
vm
.
destroy_async
()
context
=
super
(
VmDelete
,
self
)
.
get_context_data
(
**
kwargs
)
return
context
success_message
=
_
(
"VM successfully deleted!"
)
# github.com/django/django/blob/master/django/views/generic/edit.py#L245
if
request
.
is_ajax
():
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
return
HttpResponse
(
object
=
self
.
get_object
()
json
.
dumps
({
'message'
:
success_message
}),
if
not
object
.
has_level
(
request
.
user
,
'owner'
):
content_type
=
"application/json"
,
raise
PermissionDenied
()
)
else
:
object
.
destroy_async
()
messages
.
success
(
request
,
success_message
)
success_url
=
self
.
get_success_url
()
next
=
request
.
GET
.
get
(
'next'
)
success_message
=
_
(
"VM successfully deleted!"
)
return
redirect
(
next
if
next
else
reverse_lazy
(
'dashboard.index'
))
if
request
.
is_ajax
():
return
HttpResponse
(
json
.
dumps
({
'message'
:
success_message
}),
content_type
=
"application/json"
,
)
else
:
messages
.
success
(
request
,
success_message
)
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
@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