Include errors/warnings in main log in error/warning counts for updates

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@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-08-14 10:13:25 +02:00
parent dafa4dc129
commit b3e9cb05d2
3 changed files with 13 additions and 3 deletions

View File

@ -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

View File

@ -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):

View File

@ -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>