summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/tables.py
diff options
context:
space:
mode:
authorElliot Smith <elliot.smith@intel.com>2016-01-15 13:01:03 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-15 16:30:01 +0000
commit059a274aa96ced872156806936f887969980dda6 (patch)
tree8494b689ce4ad1226fbf79b67b2e9189bf8640d5 /bitbake/lib/toaster/toastergui/tables.py
parent4103e0cb748888d83a5a892b5a022d633846bce8 (diff)
downloadpoky-059a274aa96ced872156806936f887969980dda6.tar.gz
bitbake: toastergui: fix error and warning counts for builds
The error and warning counts displayed for builds were counts of the errors and warnings objects associated with a build. Because these values were being derived on the fly, it was not possible to sort by them. Previously, the 3rd party django-aggregate-if library was used to add aggregate fields to Build objects and should then have been used to populate the "all builds" and "project builds" tables. However, at some point the templates had changed so that the error and warning counts were coming from the properties on the Build model and not from these aggregates. This meant that it was not possible to sort by these fields. Django 1.8 supports conditional aggregates in annotation fields on querysets. This means we can remove django-aggregate-if, use the new Django 1.8 feature to derive errors_no and warnings_no fields as annotations, then use those annotation fields in the templates. This makes the "builds" tables sortable again. [YOCTO #8738] (Bitbake rev: 9be7c5c18b325f6ed40bc431ac408db242007eb1) Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/tables.py')
-rw-r--r--bitbake/lib/toaster/toastergui/tables.py40
1 files changed, 27 insertions, 13 deletions
diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py
index 14077e10ae..227973114c 100644
--- a/bitbake/lib/toaster/toastergui/tables.py
+++ b/bitbake/lib/toaster/toastergui/tables.py
@@ -23,7 +23,7 @@ from toastergui.widgets import ToasterTable
23from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project 23from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project
24from orm.models import CustomImageRecipe, Package, Build, LogMessage, Task 24from orm.models import CustomImageRecipe, Package, Build, LogMessage, Task
25from orm.models import ProjectTarget 25from orm.models import ProjectTarget
26from django.db.models import Q, Max, Count 26from django.db.models import Q, Max, Count, When, Case, Value, IntegerField
27from django.conf.urls import url 27from django.conf.urls import url
28from django.core.urlresolvers import reverse, resolve 28from django.core.urlresolvers import reverse, resolve
29from django.http import HttpResponse 29from django.http import HttpResponse
@@ -927,6 +927,13 @@ class BuildsTable(ToasterTable):
927 return context 927 return context
928 928
929 def setup_queryset(self, *args, **kwargs): 929 def setup_queryset(self, *args, **kwargs):
930 """
931 The queryset is annotated so that it can be sorted by number of
932 errors and number of warnings; but note that the criteria for
933 finding the log messages to populate these fields should match those
934 used in the Build model (orm/models.py) to populate the errors and
935 warnings properties
936 """
930 queryset = self.get_builds() 937 queryset = self.get_builds()
931 938
932 # don't include in progress builds 939 # don't include in progress builds
@@ -935,20 +942,27 @@ class BuildsTable(ToasterTable):
935 # sort 942 # sort
936 queryset = queryset.order_by(self.default_orderby) 943 queryset = queryset.order_by(self.default_orderby)
937 944
938 # annotate with number of ERROR and EXCEPTION log messages 945 # annotate with number of ERROR, EXCEPTION and CRITICAL log messages
946 criteria = (Q(logmessage__level=LogMessage.ERROR) |
947 Q(logmessage__level=LogMessage.EXCEPTION) |
948 Q(logmessage__level=LogMessage.CRITICAL))
949
939 queryset = queryset.annotate( 950 queryset = queryset.annotate(
940 errors_no = Count( 951 errors_no=Count(
941 'logmessage', 952 Case(
942 only = Q(logmessage__level=LogMessage.ERROR) | 953 When(criteria, then=Value(1)),
943 Q(logmessage__level=LogMessage.EXCEPTION) 954 output_field=IntegerField()
955 )
944 ) 956 )
945 ) 957 )
946 958
947 # annotate with number of WARNING log messages 959 # annotate with number of WARNING log messages
948 queryset = queryset.annotate( 960 queryset = queryset.annotate(
949 warnings_no = Count( 961 warnings_no=Count(
950 'logmessage', 962 Case(
951 only = Q(logmessage__level=LogMessage.WARNING) 963 When(logmessage__level=LogMessage.WARNING, then=Value(1)),
964 output_field=IntegerField()
965 )
952 ) 966 )
953 ) 967 )
954 968
@@ -1020,17 +1034,17 @@ class BuildsTable(ToasterTable):
1020 ''' 1034 '''
1021 1035
1022 errors_template = ''' 1036 errors_template = '''
1023 {% if data.errors.count %} 1037 {% if data.errors_no %}
1024 <a class="errors.count error" href="{% url "builddashboard" data.id %}#errors"> 1038 <a class="errors.count error" href="{% url "builddashboard" data.id %}#errors">
1025 {{data.errors.count}} error{{data.errors.count|pluralize}} 1039 {{data.errors_no}} error{{data.errors_no|pluralize}}
1026 </a> 1040 </a>
1027 {% endif %} 1041 {% endif %}
1028 ''' 1042 '''
1029 1043
1030 warnings_template = ''' 1044 warnings_template = '''
1031 {% if data.warnings.count %} 1045 {% if data.warnings_no %}
1032 <a class="warnings.count warning" href="{% url "builddashboard" data.id %}#warnings"> 1046 <a class="warnings.count warning" href="{% url "builddashboard" data.id %}#warnings">
1033 {{data.warnings.count}} warning{{data.warnings.count|pluralize}} 1047 {{data.warnings_no}} warning{{data.warnings_no|pluralize}}
1034 </a> 1048 </a>
1035 {% endif %} 1049 {% endif %}
1036 ''' 1050 '''