extend backup_detail_view to show the target device

This commit is contained in:
Andreas Zweili 2019-12-29 15:17:29 +01:00
parent 1b9f461895
commit 045c8e61de
3 changed files with 38 additions and 6 deletions

View File

@ -20,10 +20,6 @@
<th><b>Backup Software:</b></th>
<td>{{ backup.software }}</td>
</tr>
<tr>
<th><b>Target Device:</b></th>
<td>{{ backup.target_device.device }}</td>
</tr>
<tr>
<th><b>Exec Time:</b></th>
<td>{{ backup.exec_time }}</td>
@ -33,6 +29,25 @@
<td>{{ backup.exec_day }}</td>
</tr>
</table>
{% if target_device_list %}
<div class="card">
<div class="content">
<div class="header">Target Devices</div>
<table class="ui celled table">
{% for device in target_device_list %}
<tr>
<th><b>Target Device:</b></th>
<td><a href="{% url 'computer' device.device.id %}">{{ device.device }}</a></td>
</tr>
<tr>
<th><b>Target Path:</b></th>
<td>{{ device.target_path }}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endif %}
</div>
</div>
</div>

View File

@ -43,3 +43,17 @@ def test_customer_computer_table_no_permission(create_admin_user):
assert response.status_code == 403
def test_backup_detail_view_with_target_device(create_admin_user):
create_admin_user()
source_computer = mixer.blend('inventory.Computer', customer=mixer.SELECT)
target_computer = mixer.blend('inventory.Computer', customer=mixer.SELECT)
backup = mixer.blend('inventory.Backup', computer=source_computer,
software=mixer.SELECT, method=mixer.SELECT)
mixer.blend('inventory.TargetDevice', device=target_computer,
backup=mixer.SELECT)
client = Client()
client.login(username="novartis-admin", password="password")
response = client.get('/backup/' + str(backup.id) + '/')
assert (response.status_code == 200
and helper.in_content(response, backup)
and helper.in_content(response, target_computer))

View File

@ -17,7 +17,7 @@ from .decorators import (computer_view_permission, customer_view_permission,
from .models import (Device, Computer, ComputerRamRelation,
ComputerDiskRelation, ComputerCpuRelation,
ComputerSoftwareRelation, Customer, Net, Raid,
Backup, DeviceInNet)
Backup, DeviceInNet, TargetDevice)
from .tables import (CustomersTable, ComputersTable, DevicesTable, NetsTable,
BackupsTable, NetDetailTable)
from .filters import ComputerFilter
@ -116,7 +116,10 @@ def backups_table_view(request, pk):
@backup_view_permission
def backup_detail_view(request, pk):
backup = get_object_or_404(Backup, pk=pk)
return render(request, 'inventory/backup_details.html', {'backup': backup})
target_device_list = TargetDevice.objects.filter(backup=backup)
return render(request, 'inventory/backup_details.html',
{'backup': backup,
'target_device_list': target_device_list})
class ComputersFilterView(LoginRequiredMixin, SingleTableMixin, FilterView):