diff --git a/dashboard/mixins.py b/dashboard/mixins.py index 14ac0f7..8a9cb8c 100644 --- a/dashboard/mixins.py +++ b/dashboard/mixins.py @@ -1,5 +1,5 @@ from django.urls import resolve -from django.shortcuts import get_object_or_404 +from django.shortcuts import get_object_or_404, redirect from django.utils.translation import gettext_lazy as _ from django.core.exceptions import PermissionDenied from django.contrib.auth.mixins import LoginRequiredMixin @@ -53,3 +53,21 @@ class DetailsMixin(DashboardView, TemplateView): 'object': self.object, }) return context + + +class InventaryMixin(DashboardView, TemplateView): + + def post(self, request, *args, **kwargs): + devices = [int(x) for x in dict(self.request.POST).get("devices", [])] + self.request.session["devices"] = devices + url = self.request.POST.get("url") + if url: + try: + resource = resolve(url) + if resource and devices: + return redirect(url) + except Exception: + pass + return super().get(request, *args, **kwargs) + + diff --git a/dashboard/templates/unassigned_devices.html b/dashboard/templates/unassigned_devices.html index 26a2503..9ad7505 100644 --- a/dashboard/templates/unassigned_devices.html +++ b/dashboard/templates/unassigned_devices.html @@ -27,6 +27,8 @@
+
+ {% csrf_token %} @@ -38,6 +40,9 @@ {% for dev in devices %} + @@ -45,5 +50,6 @@ {% endfor %}
+ + {{ dev.type }} {{ dev.manufacturer }} {{ dev.model }}
+
{% endblock %} diff --git a/dashboard/views.py b/dashboard/views.py index 99475c8..5c38807 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -1,10 +1,10 @@ from django.utils.translation import gettext_lazy as _ from django.views.generic.base import TemplateView -from dashboard.mixins import DashboardView +from dashboard.mixins import InventaryMixin from device.models import Device -class UnassignedDevicesView(DashboardView, TemplateView): +class UnassignedDevicesView(InventaryMixin): template_name = "unassigned_devices.html" section = "Unassigned" title = _("Unassigned Devices")