Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
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
d579a218
authored
May 29, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: basic vm list filtering
note: no buttons or links yet, only view
parent
fcf88559
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
2 deletions
+23
-2
circle/dashboard/views.py
+23
-2
No files found.
circle/dashboard/views.py
View file @
d579a218
...
...
@@ -102,6 +102,20 @@ class SuccessMessageMixin(object):
return
self
.
success_message
%
cleaned_data
class
FilterMixin
(
object
):
def
get_queryset_filters
(
self
):
filters
=
{}
for
item
in
self
.
allowed_filters
:
if
item
in
self
.
request
.
GET
:
filters
[
self
.
allowed_filters
[
item
]]
=
self
.
request
.
GET
[
item
]
return
filters
def
get_queryset
(
self
):
return
super
(
FilterMixin
,
self
)
.
get_queryset
()
.
filter
(
**
self
.
get_queryset_filters
())
class
IndexView
(
LoginRequiredMixin
,
TemplateView
):
template_name
=
"dashboard/index.html"
...
...
@@ -1098,8 +1112,14 @@ class TemplateDelete(LoginRequiredMixin, DeleteView):
return
HttpResponseRedirect
(
success_url
)
class
VmList
(
LoginRequiredMixin
,
ListView
):
class
VmList
(
LoginRequiredMixin
,
FilterMixin
,
ListView
):
template_name
=
"dashboard/vm-list.html"
allowed_filters
=
{
'name'
:
"name__icontains"
,
'node'
:
"node__name__icontains"
,
'status'
:
"status__iexact"
,
'tags'
:
"tags__name__in"
,
# note: use it as ?tags[]=a,b
}
def
get
(
self
,
*
args
,
**
kwargs
):
if
self
.
request
.
is_ajax
():
...
...
@@ -1138,7 +1158,8 @@ class VmList(LoginRequiredMixin, ListView):
(
sort
[
1
:]
if
sort
[
0
]
==
"-"
else
sort
)
in
[
i
.
name
for
i
in
Instance
.
_meta
.
fields
]
+
[
"pk"
]):
queryset
=
queryset
.
order_by
(
sort
)
return
queryset
.
select_related
(
'owner'
,
'node'
)
return
queryset
.
filter
(
**
self
.
get_queryset_filters
()
)
.
select_related
(
'owner'
,
'node'
)
class
NodeList
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SingleTableView
):
...
...
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