add LicenseWithComputerDeleteView

This commit is contained in:
Andreas Zweili 2020-06-28 23:59:50 +02:00
parent efaead7d7d
commit 4b6e375833
5 changed files with 43 additions and 2 deletions

View File

@ -4,6 +4,7 @@
<tr> <tr>
<td>{{ license.license.software }}</td> <td>{{ license.license.software }}</td>
<td><code>{{ license.license.key }}</code></td> <td><code>{{ license.license.key }}</code></td>
<td><a href="{% url 'license_with_computer_delete' license.pk %}" class="delete" title="Delete" data-toggle="tooltip"><i class="material-icons">delete</i></a></tr>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View File

@ -0,0 +1,16 @@
{% extends "core/base.html" %}
{% block section_title %}Delete License Relation{% endblock %}
{% block content %}
<div class="row">
<form method="post">{% csrf_token %}
<p>Are you sure you want unasign the license "{{ object.license }}" from "{{ object.computer }}"?</p>
<button type="submit" class="btn btn-danger">Delete</button>
<a href="{{ request.META.HTTP_REFERER }}" class="btn btn-primary">Cancel</a>
<input type="hidden" id="previous_page" name="previous_page" value="/previous/page/url">
</form>
<script>
prev = document.getElementById("previous_page");
prev.value = document.referrer;
</script>
</div>
{% endblock %}

View File

@ -6,7 +6,7 @@ import pytest
pytestmark = pytest.mark.django_db pytestmark = pytest.mark.django_db
def test_license_relation_create_view(create_admin_user): def test_license_with_computer_create_view(create_admin_user):
create_admin_user() create_admin_user()
client = Client() client = Client()
client.login(username="pharma-admin", password="password") client.login(username="pharma-admin", password="password")
@ -22,3 +22,14 @@ def test_license_relation_create_view(create_admin_user):
assert response.status_code == 302 assert response.status_code == 302
def test_license_with_computer_delete_view(create_admin_user):
create_admin_user()
client = Client()
client.login(username="pharma-admin", password="password")
computer = mixer.blend('computers.Computer', customer=mixer.SELECT)
license = mixer.blend('licenses.ComputerLicense')
license_with_computer = mixer.blend('licenses.LicenseWithComputer',
computer=computer, license=license)
url = '/delete/license-with-computer/{}/'.format(license_with_computer.id)
response = client.post(url)
assert response.status_code == 302

View File

@ -8,4 +8,7 @@ urlpatterns = [
path('create/license-with/computer/<int:pk>/', path('create/license-with/computer/<int:pk>/',
views.LicenseWithComputerCreateView.as_view(), views.LicenseWithComputerCreateView.as_view(),
name='license_with_computer_create'), name='license_with_computer_create'),
path('delete/license-with-computer/<int:pk>/',
views.LicenseWithComputerDeleteView.as_view(),
name='license_with_computer_delete'),
] ]

View File

@ -4,6 +4,7 @@ from django.shortcuts import get_object_or_404
from django.shortcuts import render from django.shortcuts import render
from django.urls import reverse from django.urls import reverse
from django.views.generic import CreateView from django.views.generic import CreateView
from django.views.generic import DeleteView
from django_tables2 import RequestConfig from django_tables2 import RequestConfig
@ -35,7 +36,6 @@ def licenses_table_view(request, pk):
class LicenseWithComputerCreateView(LoginRequiredMixin, CreateView): class LicenseWithComputerCreateView(LoginRequiredMixin, CreateView):
model = LicenseWithComputer model = LicenseWithComputer
#form_class = ComputerSoftwareRelationCreateForm
template_name = 'licenses/license_with_computer_create.html' template_name = 'licenses/license_with_computer_create.html'
fields = '__all__' fields = '__all__'
@ -51,3 +51,13 @@ class LicenseWithComputerCreateView(LoginRequiredMixin, CreateView):
return { return {
'computer': self.computer, 'computer': self.computer,
} }
class LicenseWithComputerDeleteView(LoginRequiredMixin, DeleteView):
model = LicenseWithComputer
template_name = 'licenses/license_with_computer_confirm_delete.html'
def get_success_url(self):
return reverse('computer', args=(self.object.computer.pk,))