diff --git a/dashboard/mixins.py b/dashboard/mixins.py index 8a9cb8c..a6c372c 100644 --- a/dashboard/mixins.py +++ b/dashboard/mixins.py @@ -4,6 +4,7 @@ from django.utils.translation import gettext_lazy as _ from django.core.exceptions import PermissionDenied from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic.base import TemplateView +from device.models import Device class Http403(PermissionDenied): @@ -39,6 +40,12 @@ class DashboardView(LoginRequiredMixin): }) return context + def get_session_devices(self): + # import pdb; pdb.set_trace() + dev_ids = self.request.session.pop("devices", []) + self._devices = Device.objects.filter(id__in=dev_ids).filter(owner=self.request.user) + return self._devices + class DetailsMixin(DashboardView, TemplateView): @@ -58,13 +65,13 @@ class DetailsMixin(DashboardView, TemplateView): 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 + dev_ids = dict(self.request.POST).get("devices", []) + self.request.session["devices"] = dev_ids url = self.request.POST.get("url") if url: try: resource = resolve(url) - if resource and devices: + if resource and dev_ids: return redirect(url) except Exception: pass diff --git a/dashboard/templates/unassigned_devices.html b/dashboard/templates/unassigned_devices.html index 9ad7505..d697e78 100644 --- a/dashboard/templates/unassigned_devices.html +++ b/dashboard/templates/unassigned_devices.html @@ -50,6 +50,7 @@ {% endfor %} - + + {% endblock %} diff --git a/lot/forms.py b/lot/forms.py new file mode 100644 index 0000000..119192c --- /dev/null +++ b/lot/forms.py @@ -0,0 +1,22 @@ +from django import forms +from lot.models import Lot + +class LotsForm(forms.Form): + lots = forms.ModelMultipleChoiceField( + queryset=Lot.objects.all(), + widget=forms.CheckboxSelectMultiple, + ) + + def clean(self): + # import pdb; pdb.set_trace() + self._lots = self.cleaned_data.get("lots") + return self._lots + + def save(self, commit=True): + if not commit: + return + # import pdb; pdb.set_trace() + for dev in self.devices: + for lot in self._lots: + lot.devices.add(dev.id) + return diff --git a/lot/models.py b/lot/models.py index 9f33e57..860bdbf 100644 --- a/lot/models.py +++ b/lot/models.py @@ -21,3 +21,21 @@ class Lot(models.Model): closed = models.BooleanField(default=True) owner = models.ForeignKey(User, on_delete=models.CASCADE) devices = models.ManyToManyField(Device) + + @property + def is_incoming(self): + if self.type == self.Types.INCOMING: + return True + return False + + @property + def is_outgoing(self): + if self.type == self.Types.OUTGOING: + return True + return False + + @property + def is_temporal(self): + if self.type == self.Types.TEMPORAL: + return True + return False diff --git a/lot/templates/list_lots.html b/lot/templates/list_lots.html new file mode 100644 index 0000000..126e7bb --- /dev/null +++ b/lot/templates/list_lots.html @@ -0,0 +1,61 @@ +{% extends "base.html" %} +{% load i18n %} + +{% block content %} +