From bc2ac9fc925e25644aa5662d87ac4d80b2befa4a Mon Sep 17 00:00:00 2001
From: Vermaas <vermaas@astron.nl>
Date: Fri, 7 Jul 2023 09:34:59 +0200
Subject: [PATCH] add status count of jobs per task in details screen

---
 atdb/taskdatabase/models.py                   | 20 +++++++++++++++++++
 .../templates/taskdatabase/index.html         |  2 +-
 .../taskdatabase/tasks/details_card.html      |  2 +-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/atdb/taskdatabase/models.py b/atdb/taskdatabase/models.py
index 03682219..655e0487 100644
--- a/atdb/taskdatabase/models.py
+++ b/atdb/taskdatabase/models.py
@@ -159,6 +159,25 @@ class Task(models.Model):
     def get_absolute_url(self):
         return reverse('task-detail-view-api', kwargs={'pk': self.pk})
 
+    def get_jobs_statusses(self):
+        statusses = {}
+
+        # check the statusses of all the jobs of this id
+        jobs = Job.objects.filter(task_id=self.id)
+        for job in jobs:
+
+            try:
+                key = job.metadata['status'].lower()
+                # if key doesn't exist, add a new one
+                statusses.update({ key : 0 })
+                statusses[key] = statusses[key] + 1
+
+            except:
+                pass
+
+        return statusses
+
+
     @property
     def predecessor_status(self):
         try:
@@ -382,6 +401,7 @@ class Job(models.Model):
         except:
             return "N/A"
 
+
 class PostProcessingRule(models.Model):
     aggregation_key = models.CharField(db_index=True, max_length=20, default=None,null=True, blank=True)
     trigger_status = models.CharField(db_index=True, default="unknown", max_length=50, blank=True, null=True)
diff --git a/atdb/taskdatabase/templates/taskdatabase/index.html b/atdb/taskdatabase/templates/taskdatabase/index.html
index fd59a14c..60080c6d 100644
--- a/atdb/taskdatabase/templates/taskdatabase/index.html
+++ b/atdb/taskdatabase/templates/taskdatabase/index.html
@@ -31,7 +31,7 @@
             {% include 'taskdatabase/pagination.html' %}
         </div>
     </div>
-    <p class="footer"> Version 6 July 2023
+    <p class="footer"> Version 7 July 2023
 </div>
 
 {% include 'taskdatabase/refresh.html' %}
diff --git a/atdb/taskdatabase/templates/taskdatabase/tasks/details_card.html b/atdb/taskdatabase/templates/taskdatabase/tasks/details_card.html
index dd881292..1d527849 100644
--- a/atdb/taskdatabase/templates/taskdatabase/tasks/details_card.html
+++ b/atdb/taskdatabase/templates/taskdatabase/tasks/details_card.html
@@ -5,7 +5,7 @@
            <table class="table table-striped">
                <tbody>
                 <tr><td><b>id</b></td><td><a href="{% url 'task-detail-view-api' task.pk %}" target="_blank">{{ task.id }} </a></td></tr>
-                <tr><td><b>slurm jobs</b></td><td><a href="{% url 'job-list-view-api' %}?task_id={{ task.id }}" {{ task.id }} target="_blank">jobs for task {{ task.id }} </a></td></tr>
+                <tr><td><b>slurm jobs</b></td><td><a href="{% url 'job-list-view-api' %}?task_id={{ task.id }}" {{ task.id }} target="_blank">jobs for task {{ task.id }} </a> {{ task.get_jobs_statusses }}</td></tr>
 
                 <tr><td><b>priority</b></td><td>
                     {% if user.is_authenticated %}
-- 
GitLab