Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

632 Delete Requests #637

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ fabric.properties

# Virtual env
.venv*
venv

package-lock.json
*.db
20 changes: 20 additions & 0 deletions project/tests/test_delete_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from http import HTTPStatus

from django.test import Client, TestCase
from django.urls import reverse

from silk.models import Request


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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests! A few nitpicks:

  • Can you make sure that this re-routes to the summary page and the object is deleted. (Bonus for test that checks the redirection for header Referer)
  • Another test that checks when we pass in a non-existing request

13 changes: 13 additions & 0 deletions silk/static/silk/css/components/button.css
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions silk/templates/silk/base/root_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<link rel="stylesheet" href="{% static 'silk/css/components/cell.css' %}"/>
<link rel="stylesheet" href="{% static 'silk/css/components/row.css' %}"/>
<link rel="stylesheet" href="{% static 'silk/css/components/numeric.css' %}"/>
<link rel="stylesheet" href="{% static 'silk/css/components/button.css' %}">
<link rel="stylesheet" href="{% static "silk/lib/jquery.datetimepicker.css" %}"/>
<link rel="icon" type="image/png" href="{% static 'silk/favicon-32x32.png' %}" sizes="32x32">
<link rel="icon" type="image/png" href="{% static 'silk/favicon-16x16.png' %}" sizes="16x16">
Expand Down
6 changes: 6 additions & 0 deletions silk/templates/silk/inclusion/request_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
<span class="numeric">{{ silk_request.num_sql_queries }}</span>
<span class="appendage">queries<span class="meta">{% if silk_request.meta_num_queries %} +{{ silk_request.meta_num_queries }}{% endif %}</span>
</div>
<div>
<form action="{% url 'silk:request_detail' silk_request.id %}" method="POST">
{% csrf_token %}
<button class="silk-button" type="submit" value="Delete">Delete</button>
</form>
</div>
</div>
1 change: 1 addition & 0 deletions silk/templates/silk/request.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{% block style %}
<link rel="stylesheet" href="{% static 'silk/css/components/cell.css' %}"/>
<link rel="stylesheet" href="{% static 'silk/css/components/numeric.css' %}"/>
<link rel="stylesheet" href="{% static 'silk/css/components/button.css' %}">
<link rel="stylesheet" href="{% static 'silk/css/components/heading.css' %}"/>
<link rel="stylesheet" href="{% static 'silk/css/pages/request.css' %}"/>
<link rel="stylesheet" href="{% static 'silk/lib/highlight/foundation.css' %}"/>
Expand Down
12 changes: 11 additions & 1 deletion silk/views/request_detail.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from django.shortcuts import render
from django.shortcuts import HttpResponseRedirect, redirect, render
from django.utils.decorators import method_decorator
from django.views.generic import View

Expand Down Expand Up @@ -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.headers.get('Referer', '/silk'))
return redirect('/silk')
gopar marked this conversation as resolved.
Show resolved Hide resolved