add computers as placeholders
This commit is contained in:
parent
16daba1fa5
commit
01e1d6e0b7
|
@ -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)
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Reference in New Issue