From b2eb2f5a5806b99ff47fe44e7fc8b2457b98e28a Mon Sep 17 00:00:00 2001
From: Kálmán Viktor <kviktor@cloud.bme.hu>
Date: Wed, 20 Aug 2014 10:27:39 +0200
Subject: [PATCH] dashboard: fix vm list filter

---
 circle/dashboard/forms.py                      | 8 ++++----
 circle/dashboard/static/dashboard/dashboard.js | 2 +-
 circle/dashboard/views.py                      | 6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/circle/dashboard/forms.py b/circle/dashboard/forms.py
index 2cb9dc8..b74ea64 100644
--- a/circle/dashboard/forms.py
+++ b/circle/dashboard/forms.py
@@ -1133,9 +1133,9 @@ class VmResourcesForm(forms.ModelForm):
 
 
 vm_search_choices = (
-    (0, _("owned")),
-    (1, _("shared")),
-    (2, _("all")),
+    ("owned", _("owned")),
+    ("shared", _("shared")),
+    ("all", _("all")),
 )
 
 
@@ -1154,5 +1154,5 @@ class VmListSearchForm(forms.Form):
         # set initial value, otherwise it would be overwritten by request.GET
         if not self.data.get("stype"):
             data = self.data.copy()
-            data['stype'] = 2
+            data['stype'] = "all"
             self.data = data
diff --git a/circle/dashboard/static/dashboard/dashboard.js b/circle/dashboard/static/dashboard/dashboard.js
index d68d69b..9f66211 100644
--- a/circle/dashboard/static/dashboard/dashboard.js
+++ b/circle/dashboard/static/dashboard/dashboard.js
@@ -262,7 +262,7 @@ $(function () {
 
   $("#dashboard-vm-search-form").submit(function() {
     var vm_list_items = $("#dashboard-vm-list .list-group-item");
-    if(vm_list_items.length == 1) {
+    if(vm_list_items.length == 1 && vm_list_items.first().prop("href")) {
       window.location.href = vm_list_items.first().prop("href");
       return false;
     }
diff --git a/circle/dashboard/views.py b/circle/dashboard/views.py
index ab5053b..1f65ee0 100644
--- a/circle/dashboard/views.py
+++ b/circle/dashboard/views.py
@@ -1611,9 +1611,9 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
 
     def create_default_queryset(self):
         cleaned_data = self.search_form.cleaned_data
-        stype = cleaned_data.get('stype', 2)
-        superuser = stype == 2
-        shared = stype == 1
+        stype = cleaned_data.get('stype', "all")
+        superuser = stype == "all"
+        shared = stype == "shared"
         level = "owner" if stype == 0 else "user"
         queryset = Instance.get_objects_with_level(
             level, self.request.user,
--
libgit2 0.26.0