Patchwork [bitbake-devel,37/94] bitbake: webhob: add ordering capabilities to build api

login
register
mail settings
Submitter Alexandru DAMIAN
Date Sept. 24, 2013, 4:52 p.m.
Message ID <e4e474555f58ddc71a78da96ff6269a964329899.1380041477.git.alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/58797/
State New
Headers show

Comments

Alexandru DAMIAN - Sept. 24, 2013, 4:52 p.m.
From: Calin Dragomir <calinx.l.dragomir@intel.com>

This patch adds the capability to order builds by a specific
field of the build model.
The format used is 'field_name:order' and the default ordering
is ascending.

Signed-off-by: Calin Dragomir <calinx.l.dragomir@intel.com>
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
---
 bitbake/lib/webhob/bldviewer/views.py | 9 +++++++++
 1 file changed, 9 insertions(+)

Patch

diff --git a/bitbake/lib/webhob/bldviewer/views.py b/bitbake/lib/webhob/bldviewer/views.py
index de89b84..71e95b4 100644
--- a/bitbake/lib/webhob/bldviewer/views.py
+++ b/bitbake/lib/webhob/bldviewer/views.py
@@ -56,6 +56,7 @@  from django.http import HttpResponse
 
 
 def builds(request):
+    DESCENDING = 'desc'
     response_data = {}
 
     try:
@@ -68,6 +69,7 @@  def builds(request):
     except ValueError:
         offset = 0
 
+    ordering_string = request.GET.get('orderby', '')
     filter_string = request.GET.get('filter', '')
 
     if filter_string:
@@ -91,6 +93,13 @@  def builds(request):
     else:
         response_data['count'] = 0
 
+    if queryset and ordering_string:
+        column, order = ordering_string.split(':')
+        if order.lower() == DESCENDING:
+            queryset = queryset.order_by('-' + column)
+        else:
+            queryset = queryset.order_by(column)
+
     response_data['list'] = serializers.serialize('json', queryset)
 
     return HttpResponse(json.dumps(response_data), content_type='application/json')