Commit e84b8b16 by Bach Dániel

dashboard: fix #400 ("VM List Enhance with inverz command" :D)

closes #400
parent e76ab3f5
...@@ -148,7 +148,11 @@ ...@@ -148,7 +148,11 @@
</div> </div>
<div class="alert alert-info"> <div class="alert alert-info">
You can filter the list by certain attributes (owner, name, status, tags) in the following way: "owner:John Doe name:my little server". If you don't specify any attribute names the filtering will be done by name. {% blocktrans %}
You can filter the list by certain attributes (owner, name, status, tags)
in the following way: "owner:John Doe name:my little server !name:test".
If you don't specify any attribute names the filtering will be done by name.
{% endblocktrans %}
</div> </div>
<div class="alert alert-info"> <div class="alert alert-info">
......
...@@ -237,7 +237,8 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView): ...@@ -237,7 +237,8 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView):
self.create_fake_get() self.create_fake_get()
try: try:
qs = qs.filter(**self.get_queryset_filters()).distinct() filters, excludes = self.get_queryset_filters()
qs = qs.filter(**filters).exclude(**excludes).distinct()
except ValueError: except ValueError:
messages.error(self.request, _("Error during filtering.")) messages.error(self.request, _("Error during filtering."))
......
...@@ -79,14 +79,24 @@ class FilterMixin(object): ...@@ -79,14 +79,24 @@ class FilterMixin(object):
def get_queryset_filters(self): def get_queryset_filters(self):
filters = {} filters = {}
for item in self.allowed_filters: excludes = {}
if item in self.request.GET:
filters[self.allowed_filters[item]] = ( for key, value in self.request.GET.items():
self.request.GET[item].split(",") exclude = key.startswith('!')
if self.allowed_filters[item].endswith("__in") else key = key.lstrip('!')
self.request.GET[item]) if key not in self.allowed_filters:
continue
filter_field = self.allowed_filters[key]
value = (value.split(",")
if filter_field.endswith("__in") else
value)
if exclude:
excludes[filter_field] = value
else:
filters[filter_field] = value
return filters return filters, excludes
def get_queryset(self): def get_queryset(self):
return super(FilterMixin, return super(FilterMixin,
...@@ -118,6 +128,9 @@ class FilterMixin(object): ...@@ -118,6 +128,9 @@ class FilterMixin(object):
>>> o = f._parse_get({'s': "name:hello ws node:node 3 oh"}).items() >>> o = f._parse_get({'s': "name:hello ws node:node 3 oh"}).items()
>>> sorted(o) # doctest: +ELLIPSIS >>> sorted(o) # doctest: +ELLIPSIS
[(u'name', u'hello ws'), (u'node', u'node 3 oh'), (...)] [(u'name', u'hello ws'), (u'node', u'node 3 oh'), (...)]
>>> o = f._parse_get({'s': "!hello:szia"}).items()
>>> sorted(o) # doctest: +ELLIPSIS
[(u'!hello', u'szia'), (...)]
""" """
s = GET_dict.get("s") s = GET_dict.get("s")
fake = GET_dict.copy() fake = GET_dict.copy()
......
...@@ -1002,7 +1002,8 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView): ...@@ -1002,7 +1002,8 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
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()).prefetch_related( filters, excludes = self.get_queryset_filters()
return queryset.filter(**filters).exclude(**excludes).prefetch_related(
"owner", "node", "owner__profile", "interface_set", "lease", "owner", "node", "owner__profile", "interface_set", "lease",
"interface_set__host").distinct() "interface_set__host").distinct()
......
...@@ -2650,6 +2650,26 @@ msgstr "IP cím" ...@@ -2650,6 +2650,26 @@ msgstr "IP cím"
msgid "No result." msgid "No result."
msgstr "Nincs eredmény." msgstr "Nincs eredmény."
#: dashboard/templates/dashboard/vm-list.html:151
msgid ""
"\n"
" You can filter the list by certain attributes (owner, name, status, tags)\n"
" in the following way: \"owner:John Doe name:my little server !name:test"
"\".\n"
" If you don't specify any attribute names the filtering will be done by "
"name.\n"
" "
msgstr ""
"\n"
" A listát szűrheti is bizonyos attribútumok (owner (tulajdonos), name (név), "
"status (állapot), tags (címkék)) szerint\n"
" a következő módon: \"owner:Gipsz Jakab name:én kicsi szerverem !name:teszt"
"\".\n"
" Ha nem ad meg egyetlen attribútumot sem, akkor a szűrés a név szerint fog "
"történni.\n"
"name.\n"
" "
#: dashboard/templates/dashboard/vm-list.html:155 #: dashboard/templates/dashboard/vm-list.html:155
msgid "" msgid ""
"You can select multiple vm instances while holding down the " "You can select multiple vm instances while holding down the "
......
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