2019-06-16 15:02:47 +02:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2019-08-04 22:15:30 +02:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2019-12-30 11:09:47 +01:00
|
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
from django.shortcuts import render
|
2020-02-27 22:01:07 +01:00
|
|
|
from django.urls import reverse
|
2020-05-01 13:08:40 +02:00
|
|
|
from django.views.generic import CreateView
|
|
|
|
from django.views.generic import UpdateView
|
2020-05-26 23:26:31 +02:00
|
|
|
from django.views.generic import DeleteView
|
2019-09-01 12:06:27 +02:00
|
|
|
|
2019-12-30 11:09:47 +01:00
|
|
|
from django_filters.views import FilterView
|
2019-08-02 13:05:42 +02:00
|
|
|
from django_tables2 import RequestConfig
|
2019-08-02 16:54:32 +02:00
|
|
|
from django_tables2.views import SingleTableMixin
|
2019-09-01 12:06:27 +02:00
|
|
|
|
2020-02-29 15:49:00 +01:00
|
|
|
from core import utils
|
2020-01-11 17:41:39 +01:00
|
|
|
from backups.models import Backup
|
2020-01-10 00:01:06 +01:00
|
|
|
from customers.models import Customer
|
|
|
|
from customers.decorators import customer_view_permission
|
2020-05-03 22:10:11 +02:00
|
|
|
from devices.models import DeviceInNet
|
2020-02-16 12:59:44 +01:00
|
|
|
from devices.models import Warranty
|
2020-01-12 12:43:01 +01:00
|
|
|
from licenses.models import LicenseWithComputer
|
2020-01-07 21:31:44 +01:00
|
|
|
|
2019-12-30 11:09:47 +01:00
|
|
|
from .decorators import computer_view_permission
|
2019-08-02 16:54:32 +02:00
|
|
|
from .filters import ComputerFilter
|
2020-02-27 22:00:17 +01:00
|
|
|
from .forms import ComputerCreateForm
|
2020-05-26 23:25:21 +02:00
|
|
|
from .forms import ComputerUpdateForm
|
2020-06-15 21:38:21 +02:00
|
|
|
from .forms import ComputerCpuRelationCreateForm
|
2020-06-15 21:39:58 +02:00
|
|
|
from .forms import ComputerDiskRelationCreateForm
|
2020-06-15 21:39:31 +02:00
|
|
|
from .forms import ComputerGpuRelationCreateForm
|
2020-06-09 21:59:20 +02:00
|
|
|
from .forms import ComputerRamRelationCreateForm
|
2020-06-28 19:04:55 +02:00
|
|
|
from .forms import ComputerSoftwareRelationCreateForm
|
2020-06-29 22:43:39 +02:00
|
|
|
from .forms import RaidCreateForm
|
2019-12-30 11:09:47 +01:00
|
|
|
from .models import Computer
|
|
|
|
from .models import ComputerCpuRelation
|
|
|
|
from .models import ComputerDiskRelation
|
2020-04-30 15:40:00 +02:00
|
|
|
from .models import ComputerGpuRelation
|
2019-12-30 11:09:47 +01:00
|
|
|
from .models import ComputerRamRelation
|
|
|
|
from .models import ComputerSoftwareRelation
|
2020-01-03 03:29:44 +01:00
|
|
|
from .models import DisksInRaid
|
2019-12-30 11:09:47 +01:00
|
|
|
from .models import Raid
|
|
|
|
from .tables import ComputersTable
|
2017-12-25 13:35:09 +01:00
|
|
|
|
|
|
|
|
2019-06-16 15:02:47 +02:00
|
|
|
@login_required
|
|
|
|
@computer_view_permission
|
2019-09-03 18:49:44 +02:00
|
|
|
def computer_detail_view(request, pk):
|
2020-02-16 14:20:27 +01:00
|
|
|
device = get_object_or_404(Computer, pk=pk)
|
2020-01-12 16:55:16 +01:00
|
|
|
disks_relations = ComputerDiskRelation.objects.filter(computer=pk)
|
2020-02-16 12:59:44 +01:00
|
|
|
warranty_relations = Warranty.objects.filter(device=pk)
|
2020-01-12 16:55:16 +01:00
|
|
|
ram_relations = ComputerRamRelation.objects.filter(computer=pk)
|
|
|
|
cpu_relations = ComputerCpuRelation.objects.filter(computer=pk)
|
2020-04-30 15:40:00 +02:00
|
|
|
gpu_relations = ComputerGpuRelation.objects.filter(computer=pk)
|
2020-01-12 16:55:16 +01:00
|
|
|
software_relations = ComputerSoftwareRelation.objects.filter(computer=pk)
|
|
|
|
license_list = LicenseWithComputer.objects.filter(computer=pk)
|
2020-05-03 22:10:11 +02:00
|
|
|
net_relations = DeviceInNet.objects.filter(device=pk)
|
2020-01-03 03:29:44 +01:00
|
|
|
raid_disk_pairs = {}
|
|
|
|
for raid in Raid.objects.filter(computer=pk):
|
|
|
|
raid_disk_pairs[raid] = DisksInRaid.objects.filter(raid=raid)
|
2019-09-03 18:49:44 +02:00
|
|
|
backup_list = Backup.objects.filter(computer=pk)
|
2020-02-16 14:20:27 +01:00
|
|
|
context = {'device': device,
|
2020-02-16 12:59:44 +01:00
|
|
|
'warranty_relations': warranty_relations,
|
2020-01-12 16:55:16 +01:00
|
|
|
'disks_relations': disks_relations,
|
|
|
|
'ram_relations': ram_relations,
|
|
|
|
'cpu_relations': cpu_relations,
|
2020-04-30 15:40:00 +02:00
|
|
|
'gpu_relations': gpu_relations,
|
2020-01-12 16:55:16 +01:00
|
|
|
'software_relations': software_relations,
|
2020-01-03 03:29:44 +01:00
|
|
|
'raid_disk_pairs': raid_disk_pairs,
|
2020-01-12 16:55:16 +01:00
|
|
|
'backup_relations': backup_list,
|
2020-05-01 16:57:38 +02:00
|
|
|
'license_list': license_list,
|
2020-05-03 22:10:11 +02:00
|
|
|
'net_relations': net_relations,
|
2020-05-01 16:57:38 +02:00
|
|
|
'pk': pk}
|
2020-01-12 14:36:44 +01:00
|
|
|
return render(request, 'computers/computer_details.html', context)
|
2017-12-25 13:35:30 +01:00
|
|
|
|
|
|
|
|
2019-08-04 20:44:37 +02:00
|
|
|
@login_required
|
2019-12-27 00:47:25 +01:00
|
|
|
@customer_view_permission
|
2019-09-03 18:49:44 +02:00
|
|
|
def computers_table_view(request, pk):
|
|
|
|
table = ComputersTable(Computer.objects.filter(customer=pk))
|
2019-08-02 13:05:42 +02:00
|
|
|
RequestConfig(request).configure(table)
|
2020-02-28 17:45:12 +01:00
|
|
|
return render(request, 'computers/computer_list.html', {'computers': table,
|
2020-02-29 19:00:23 +01:00
|
|
|
'pk': pk})
|
2019-07-24 22:56:08 +02:00
|
|
|
|
|
|
|
|
2019-08-28 23:09:34 +02:00
|
|
|
class ComputersFilterView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
2020-02-29 15:35:46 +01:00
|
|
|
"""
|
|
|
|
A view to show all computer objects in a table.
|
|
|
|
This view is not intended for customers to see but should be limited to
|
|
|
|
admins only
|
|
|
|
"""
|
2019-08-02 16:54:32 +02:00
|
|
|
table_class = ComputersTable
|
|
|
|
model = Computer
|
2020-01-12 14:36:44 +01:00
|
|
|
template_name = "computers/all_computers.html"
|
2019-08-02 16:54:32 +02:00
|
|
|
|
|
|
|
filterset_class = ComputerFilter
|
|
|
|
|
|
|
|
def get_queryset(self):
|
2020-02-29 15:49:00 +01:00
|
|
|
return utils.get_objects("Computer", self.request.user)
|
2020-02-26 21:56:53 +01:00
|
|
|
|
|
|
|
|
2020-02-29 11:45:06 +01:00
|
|
|
class ComputerCreateFromCustomerView(LoginRequiredMixin, CreateView):
|
2020-02-29 15:35:46 +01:00
|
|
|
"""
|
|
|
|
A view to show a ComputerCreateForm after comming from a customers computer
|
|
|
|
table. The customer will be preselected in the form.
|
|
|
|
"""
|
2020-02-26 21:56:53 +01:00
|
|
|
form_class = ComputerCreateForm
|
|
|
|
template_name = 'computers/computer_create.html'
|
|
|
|
|
2020-02-27 22:01:07 +01:00
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer_update', args=(self.object.pk,))
|
|
|
|
|
2020-02-29 11:46:18 +01:00
|
|
|
def get_form_kwargs(self):
|
|
|
|
"""
|
2020-02-29 15:18:58 +01:00
|
|
|
Pass the request user to the form.
|
2020-02-29 11:46:18 +01:00
|
|
|
"""
|
|
|
|
kwargs = super(ComputerCreateFromCustomerView, self).get_form_kwargs()
|
|
|
|
kwargs.update({'user': self.request.user})
|
|
|
|
return kwargs
|
|
|
|
|
2020-02-29 11:46:44 +01:00
|
|
|
def get_initial(self):
|
|
|
|
"""
|
|
|
|
Set the customer dropdown to the customer from the previews view.
|
|
|
|
"""
|
|
|
|
customer = get_object_or_404(Customer, id=self.kwargs.get('pk'))
|
|
|
|
return {
|
|
|
|
'customer': customer,
|
|
|
|
}
|
|
|
|
|
2020-02-26 21:56:53 +01:00
|
|
|
|
|
|
|
class ComputerUpdateView(LoginRequiredMixin, UpdateView):
|
|
|
|
model = Computer
|
2020-05-26 23:25:21 +02:00
|
|
|
form_class = ComputerUpdateForm
|
2020-02-29 12:24:46 +01:00
|
|
|
template_name = 'computers/computer_update.html'
|
|
|
|
|
2020-05-26 23:25:21 +02:00
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.object.pk,))
|
2020-05-26 23:26:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ComputerDeleteView(LoginRequiredMixin, DeleteView):
|
|
|
|
model = Computer
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computers', args=(self.object.customer.pk,))
|
|
|
|
|
|
|
|
|
2020-06-09 21:59:20 +02:00
|
|
|
class ComputerRamRelationCreateView(LoginRequiredMixin, CreateView):
|
|
|
|
model = ComputerRamRelation
|
|
|
|
form_class = ComputerRamRelationCreateForm
|
|
|
|
template_name = 'computers/ram_relation_create.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.computer.pk,))
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
"""
|
|
|
|
Set the device and customer dropdown to the device from the previous
|
|
|
|
view and the customer related to the device.
|
|
|
|
"""
|
|
|
|
self.computer = get_object_or_404(Computer, id=self.kwargs.get('pk'))
|
|
|
|
return {
|
|
|
|
'computer': self.computer,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ComputerRamRelationDeleteView(LoginRequiredMixin, DeleteView):
|
|
|
|
model = ComputerRamRelation
|
2020-06-15 21:36:41 +02:00
|
|
|
template_name = 'computers/relation_confirm_delete.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.object.computer.pk,))
|
|
|
|
|
|
|
|
|
2020-06-15 21:38:21 +02:00
|
|
|
class ComputerCpuRelationCreateView(LoginRequiredMixin, CreateView):
|
|
|
|
model = ComputerCpuRelation
|
|
|
|
form_class = ComputerCpuRelationCreateForm
|
|
|
|
template_name = 'computers/cpu_relation_create.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.computer.pk,))
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
"""
|
|
|
|
Set the device and customer dropdown to the device from the previous
|
|
|
|
view and the customer related to the device.
|
|
|
|
"""
|
|
|
|
self.computer = get_object_or_404(Computer, id=self.kwargs.get('pk'))
|
|
|
|
return {
|
|
|
|
'computer': self.computer,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ComputerCpuRelationDeleteView(LoginRequiredMixin, DeleteView):
|
|
|
|
model = ComputerCpuRelation
|
|
|
|
template_name = 'computers/relation_confirm_delete.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.object.computer.pk,))
|
|
|
|
|
|
|
|
|
2020-06-15 21:39:31 +02:00
|
|
|
class ComputerGpuRelationCreateView(LoginRequiredMixin, CreateView):
|
|
|
|
model = ComputerGpuRelation
|
|
|
|
form_class = ComputerGpuRelationCreateForm
|
|
|
|
template_name = 'computers/gpu_relation_create.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.computer.pk,))
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
"""
|
|
|
|
Set the device and customer dropdown to the device from the previous
|
|
|
|
view and the customer related to the device.
|
|
|
|
"""
|
|
|
|
self.computer = get_object_or_404(Computer, id=self.kwargs.get('pk'))
|
|
|
|
return {
|
|
|
|
'computer': self.computer,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ComputerGpuRelationDeleteView(LoginRequiredMixin, DeleteView):
|
|
|
|
model = ComputerGpuRelation
|
|
|
|
template_name = 'computers/relation_confirm_delete.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.object.computer.pk,))
|
|
|
|
|
|
|
|
|
2020-06-15 21:39:58 +02:00
|
|
|
class ComputerDiskRelationCreateView(LoginRequiredMixin, CreateView):
|
|
|
|
model = ComputerDiskRelation
|
|
|
|
form_class = ComputerDiskRelationCreateForm
|
|
|
|
template_name = 'computers/disk_relation_create.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.computer.pk,))
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
"""
|
|
|
|
Set the device and customer dropdown to the device from the previous
|
|
|
|
view and the customer related to the device.
|
|
|
|
"""
|
|
|
|
self.computer = get_object_or_404(Computer, id=self.kwargs.get('pk'))
|
|
|
|
return {
|
|
|
|
'computer': self.computer,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ComputerDiskRelationDeleteView(LoginRequiredMixin, DeleteView):
|
|
|
|
model = ComputerDiskRelation
|
|
|
|
template_name = 'computers/relation_confirm_delete.html'
|
2020-06-09 21:59:20 +02:00
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.object.computer.pk,))
|
2020-06-28 19:04:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ComputerSoftwareRelationCreateView(LoginRequiredMixin, CreateView):
|
|
|
|
model = ComputerSoftwareRelation
|
|
|
|
form_class = ComputerSoftwareRelationCreateForm
|
|
|
|
template_name = 'computers/software_relation_create.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.computer.pk,))
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
"""
|
|
|
|
Set the device and customer dropdown to the device from the previous
|
|
|
|
view and the customer related to the device.
|
|
|
|
"""
|
|
|
|
self.computer = get_object_or_404(Computer, id=self.kwargs.get('pk'))
|
|
|
|
return {
|
|
|
|
'computer': self.computer,
|
|
|
|
}
|
|
|
|
|
2020-06-28 19:12:49 +02:00
|
|
|
|
|
|
|
class ComputerSoftwareRelationDeleteView(LoginRequiredMixin, DeleteView):
|
|
|
|
model = ComputerSoftwareRelation
|
|
|
|
template_name = 'computers/relation_confirm_delete.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.object.computer.pk,))
|
|
|
|
|
2020-06-29 22:43:39 +02:00
|
|
|
|
|
|
|
class RaidCreateView(LoginRequiredMixin, CreateView):
|
|
|
|
model = Raid
|
|
|
|
form_class = RaidCreateForm
|
|
|
|
template_name = 'computers/raid_create.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.computer.pk,))
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
"""
|
|
|
|
Set the device and customer dropdown to the device from the previous
|
|
|
|
view and the customer related to the device.
|
|
|
|
"""
|
|
|
|
self.computer = get_object_or_404(Computer, id=self.kwargs.get('pk'))
|
|
|
|
return {
|
|
|
|
'computer': self.computer,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class RaidDeleteView(LoginRequiredMixin, DeleteView):
|
|
|
|
model = Raid
|
|
|
|
template_name = 'computers/relation_confirm_delete.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('computer', args=(self.object.computer.pk,))
|