2020-01-11 18:23:15 +01:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2020-06-28 23:31:35 +02:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.shortcuts import get_object_or_404
|
2020-01-11 17:54:31 +01:00
|
|
|
from django.shortcuts import render
|
2020-06-28 23:31:35 +02:00
|
|
|
from django.urls import reverse
|
|
|
|
from django.views.generic import CreateView
|
2020-06-28 23:59:50 +02:00
|
|
|
from django.views.generic import DeleteView
|
2020-01-11 17:54:31 +01:00
|
|
|
|
2020-01-11 18:23:15 +01:00
|
|
|
from django_tables2 import RequestConfig
|
|
|
|
|
|
|
|
from customers.decorators import customer_view_permission
|
|
|
|
|
2020-06-28 23:31:35 +02:00
|
|
|
from computers.models import Computer
|
|
|
|
|
2020-01-11 18:23:15 +01:00
|
|
|
from .models import ComputerLicense
|
|
|
|
from .models import UserLicense
|
2020-06-28 23:31:35 +02:00
|
|
|
from .models import LicenseWithComputer
|
2020-01-11 18:23:15 +01:00
|
|
|
from .tables import ComputerLicensesTable
|
|
|
|
from .tables import UserLicensesTable
|
2020-01-11 18:18:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@customer_view_permission
|
|
|
|
def licenses_table_view(request, pk):
|
|
|
|
user_licenses = UserLicensesTable(UserLicense.objects.filter(customer=pk))
|
|
|
|
computer_licenses = ComputerLicensesTable(
|
|
|
|
ComputerLicense.objects.filter(customer=pk))
|
|
|
|
RequestConfig(request).configure(user_licenses)
|
|
|
|
RequestConfig(request).configure(computer_licenses)
|
|
|
|
return render(request,
|
2020-01-12 12:30:01 +01:00
|
|
|
'licenses/license_list.html',
|
2020-01-11 18:18:23 +01:00
|
|
|
{'user_licenses': user_licenses,
|
|
|
|
'computer_licenses': computer_licenses})
|
2020-06-28 23:31:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
class LicenseWithComputerCreateView(LoginRequiredMixin, CreateView):
|
|
|
|
model = LicenseWithComputer
|
|
|
|
template_name = 'licenses/license_with_computer_create.html'
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
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 23:59:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
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,))
|
2020-08-03 17:33:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
class UserLicenseDeleteView(LoginRequiredMixin, DeleteView):
|
|
|
|
model = UserLicense
|
|
|
|
template_name = 'licenses/license_confirm_delete.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('licenses', args=(self.object.customer.pk,))
|
|
|
|
|
|
|
|
|
|
|
|
class ComputerLicenseDeleteView(LoginRequiredMixin, DeleteView):
|
|
|
|
model = ComputerLicense
|
|
|
|
template_name = 'licenses/license_confirm_delete.html'
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('licenses', args=(self.object.customer.pk,))
|