[yocto] [layerindex-web][PATCH 5/5] Include errors/warnings in main log in error/warning counts for updates

Paul Eggleton paul.eggleton at linux.intel.com
Tue Aug 14 06:32:18 PDT 2018


When showing the error/warning counts for update records we need to
include any errors/warnings that are shown only in the main update log,
so we need to adjust how these are collected. Use a function rather than
pure aggregation to give a bit more control, and a {% with ... %} block
in the template to avoid the functions being called more than necessary.

Signed-off-by: Paul Eggleton <paul.eggleton at linux.intel.com>
---
 layerindex/models.py                 | 8 ++++++++
 layerindex/views.py                  | 2 +-
 templates/layerindex/updatelist.html | 6 ++++--
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/layerindex/models.py b/layerindex/models.py
index 0dc4bd7c..379fdb6b 100644
--- a/layerindex/models.py
+++ b/layerindex/models.py
@@ -98,6 +98,14 @@ class Update(models.Model):
     task_id = models.CharField(max_length=50, blank=True, db_index=True)
     triggered_by = models.ForeignKey(User, blank=True, null=True, on_delete=models.SET_NULL)
 
+    def error_count(self):
+        sums = self.layerupdate_set.aggregate(errors=models.Sum('errors'))
+        return (sums['errors'] or 0) + self.log.count('ERROR:')
+
+    def warning_count(self):
+        sums = self.layerupdate_set.aggregate(warnings=models.Sum('warnings'))
+        return (sums['warnings'] or 0) + self.log.count('WARNING:')
+
     def __str__(self):
         return '%s' % self.started
 
diff --git a/layerindex/views.py b/layerindex/views.py
index 69165c48..8adebed9 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -708,7 +708,7 @@ class UpdateListView(ListView):
     paginate_by = 50
 
     def get_queryset(self):
-        return Update.objects.all().order_by('-started').annotate(errors=Sum('layerupdate__errors'), warnings=Sum('layerupdate__warnings'))
+        return Update.objects.all().order_by('-started')
 
 
 class UpdateDetailView(DetailView):
diff --git a/templates/layerindex/updatelist.html b/templates/layerindex/updatelist.html
index d58d175b..5a207ce8 100644
--- a/templates/layerindex/updatelist.html
+++ b/templates/layerindex/updatelist.html
@@ -35,12 +35,14 @@
 
             <tbody>
                 {% for update in updates %}
+                {% with error_count=update.error_count warning_count=update.warning_count %}
                 <tr>
                     <td><a href="{% url 'update' update.id %}">{{ update.started }}{% if update.reload %} (reload){% endif %}</a></td>
                     <td>{% if update.finished %}{{ update.started|timesince2:update.finished }}{% else %}(in progress){% endif %}</td>
-                    <td>{% if update.errors %}<span class="badge badge-important">{{ update.errors }}</span>{% endif %}</td>
-                    <td>{% if update.warnings %}<span class="badge badge-warning">{{ update.warnings }}</span>{% endif %}</td>
+                    <td>{% if error_count %}<span class="badge badge-important">{{ error_count }}</span>{% endif %}</td>
+                    <td>{% if warning_count %}<span class="badge badge-warning">{{ warning_count }}</span>{% endif %}</td>
                 </tr>
+                {% endwith %}
                 {% endfor %}
 
             </tbody>
-- 
2.17.1



More information about the yocto mailing list