queries{% if silk_request.meta_num_queries %} +{{ silk_request.meta_num_queries }}{% endif %}
+
+
+
diff --git a/silk/templates/silk/request.html b/silk/templates/silk/request.html
index ca545874..f2caf880 100644
--- a/silk/templates/silk/request.html
+++ b/silk/templates/silk/request.html
@@ -5,6 +5,7 @@
{% block style %}
+
diff --git a/silk/views/request_detail.py b/silk/views/request_detail.py
index 6baa3adb..9e170c67 100644
--- a/silk/views/request_detail.py
+++ b/silk/views/request_detail.py
@@ -1,6 +1,6 @@
import json
-from django.shortcuts import render
+from django.shortcuts import render, redirect, HttpResponseRedirect
from django.utils.decorators import method_decorator
from django.views.generic import View
@@ -40,3 +40,13 @@ def get(self, request, request_id):
'request': request
}
return render(request, 'silk/request.html', context)
+
+ @method_decorator(login_possibly_required)
+ @method_decorator(permissions_possibly_required)
+ def post(self, request, request_id):
+ silk_request = Request.objects.get(pk=request_id)
+ try:
+ silk_request.delete()
+ except Request.DoesNotExist:
+ return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/silk'))
+ return redirect('/silk')
From e919cdd443f121256cc3b105b5edbee0d8b30d3b Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Sun, 1 Jan 2023 16:20:23 +0000
Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---
project/tests/test_delete_request.py | 11 +++++++----
silk/views/request_detail.py | 6 +++---
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/project/tests/test_delete_request.py b/project/tests/test_delete_request.py
index 2b98448c..1ce28dd3 100644
--- a/project/tests/test_delete_request.py
+++ b/project/tests/test_delete_request.py
@@ -1,7 +1,10 @@
+from http import HTTPStatus
+
from django.test import Client, TestCase
-from silk.models import Request
from django.urls import reverse
-from http import HTTPStatus
+
+from silk.models import Request
+
class TestDeleteRequest(TestCase):
def setUp(self):
@@ -11,7 +14,7 @@ def setUp(self):
self.request.method = 'get'
self.request.body = b'a' * 1000
self.request.save()
-
+
def test_delete(self):
- response = self.client.post(reverse('silk:request_detail', kwargs={'request_id':str(self.request.id)}))
+ response = self.client.post(reverse('silk:request_detail', kwargs={'request_id': str(self.request.id)}))
self.assertEqual(response.status_code, HTTPStatus.FOUND)
diff --git a/silk/views/request_detail.py b/silk/views/request_detail.py
index 9e170c67..38bf009d 100644
--- a/silk/views/request_detail.py
+++ b/silk/views/request_detail.py
@@ -1,6 +1,6 @@
import json
-from django.shortcuts import render, redirect, HttpResponseRedirect
+from django.shortcuts import HttpResponseRedirect, redirect, render
from django.utils.decorators import method_decorator
from django.views.generic import View
@@ -40,7 +40,7 @@ def get(self, request, request_id):
'request': request
}
return render(request, 'silk/request.html', context)
-
+
@method_decorator(login_possibly_required)
@method_decorator(permissions_possibly_required)
def post(self, request, request_id):
@@ -48,5 +48,5 @@ def post(self, request, request_id):
try:
silk_request.delete()
except Request.DoesNotExist:
- return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/silk'))
+ return HttpResponseRedirect(request.headers.get('Referer', '/silk'))
return redirect('/silk')
From 3cfc8688cb2148fff5acb101ec67d4900bfcb18c Mon Sep 17 00:00:00 2001
From: Ashfaq Ahmed <46718979+ashfaq1934@users.noreply.github.com>
Date: Sun, 22 Oct 2023 14:16:44 +0100
Subject: [PATCH 4/5] replaced hardcoded url route with django reverse method
---
silk/views/request_detail.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/silk/views/request_detail.py b/silk/views/request_detail.py
index 38bf009d..bd890d1b 100644
--- a/silk/views/request_detail.py
+++ b/silk/views/request_detail.py
@@ -3,6 +3,7 @@
from django.shortcuts import HttpResponseRedirect, redirect, render
from django.utils.decorators import method_decorator
from django.views.generic import View
+from django.urls import reverse_lazy, reverse
from silk.auth import login_possibly_required, permissions_possibly_required
from silk.code_generation.curl import curl_cmd
@@ -48,5 +49,5 @@ def post(self, request, request_id):
try:
silk_request.delete()
except Request.DoesNotExist:
- return HttpResponseRedirect(request.headers.get('Referer', '/silk'))
- return redirect('/silk')
+ return HttpResponseRedirect(request.headers.get('Referer', reverse("silk:summary")))
+ return redirect(reverse("silk:summary"))
From 17b423ff3f61e9c4d96f80070d81f64bb6ba6627 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Sun, 22 Oct 2023 13:17:42 +0000
Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---
silk/views/request_detail.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/silk/views/request_detail.py b/silk/views/request_detail.py
index bd890d1b..3f43aacc 100644
--- a/silk/views/request_detail.py
+++ b/silk/views/request_detail.py
@@ -1,9 +1,9 @@
import json
from django.shortcuts import HttpResponseRedirect, redirect, render
+from django.urls import reverse
from django.utils.decorators import method_decorator
from django.views.generic import View
-from django.urls import reverse_lazy, reverse
from silk.auth import login_possibly_required, permissions_possibly_required
from silk.code_generation.curl import curl_cmd