Commit c11bddba by Bach Dániel

Merge branch 'issue-fix-vm-list-filter' into 'master'

Issue Fix Vm List Filter

Filtering by tags haven't worked.
parents 86d76cc1 c62287ca
...@@ -128,7 +128,11 @@ class FilterMixin(object): ...@@ -128,7 +128,11 @@ class FilterMixin(object):
filters = {} filters = {}
for item in self.allowed_filters: for item in self.allowed_filters:
if item in self.request.GET: if item in self.request.GET:
filters[self.allowed_filters[item]] = self.request.GET[item] filters[self.allowed_filters[item]] = (
self.request.GET[item].split(",")
if self.allowed_filters[item].endswith("__in") else
self.request.GET[item])
return filters return filters
def get_queryset(self): def get_queryset(self):
...@@ -1158,7 +1162,8 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView): ...@@ -1158,7 +1162,8 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
'name': "name__icontains", 'name': "name__icontains",
'node': "node__name__icontains", 'node': "node__name__icontains",
'status': "status__iexact", 'status': "status__iexact",
'tags': "tags__name__in", # note: use it as ?tags[]=a,b 'tags[]': "tags__name__in",
'tags': "tags__name__in", # for search string
'owner': "owner__username", 'owner': "owner__username",
} }
...@@ -1197,8 +1202,10 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView): ...@@ -1197,8 +1202,10 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
(sort[1:] if sort[0] == "-" else sort) (sort[1:] if sort[0] == "-" else sort)
in [i.name for i in Instance._meta.fields] + ["pk"]): in [i.name for i in Instance._meta.fields] + ["pk"]):
queryset = queryset.order_by(sort) queryset = queryset.order_by(sort)
return queryset.filter(**self.get_queryset_filters()
).select_related('owner', 'node') return queryset.filter(
**self.get_queryset_filters()).select_related('owner', 'node'
).distinct()
def create_fake_get(self): def create_fake_get(self):
""" """
...@@ -1230,8 +1237,7 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView): ...@@ -1230,8 +1237,7 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
# generate a new GET request, that is kinda fake # generate a new GET request, that is kinda fake
fake = self.request.GET.copy() fake = self.request.GET.copy()
for k, v in got.iteritems(): for k, v in got.iteritems():
fake["%s%s" % ( fake[k] = v
k, "[]" if len(v.split(",")) > 1 else "")] = v
self.request.GET = fake self.request.GET = fake
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment