updated views for new model structure

This commit is contained in:
Thomas Nahuel Rusiecki 2024-12-10 16:53:07 -03:00
parent fe5abd0299
commit 443c37b1e2
4 changed files with 11 additions and 15 deletions

View file

@ -6,7 +6,7 @@ from django.shortcuts import Http404
from django.db.models import Q from django.db.models import Q
from dashboard.mixins import InventaryMixin, DetailsMixin from dashboard.mixins import InventaryMixin, DetailsMixin
from evidence.models import Property, SystemProperty from evidence.models import SystemProperty
from evidence.xapian import search from evidence.xapian import search
from device.models import Device from device.models import Device
from lot.models import Lot from lot.models import Lot
@ -96,7 +96,6 @@ class SearchView(InventaryMixin):
qry |= Q(value__startswith=i) qry |= Q(value__startswith=i)
chids = SystemProperty.objects.filter( chids = SystemProperty.objects.filter(
type=Property.Type.SYSTEM,
owner=self.request.user.institution owner=self.request.user.institution
).filter( ).filter(
qry qry

View file

@ -15,7 +15,7 @@ from django.views.generic.edit import (
) )
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from dashboard.mixins import DashboardView, Http403 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 lot.models import LotTag
from device.models import Device from device.models import Device
from device.forms import DeviceFormSet from device.forms import DeviceFormSet
@ -184,7 +184,7 @@ class AddUserPropertyView(DashboardView, CreateView):
form.instance.owner = self.request.user.institution form.instance.owner = self.request.user.institution
form.instance.user = self.request.user form.instance.user = self.request.user
form.instance.uuid = self.property.uuid 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.")) messages.success(self.request, _("User property successfully added."))
@ -201,7 +201,6 @@ class AddUserPropertyView(DashboardView, CreateView):
self.property = SystemProperty.objects.filter( self.property = SystemProperty.objects.filter(
owner=institution, owner=institution,
value=pk, value=pk,
type=Property.Type.SYSTEM
).first() ).first()
if not self.property: if not self.property:
@ -237,7 +236,7 @@ class UpdateUserPropertyView(DashboardView, UpdateView):
form.instance.owner = self.request.user.institution form.instance.owner = self.request.user.institution
form.instance.user = self.request.user form.instance.user = self.request.user
form.instance.type = Property.Type.USER form.instance.type = UserProperty.Type.USER
response = super().form_valid(form) response = super().form_valid(form)
messages.success(self.request, _("User property updated successfully.")) messages.success(self.request, _("User property updated successfully."))
@ -278,14 +277,14 @@ class AddDocumentView(DashboardView, CreateView):
title = _("New Document") title = _("New Document")
breadcrumb = "Device / New document" breadcrumb = "Device / New document"
success_url = reverse_lazy('dashboard:unassigned_devices') success_url = reverse_lazy('dashboard:unassigned_devices')
model = SystemProperty model = UserProperty
fields = ("key", "value") fields = ("key", "value")
def form_valid(self, form): def form_valid(self, form):
form.instance.owner = self.request.user.institution form.instance.owner = self.request.user.institution
form.instance.user = self.request.user form.instance.user = self.request.user
form.instance.uuid = self.property.uuid form.instance.uuid = self.property.uuid
form.instance.type = Property.Type.DOCUMENT form.instance.type = UserProperty.Type.DOCUMENT
response = super().form_valid(form) response = super().form_valid(form)
return response return response
@ -295,7 +294,6 @@ class AddDocumentView(DashboardView, CreateView):
self.property = SystemProperty.objects.filter( self.property = SystemProperty.objects.filter(
owner=institution, owner=institution,
value=pk, value=pk,
type=Property.Type.SYSTEM
).first() ).first()
if not self.property: if not self.property:

View file

@ -13,7 +13,7 @@ from django.views.generic.edit import (
) )
from dashboard.mixins import DashboardView, Http403 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 ( from evidence.forms import (
UploadForm, UploadForm,
UserTagForm, UserTagForm,

View file

@ -11,7 +11,6 @@ from django.views.generic.edit import (
from dashboard.mixins import DashboardView from dashboard.mixins import DashboardView
from lot.models import Lot, LotTag, LotProperty from lot.models import Lot, LotTag, LotProperty
from lot.forms import LotsForm from lot.forms import LotsForm
from device.models import Property
class NewLotView(DashboardView, CreateView): class NewLotView(DashboardView, CreateView):
template_name = "new_lot.html" template_name = "new_lot.html"
@ -154,7 +153,7 @@ class LotAddDocumentView(DashboardView, CreateView):
form.instance.owner = self.request.user.institution form.instance.owner = self.request.user.institution
form.instance.user = self.request.user form.instance.user = self.request.user
form.instance.lot = self.lot form.instance.lot = self.lot
form.instance.type = Property.Type.DOCUMENT form.instance.type = LotProperty.Type.DOCUMENT
response = super().form_valid(form) response = super().form_valid(form)
return response return response
@ -178,7 +177,7 @@ class LotDocumentsView(DashboardView, TemplateView):
documents = LotProperty.objects.filter( documents = LotProperty.objects.filter(
lot=lot, lot=lot,
owner=self.request.user.institution, owner=self.request.user.institution,
type=Property.Type.DOCUMENT, type=LotProperty.Type.DOCUMENT,
) )
context.update({ context.update({
'lot': lot, 'lot': lot,
@ -201,7 +200,7 @@ class LotPropertiesView(DashboardView, TemplateView):
properties = LotProperty.objects.filter( properties = LotProperty.objects.filter(
lot=lot, lot=lot,
owner=self.request.user.institution, owner=self.request.user.institution,
type=Property.Type.USER, type=LotProperty.Type.USER,
) )
context.update({ context.update({
'lot': lot, 'lot': lot,
@ -224,7 +223,7 @@ class LotAddPropertyView(DashboardView, CreateView):
form.instance.owner = self.request.user.institution form.instance.owner = self.request.user.institution
form.instance.user = self.request.user form.instance.user = self.request.user
form.instance.lot = self.lot form.instance.lot = self.lot
form.instance.type = Property.Type.USER form.instance.type = LotProperty.Type.USER
response = super().form_valid(form) response = super().form_valid(form)
return response return response