add computers as placeholders

This commit is contained in:
Cayo Puigdefabregas 2022-06-29 11:51:03 +02:00
parent 16daba1fa5
commit 01e1d6e0b7
2 changed files with 27 additions and 3 deletions

View File

@ -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:
_hid = '1'
if _hid:
_hid = str(_hid.id + 1)
else:
_hid = '1'
snapshot_json['device'].hid = _hid
snapshot_json['device'].hid = _hid.lower()
snapshot = upload_form.build(snapshot_json)

View File

@ -36,6 +36,14 @@
<label for="name" class="form-label">Type *</label>
<select id="type" class="form-control" name="type" required="">
<option value="">Select one Type</option>
<optgroup label="Computer">
<option value="Laptop"
{% if form.type.data == 'Laptop' %} selected="selected"{% endif %}>Laptop</option>
<option value="Desktop"
{% if form.type.data == 'Desktop' %} selected="selected"{% endif %}>Desktop</option>
<option value="Server"
{% if form.type.data == 'Server' %} selected="selected"{% endif %}>Server</option>
</optgroup>
<optgroup label="Monitor">
<option value="ComputerMonitor"
{% if form.type.data == 'Monitor' %} selected="selected"{% endif %}>Computer Monitor</option>