From 7255dcb8372708279057a4a2ae3f4ae72c2e9eab Mon Sep 17 00:00:00 2001
From: Nico Vermaas <vermaas@astron.nl>
Date: Thu, 21 Apr 2022 12:46:18 +0200
Subject: [PATCH] bugfix error 500 when click service hold/resume button

---
 atdb/taskdatabase/services/algorithms.py | 4 ++--
 atdb/taskdatabase/urls.py                | 3 ++-
 atdb/taskdatabase/views.py               | 4 ++--
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/atdb/taskdatabase/services/algorithms.py b/atdb/taskdatabase/services/algorithms.py
index 62fe1b7b..eb0a0d45 100644
--- a/atdb/taskdatabase/services/algorithms.py
+++ b/atdb/taskdatabase/services/algorithms.py
@@ -287,9 +287,9 @@ def convert_monitor_to_html(request, monitor_data):
             # only provide the hold/resume buttons for superusers, otherwise just show the state
             if request.user.is_superuser:
                 if record.enabled=="True":
-                    service_enabled = str(record.enabled) + '&nbsp;&nbsp; <a href="service_hold_resume/' + str(record.pk) + '/False"' + 'class="btn btn-warning btn-sm" role="button"><i class="fas fa-pause"></i> Hold</a>'
+                    service_enabled = str(record.enabled) + '&nbsp;&nbsp; <a href="service_hold_resume/' + record.name + '/' + record.hostname + '/False"' + 'class="btn btn-warning btn-sm" role="button"><i class="fas fa-pause"></i> Hold</a>'
                 else:
-                    service_enabled = str(record.enabled) + '&nbsp;&nbsp; <a href="service_hold_resume/' + str(record.pk) + '/True"' + 'class="btn btn-success btn-sm" role="button"><i class="fas fa-play"></i> Resume</a>'
+                    service_enabled = str(record.enabled) + '&nbsp;&nbsp; <a href="service_hold_resume/' + record.name + '/' + record.hostname + '/True"' + 'class="btn btn-success btn-sm" role="button"><i class="fas fa-play"></i> Resume</a>'
             else:
                 service_enabled = str(record.enabled)
 
diff --git a/atdb/taskdatabase/urls.py b/atdb/taskdatabase/urls.py
index e55c0c03..4c2fb8db 100644
--- a/atdb/taskdatabase/urls.py
+++ b/atdb/taskdatabase/urls.py
@@ -72,7 +72,8 @@ urlpatterns = [
     path('monitor/<int:pk>/', views.MonitorDetailsViewAPI.as_view(),name='monitor-detail-view-api'),
     path('latest_monitor/', views.LatestMonitorListViewAPI.as_view(),name='latest-monitor-detail-view-api'),
     path('monitor/clear_inactive_services/', views.ClearInactiveServices, name='clear-inactive-services'),
-    path('monitoring/service_hold_resume/<int:pk>/<enabled>', views.ServiceHoldResume, name='service-hold-resume'),
+    # path('monitoring/service_hold_resume/<int:pk>/<enabled>', views.ServiceHoldResume, name='service-hold-resume'),
+    path('monitoring/service_hold_resume/<name>/<hostname>/<enabled>', views.ServiceHoldResume, name='service-hold-resume'),
 
     # --- custom requests ---
     # /atdb/get_size?status__in=defined,staged
diff --git a/atdb/taskdatabase/views.py b/atdb/taskdatabase/views.py
index f6775feb..02b3fbf6 100644
--- a/atdb/taskdatabase/views.py
+++ b/atdb/taskdatabase/views.py
@@ -953,9 +953,9 @@ def HoldQuery(request, pk, hold_it, query_params):
     return redirect('/atdb/query/?' + current_query_params)
 
 @login_required
-def ServiceHoldResume(request, pk, enabled):
+def ServiceHoldResume(request, name, hostname, enabled):
     model = LatestMonitor
-    service = LatestMonitor.objects.get(pk=pk)
+    service = LatestMonitor.objects.get(name=name,hostname=hostname)
     metadata = service.metadata
     if not metadata:
         metadata = {}
-- 
GitLab