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, SAI,
Cellphone, Cellphone,
ComputerMonitor, ComputerMonitor,
Desktop,
Device, Device,
Keyboard, Keyboard,
Laptop,
MemoryCardReader, MemoryCardReader,
Mouse, Mouse,
Placeholder, Placeholder,
Server,
Smartphone, Smartphone,
Tablet, Tablet,
) )
@ -333,6 +336,9 @@ class NewDeviceForm(FlaskForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.devices = { self.devices = {
"Laptop": Laptop,
"Desktop": Desktop,
"Server": Server,
"Smartphone": Smartphone, "Smartphone": Smartphone,
"Tablet": Tablet, "Tablet": Tablet,
"Cellphone": Cellphone, "Cellphone": Cellphone,
@ -397,6 +403,15 @@ class NewDeviceForm(FlaskForm):
self.meid.errors = error self.meid.errors = error
is_valid = False 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: if not is_valid:
return False return False
@ -465,11 +480,12 @@ class NewDeviceForm(FlaskForm):
_hid = self.phid.data _hid = self.phid.data
if not _hid: if not _hid:
_hid = Placeholder.query.order_by(Placeholder.id.desc()).first() _hid = Placeholder.query.order_by(Placeholder.id.desc()).first()
if not _hid: if _hid:
_hid = str(_hid.id + 1)
else:
_hid = '1' _hid = '1'
_hid = str(_hid.id + 1)
snapshot_json['device'].hid = _hid snapshot_json['device'].hid = _hid.lower()
snapshot = upload_form.build(snapshot_json) snapshot = upload_form.build(snapshot_json)

View File

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