From a66322dc0a59ca2bc4cb0a87ab99fbc9e7e14c19 Mon Sep 17 00:00:00 2001 From: Ashfaq Ahmed <46718979+ashfaq1934@users.noreply.github.com> Date: Thu, 29 Dec 2022 21:29:59 +0000 Subject: [PATCH 1/5] added button to delete single requests on summary and requests page --- project/tests/test_delete_request.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 project/tests/test_delete_request.py diff --git a/project/tests/test_delete_request.py b/project/tests/test_delete_request.py new file mode 100644 index 00000000..2b98448c --- /dev/null +++ b/project/tests/test_delete_request.py @@ -0,0 +1,17 @@ +from django.test import Client, TestCase +from silk.models import Request +from django.urls import reverse +from http import HTTPStatus + +class TestDeleteRequest(TestCase): + def setUp(self): + self.client = Client() + self.request = Request() + self.request.path = reverse('silk:requests') + 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)})) + self.assertEqual(response.status_code, HTTPStatus.FOUND) From fcaedb33786f442a9299a70209a6529147a6ca7c Mon Sep 17 00:00:00 2001 From: Ashfaq Ahmed <46718979+ashfaq1934@users.noreply.github.com> Date: Thu, 29 Dec 2022 21:33:00 +0000 Subject: [PATCH 2/5] added button to delete specific requests on summary and requests pages --- .gitignore | 1 + silk/static/silk/css/components/button.css | 13 +++++++++++++ silk/templates/silk/base/root_base.html | 1 + silk/templates/silk/inclusion/request_summary.html | 6 ++++++ silk/templates/silk/request.html | 1 + silk/views/request_detail.py | 12 +++++++++++- 6 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 silk/static/silk/css/components/button.css diff --git a/.gitignore b/.gitignore index 1ee03766..b48aa763 100644 --- a/.gitignore +++ b/.gitignore @@ -119,6 +119,7 @@ fabric.properties # Virtual env .venv* +venv package-lock.json *.db diff --git a/silk/static/silk/css/components/button.css b/silk/static/silk/css/components/button.css new file mode 100644 index 00000000..490c231e --- /dev/null +++ b/silk/static/silk/css/components/button.css @@ -0,0 +1,13 @@ +.silk-button{ + border: 1px solid transparent; + border-radius: 0.25rem; + padding: 6px 10px; + background: rgb(51, 51, 68); + color: whitesmoke; + margin-top: 5%; +} + +.cell:hover .silk-button{ + background-color: #e2e6ea; + color: #000; +} diff --git a/silk/templates/silk/base/root_base.html b/silk/templates/silk/base/root_base.html index 5154e818..6051212a 100644 --- a/silk/templates/silk/base/root_base.html +++ b/silk/templates/silk/base/root_base.html @@ -11,6 +11,7 @@ + diff --git a/silk/templates/silk/inclusion/request_summary.html b/silk/templates/silk/inclusion/request_summary.html index 18caa4bb..8cc82401 100644 --- a/silk/templates/silk/inclusion/request_summary.html +++ b/silk/templates/silk/inclusion/request_summary.html @@ -14,4 +14,10 @@ {{ silk_request.num_sql_queries }} queries{% if silk_request.meta_num_queries %} +{{ silk_request.meta_num_queries }}{% endif %} +
+
+ {% csrf_token %} + +
+
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