Patchwork [bitbake-devel,1/5] toaster: sort outcome and sstate columns by string value

login
register
mail settings
Submitter Alexandru DAMIAN
Date May 8, 2014, 1:24 p.m.
Message ID <7fc64b40c28e09f8fe549d8d2972d5066bc1d125.1399555312.git.alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/71769/
State New
Headers show

Comments

Alexandru DAMIAN - May 8, 2014, 1:24 p.m.
From: David Reyna <David.Reyna@windriver.com>

Sort the 'outcome' and 'sstate_result' columns by their
description string values and not their numerical values.

[YOCTO #5921]

Signed-off-by: David Reyna <David.Reyna@windriver.com>
---
 lib/toaster/orm/models.py       | 12 ++++++++++++
 lib/toaster/toastergui/views.py |  9 ++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

Patch

diff --git a/lib/toaster/orm/models.py b/lib/toaster/orm/models.py
index c344c66..22c66a9 100644
--- a/lib/toaster/orm/models.py
+++ b/lib/toaster/orm/models.py
@@ -166,9 +166,18 @@  class Task(models.Model):
     def get_related_setscene(self):
         return Task.objects.related_setscene(self)
 
+    def get_outcome_text(self):
+        return Task.TASK_OUTCOME[self.outcome + 1][1]
+
     def get_outcome_help(self):
         return Task.TASK_OUTCOME_HELP[self.outcome][1]
 
+    def get_sstate_text(self):
+        if self.sstate_result==Task.SSTATE_NA:
+            return ''
+        else:
+            return Task.SSTATE_RESULT[self.sstate_result][1]
+
     def get_executed_display(self):
         if self.task_executed:
             return "Executed"
@@ -200,6 +209,9 @@  class Task(models.Model):
     message = models.CharField(max_length=240)
     logfile = models.FilePathField(max_length=255, blank=True)
 
+    outcome_text = property(get_outcome_text)
+    sstate_text  = property(get_sstate_text)
+
     class Meta:
         ordering = ('order', 'recipe' ,)
         unique_together = ('build', 'recipe', 'task_name', )
diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/views.py
index 53be967..3d2ed4c 100644
--- a/lib/toaster/toastergui/views.py
+++ b/lib/toaster/toastergui/views.py
@@ -853,7 +853,14 @@  def tasks_common(request, build_id, variant, task_anchor):
     (filter_string, search_term, ordering_string) = _search_tuple(request, Task)
     queryset_all = Task.objects.filter(build=build_id).exclude(order__isnull=True).exclude(outcome=Task.OUTCOME_NA)
     queryset_with_search = _get_queryset(Task, queryset_all, None , search_term, ordering_string, 'order')
-    queryset = _get_queryset(Task, queryset_all, filter_string, search_term, ordering_string, 'order')
+    if ordering_string.startswith('outcome'):
+        queryset = _get_queryset(Task, queryset_all, filter_string, search_term, 'order:+', 'order')
+        queryset = sorted(queryset, key=lambda ur: (ur.outcome_text), reverse=ordering_string.endswith('-'))
+    elif ordering_string.startswith('sstate_result'):
+        queryset = _get_queryset(Task, queryset_all, filter_string, search_term, 'order:+', 'order')
+        queryset = sorted(queryset, key=lambda ur: (ur.sstate_text), reverse=ordering_string.endswith('-'))
+    else:
+        queryset = _get_queryset(Task, queryset_all, filter_string, search_term, ordering_string, 'order')
 
 	# compute the anchor's page
     if anchor: