add a backups table view

This commit is contained in:
Andreas Zweili 2019-09-24 20:30:43 +02:00
parent ba20a056c3
commit a98dd4f2b0
5 changed files with 60 additions and 2 deletions

View File

@ -7,6 +7,7 @@ class CustomersTable(tables.Table):
nets = tables.LinkColumn('nets', text='Nets', args=[A('pk')])
computers = tables.LinkColumn('computers', text='Computers', args=[A('pk')])
devices = tables.LinkColumn('devices', text='Devices', args=[A('pk')])
backups = tables.LinkColumn('backups', text='Backups', args=[A('pk')])
class Meta:
template_name = 'django_tables2/semantic.html'
@ -44,6 +45,15 @@ class NetsTable(tables.Table):
model = Net
class BackupsTable(tables.Table):
name = tables.LinkColumn('backup', args=[A('pk')])
computer = tables.LinkColumn('computer', args=[A('pk')])
class Meta:
template_name = 'django_tables2/semantic.html'
model = Backup
class NetDetailTable(tables.Table):
device = tables.LinkColumn('computer', args=[A('pk')])
ip = tables.Column()
@ -55,6 +65,8 @@ class NetDetailTable(tables.Table):
class BackupDetailTable(tables.Table):
computer = tables.LinkColumn('computer', args=[A('pk')])
class Meta:
template_name = 'django_tables2/semantic.html'
model = Backup

View File

@ -0,0 +1,6 @@
{% extends "inventory/base.html" %}
{% load render_table from django_tables2 %}
{% block section_title %}List of Backups{% endblock %}
{% block content %}
{% render_table backups %}
{% endblock %}

View File

@ -0,0 +1,31 @@
import pytest
from mixer.backend.django import mixer
from django.test import Client
from helper import in_content, not_in_content
pytestmark=pytest.mark.django_db
def test_customer_backup_table_not_logged_in():
response = Client().get('/customer/1/backups/')
assert response.status_code == 302 and 'login' in response.url
def test_customer_backup_table(create_admin_user):
fixture = create_admin_user()
customer = fixture['customer']
client = Client()
client.login(username="novartis-admin", password="password")
backup = mixer.blend('inventory.Backup', customer=mixer.SELECT)
response = client.get('/customer/' + str(customer.id) + '/backups/')
assert response.status_code == 200 and in_content(response, backup.name)
def test_customer_backup_table_no_backup(create_admin_user):
fixture = create_admin_user()
customer = fixture['customer']
client = Client()
client.login(username="novartis-admin", password="password")
response = client.get('/customer/' + str(customer.id) + '/backups/')
assert response.status_code == 200 and not_in_content(response, "Novartis PC")

View File

@ -13,6 +13,8 @@ urlpatterns = [
name='devices'),
path('customer/<int:pk>/nets/', views.nets_table_view,
name='nets'),
path('customer/<int:pk>/backups/', views.backups_table_view,
name='backups'),
path('computer/<int:pk>/', views.computer_detail_view,
name='computer'),
path('device/<int:pk>/', views.device_detail_view, name='device'),

View File

@ -17,7 +17,7 @@ from .models import (Device, Computer, ComputerRamRelation,
ComputerSoftwareRelation, Customer, Net, RaidInComputer,
Backup, DeviceInNet)
from .tables import (CustomersTable, ComputersTable, DevicesTable, NetsTable,
NetDetailTable, BackupDetailTable)
BackupsTable, NetDetailTable, BackupDetailTable)
from .filters import ComputerFilter
@ -96,6 +96,14 @@ def net_detail_view(request, pk):
'net': net})
@login_required
def backups_table_view(request, pk):
computers = Computer.objects.filter(customer=pk)
table = BackupsTable(Backup.objects.filter(computer__in=computers))
RequestConfig(request).configure(table)
return render(request, 'inventory/backup_list.html', {'backups': table})
@login_required
def backup_detail_view(request, pk):
table = BackupDetailTable(Backup.objects.filter(pk=pk))
@ -103,7 +111,6 @@ def backup_detail_view(request, pk):
return render(request, 'inventory/backup_details.html', {'backup': table})
class ComputersFilterView(LoginRequiredMixin, SingleTableMixin, FilterView):
table_class = ComputersTable
model = Computer