From 443c37b1e21cbfefa88dbe67050f0bea719a6304 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Tue, 10 Dec 2024 16:53:07 -0300 Subject: [PATCH] updated views for new model structure --- dashboard/views.py | 3 +-- device/views.py | 12 +++++------- evidence/views.py | 2 +- lot/views.py | 9 ++++----- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/dashboard/views.py b/dashboard/views.py index cb36078..6b91674 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -6,7 +6,7 @@ from django.shortcuts import Http404 from django.db.models import Q from dashboard.mixins import InventaryMixin, DetailsMixin -from evidence.models import Property, SystemProperty +from evidence.models import SystemProperty from evidence.xapian import search from device.models import Device from lot.models import Lot @@ -96,7 +96,6 @@ class SearchView(InventaryMixin): qry |= Q(value__startswith=i) chids = SystemProperty.objects.filter( - type=Property.Type.SYSTEM, owner=self.request.user.institution ).filter( qry diff --git a/device/views.py b/device/views.py index 751b8ef..73f2448 100644 --- a/device/views.py +++ b/device/views.py @@ -15,7 +15,7 @@ from django.views.generic.edit import ( ) from django.views.generic.base import TemplateView from dashboard.mixins import DashboardView, Http403 -from evidence.models import UserProperty, SystemProperty, Property +from evidence.models import UserProperty, SystemProperty from lot.models import LotTag from device.models import Device from device.forms import DeviceFormSet @@ -184,7 +184,7 @@ class AddUserPropertyView(DashboardView, CreateView): form.instance.owner = self.request.user.institution form.instance.user = self.request.user form.instance.uuid = self.property.uuid - form.instance.type = Property.Type.USER + form.instance.type = UserProperty.Type.USER messages.success(self.request, _("User property successfully added.")) @@ -201,7 +201,6 @@ class AddUserPropertyView(DashboardView, CreateView): self.property = SystemProperty.objects.filter( owner=institution, value=pk, - type=Property.Type.SYSTEM ).first() if not self.property: @@ -237,7 +236,7 @@ class UpdateUserPropertyView(DashboardView, UpdateView): form.instance.owner = self.request.user.institution form.instance.user = self.request.user - form.instance.type = Property.Type.USER + form.instance.type = UserProperty.Type.USER response = super().form_valid(form) messages.success(self.request, _("User property updated successfully.")) @@ -278,14 +277,14 @@ class AddDocumentView(DashboardView, CreateView): title = _("New Document") breadcrumb = "Device / New document" success_url = reverse_lazy('dashboard:unassigned_devices') - model = SystemProperty + model = UserProperty fields = ("key", "value") def form_valid(self, form): form.instance.owner = self.request.user.institution form.instance.user = self.request.user form.instance.uuid = self.property.uuid - form.instance.type = Property.Type.DOCUMENT + form.instance.type = UserProperty.Type.DOCUMENT response = super().form_valid(form) return response @@ -295,7 +294,6 @@ class AddDocumentView(DashboardView, CreateView): self.property = SystemProperty.objects.filter( owner=institution, value=pk, - type=Property.Type.SYSTEM ).first() if not self.property: diff --git a/evidence/views.py b/evidence/views.py index c71ab68..833de03 100644 --- a/evidence/views.py +++ b/evidence/views.py @@ -13,7 +13,7 @@ from django.views.generic.edit import ( ) from dashboard.mixins import DashboardView, Http403 -from evidence.models import Property, SystemProperty, UserProperty, Evidence +from evidence.models import SystemProperty, UserProperty, Evidence from evidence.forms import ( UploadForm, UserTagForm, diff --git a/lot/views.py b/lot/views.py index 36f582f..9ff0227 100644 --- a/lot/views.py +++ b/lot/views.py @@ -11,7 +11,6 @@ from django.views.generic.edit import ( from dashboard.mixins import DashboardView from lot.models import Lot, LotTag, LotProperty from lot.forms import LotsForm -from device.models import Property class NewLotView(DashboardView, CreateView): template_name = "new_lot.html" @@ -154,7 +153,7 @@ class LotAddDocumentView(DashboardView, CreateView): form.instance.owner = self.request.user.institution form.instance.user = self.request.user form.instance.lot = self.lot - form.instance.type = Property.Type.DOCUMENT + form.instance.type = LotProperty.Type.DOCUMENT response = super().form_valid(form) return response @@ -178,7 +177,7 @@ class LotDocumentsView(DashboardView, TemplateView): documents = LotProperty.objects.filter( lot=lot, owner=self.request.user.institution, - type=Property.Type.DOCUMENT, + type=LotProperty.Type.DOCUMENT, ) context.update({ 'lot': lot, @@ -201,7 +200,7 @@ class LotPropertiesView(DashboardView, TemplateView): properties = LotProperty.objects.filter( lot=lot, owner=self.request.user.institution, - type=Property.Type.USER, + type=LotProperty.Type.USER, ) context.update({ 'lot': lot, @@ -224,7 +223,7 @@ class LotAddPropertyView(DashboardView, CreateView): form.instance.owner = self.request.user.institution form.instance.user = self.request.user form.instance.lot = self.lot - form.instance.type = Property.Type.USER + form.instance.type = LotProperty.Type.USER response = super().form_valid(form) return response