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
c85a3779
authored
Nov 25, 2013
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: mass delete as generic View
parent
4f31c740
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
30 deletions
+32
-30
circle/dashboard/urls.py
+2
-2
circle/dashboard/views.py
+30
-28
No files found.
circle/dashboard/urls.py
View file @
c85a3779
...
@@ -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
,
VmDelete
,
mass_delete_vm
,
vm_activity
)
VmDelete
,
VmMassDelete
,
vm_activity
)
urlpatterns
=
patterns
(
urlpatterns
=
patterns
(
''
,
''
,
...
@@ -19,7 +19,7 @@ urlpatterns = patterns(
...
@@ -19,7 +19,7 @@ urlpatterns = patterns(
name
=
'dashboard.views.vm-create'
),
name
=
'dashboard.views.vm-create'
),
url
(
r'^vm/delete/(?P<pk>\d+)/$'
,
VmDelete
.
as_view
(),
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/'
,
VmMassDelete
.
as_view
()
,
name
=
'dashboard.view.mass-delete-vm'
),
name
=
'dashboard.view.mass-delete-vm'
),
url
(
r'^vm/(?P<pk>\d+)/activity/$'
,
vm_activity
)
url
(
r'^vm/(?P<pk>\d+)/activity/$'
,
vm_activity
)
)
)
circle/dashboard/views.py
View file @
c85a3779
...
@@ -332,39 +332,41 @@ class VmDelete(DeleteView):
...
@@ -332,39 +332,41 @@ class VmDelete(DeleteView):
return
reverse_lazy
(
'dashboard.index'
)
return
reverse_lazy
(
'dashboard.index'
)
def
mass_delete_vm
(
request
,
**
kwargs
):
class
VmMassDelete
(
View
):
if
request
.
method
==
"GET"
:
def
get
(
self
,
request
,
*
args
,
**
kwargs
)
:
vms
=
request
.
GET
.
getlist
(
'v[]'
)
vms
=
request
.
GET
.
getlist
(
'v[]'
)
objects
=
Instance
.
objects
.
filter
(
pk__in
=
vms
)
objects
=
Instance
.
objects
.
filter
(
pk__in
=
vms
)
return
render
(
request
,
"dashboard/confirm/mass-delete.html"
,
return
render
(
request
,
"dashboard/confirm/mass-delete.html"
,
{
'objects'
:
objects
})
{
'objects'
:
objects
})
vms
=
request
.
POST
.
getlist
(
'vms'
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
names
=
[]
vms
=
request
.
POST
.
getlist
(
'vms'
)
if
vms
is
not
None
:
names
=
[]
for
i
in
Instance
.
objects
.
filter
(
pk__in
=
vms
):
if
vms
is
not
None
:
if
not
i
.
has_level
(
request
.
user
,
'owner'
):
for
i
in
Instance
.
objects
.
filter
(
pk__in
=
vms
):
logger
.
info
(
'Tried to delete instance #
%
d without owner '
if
not
i
.
has_level
(
request
.
user
,
'owner'
):
'permission by
%
s.'
,
i
.
pk
,
unicode
(
request
.
user
))
logger
.
info
(
'Tried to delete instance #
%
d without owner '
raise
PermissionDenied
()
# no need for rollback or proper
'permission by
%
s.'
,
i
.
pk
,
# error message, this can't
unicode
(
request
.
user
))
# normally happen.
raise
PermissionDenied
()
# no need for rollback or proper
i
.
destroy_async
(
request
.
user
)
# error message, this can't
names
.
append
(
i
.
name
)
# normally happen.
i
.
destroy_async
(
request
.
user
)
success_message
=
_
(
"Mass delete complete, the following VMs were "
+
names
.
append
(
i
.
name
)
"deleted:
%
s!"
%
u', '
.
join
(
names
))
success_message
=
_
(
"Mass delete complete, the following VMs were "
+
# we can get this only via AJAX ...
"deleted:
%
s!"
%
u', '
.
join
(
names
))
if
request
.
is_ajax
():
return
HttpResponse
(
# we can get this only via AJAX ...
json
.
dumps
({
'message'
:
success_message
}),
if
request
.
is_ajax
():
content_type
=
"application/json"
return
HttpResponse
(
)
json
.
dumps
({
'message'
:
success_message
}),
else
:
content_type
=
"application/json"
messages
.
success
(
request
,
success_message
)
)
next
=
request
.
GET
.
get
(
'next'
)
else
:
return
redirect
(
next
if
next
else
reverse_lazy
(
'dashboard.index'
))
messages
.
success
(
request
,
success_message
)
next
=
request
.
GET
.
get
(
'next'
)
return
redirect
(
next
if
next
else
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