diff --git a/layerindex/models.py b/layerindex/models.py index 0dc4bd7..379fdb6 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 69165c4..8adebed 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 d58d175..5a207ce 100644 --- a/templates/layerindex/updatelist.html +++ b/templates/layerindex/updatelist.html @@ -35,12 +35,14 @@ {% for update in updates %} + {% with error_count=update.error_count warning_count=update.warning_count %} {{ update.started }}{% if update.reload %} (reload){% endif %} {% if update.finished %}{{ update.started|timesince2:update.finished }}{% else %}(in progress){% endif %} - {% if update.errors %}{{ update.errors }}{% endif %} - {% if update.warnings %}{{ update.warnings }}{% endif %} + {% if error_count %}{{ error_count }}{% endif %} + {% if warning_count %}{{ warning_count }}{% endif %} + {% endwith %} {% endfor %}