From 01e1d6e0b7882d058e9b9dc7586bb068e2a79155 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 29 Jun 2022 11:51:03 +0200 Subject: [PATCH] add computers as placeholders --- ereuse_devicehub/inventory/forms.py | 22 ++++++++++++++++--- .../templates/inventory/device_create.html | 8 +++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index cfe7fee4..2857f34a 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -42,11 +42,14 @@ from ereuse_devicehub.resources.device.models import ( SAI, Cellphone, ComputerMonitor, + Desktop, Device, Keyboard, + Laptop, MemoryCardReader, Mouse, Placeholder, + Server, Smartphone, Tablet, ) @@ -333,6 +336,9 @@ class NewDeviceForm(FlaskForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.devices = { + "Laptop": Laptop, + "Desktop": Desktop, + "Server": Server, "Smartphone": Smartphone, "Tablet": Tablet, "Cellphone": Cellphone, @@ -397,6 +403,15 @@ class NewDeviceForm(FlaskForm): self.meid.errors = error is_valid = False + if self.phid.data: + dev = Device.query.filter_by( + hid=self.phid.data, owner=g.user, active=True + ).first() + if dev and not dev.placeholder: + msg = "Sorry, exist one snapshot device with this HID" + self.phid.errors = [msg] + is_valid = False + if not is_valid: return False @@ -465,11 +480,12 @@ class NewDeviceForm(FlaskForm): _hid = self.phid.data if not _hid: _hid = Placeholder.query.order_by(Placeholder.id.desc()).first() - if not _hid: + if _hid: + _hid = str(_hid.id + 1) + else: _hid = '1' - _hid = str(_hid.id + 1) - snapshot_json['device'].hid = _hid + snapshot_json['device'].hid = _hid.lower() snapshot = upload_form.build(snapshot_json) diff --git a/ereuse_devicehub/templates/inventory/device_create.html b/ereuse_devicehub/templates/inventory/device_create.html index 1243b41d..c36e2e79 100644 --- a/ereuse_devicehub/templates/inventory/device_create.html +++ b/ereuse_devicehub/templates/inventory/device_create.html @@ -36,6 +36,14 @@