This commit is contained in:
parent
4debac4fbe
commit
fac6380bcf
|
@ -745,7 +745,7 @@ class Device(Thing):
|
|||
|
||||
return ""
|
||||
|
||||
def set_hid(self):
|
||||
def set_new_hid(self):
|
||||
"""
|
||||
The order is important
|
||||
# product_vendor, is a manufacturer
|
||||
|
@ -814,7 +814,18 @@ class Device(Thing):
|
|||
if self.hid:
|
||||
return hashlib.sha3_512(self.hid.encode()).hexdigest()
|
||||
|
||||
def set_old_hid(self):
|
||||
def get_from_db(self):
|
||||
if not self.hid:
|
||||
return
|
||||
|
||||
return Device.query.filter_by(
|
||||
hid=self.hid,
|
||||
owner_id=g.user.id,
|
||||
active=True,
|
||||
placeholder=None,
|
||||
).first()
|
||||
|
||||
def set_hid(self):
|
||||
with suppress(TypeError):
|
||||
self.hid = Naming.hid(
|
||||
self.type, self.manufacturer, self.model, self.serial_number
|
||||
|
|
|
@ -208,21 +208,6 @@ class Computer(Device):
|
|||
receiver_id = UUID(data_key='receiverID')
|
||||
system_uuid = UUID(required=False)
|
||||
|
||||
@post_load
|
||||
def validate_hid(self, data):
|
||||
"""Validates than exist model manufacturer and system_uuid."""
|
||||
|
||||
minimum = [
|
||||
data.get('manufacturer'),
|
||||
data.get('model'),
|
||||
data.get('system_uuid'),
|
||||
]
|
||||
|
||||
if not all(minimum):
|
||||
txt = 'You can not register one device with out minimum datas, '
|
||||
txt += 'you can to do one placeholder.'
|
||||
raise ValidationError(txt)
|
||||
|
||||
|
||||
class Desktop(Computer):
|
||||
__doc__ = m.Desktop.__doc__
|
||||
|
|
|
@ -212,19 +212,10 @@ class Sync:
|
|||
placeholder=None,
|
||||
).one()
|
||||
# if no there are any Computer by uuid search by hid
|
||||
if not db_device and device.hid:
|
||||
with suppress(ResourceNotFound):
|
||||
db_device = Device.query.filter_by(
|
||||
hid=device.hid,
|
||||
owner_id=g.user.id,
|
||||
active=True,
|
||||
placeholder=None,
|
||||
).one()
|
||||
if not db_device:
|
||||
db_device = device.get_from_db()
|
||||
elif device.hid:
|
||||
with suppress(ResourceNotFound):
|
||||
db_device = Device.query.filter_by(
|
||||
hid=device.hid, owner_id=g.user.id, active=True, placeholder=None
|
||||
).one()
|
||||
db_device = device.get_from_db()
|
||||
|
||||
if db_device and db_device.allocated:
|
||||
raise ResourceNotFound('device is actually allocated {}'.format(device))
|
||||
|
|
Reference in New Issue