put the correct link in the snapshot to warning message
This commit is contained in:
parent
50856671ed
commit
9c2bc7d7fa
|
@ -31,7 +31,7 @@ from wtforms.fields import FormField
|
||||||
|
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.inventory.models import DeliveryNote, ReceiverNote, Transfer
|
from ereuse_devicehub.inventory.models import DeliveryNote, ReceiverNote, Transfer
|
||||||
from ereuse_devicehub.parser.models import PlaceholdersLog
|
from ereuse_devicehub.parser.models import PlaceholdersLog, SnapshotsLog
|
||||||
from ereuse_devicehub.parser.parser import ParseSnapshotLsHw
|
from ereuse_devicehub.parser.parser import ParseSnapshotLsHw
|
||||||
from ereuse_devicehub.parser.schemas import Snapshot_lite
|
from ereuse_devicehub.parser.schemas import Snapshot_lite
|
||||||
from ereuse_devicehub.resources.action.models import Snapshot, Trade
|
from ereuse_devicehub.resources.action.models import Snapshot, Trade
|
||||||
|
@ -1761,7 +1761,6 @@ class UserTrustsForm(FlaskForm):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
# import pdb; pdb.set_trace()
|
|
||||||
if not self.show():
|
if not self.show():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1770,11 +1769,34 @@ class UserTrustsForm(FlaskForm):
|
||||||
|
|
||||||
if self.snapshot_type.data == 'update' and not self.unic():
|
if self.snapshot_type.data == 'update' and not self.unic():
|
||||||
self.device.reliable()
|
self.device.reliable()
|
||||||
|
txt = "This devices is assigned as reliable for the user."
|
||||||
|
self.error_log(txt)
|
||||||
|
|
||||||
if self.snapshot_type.data == 'new_device' and self.unic():
|
if self.snapshot_type.data == 'new_device' and self.unic():
|
||||||
self.device.unreliable()
|
self.device.unreliable()
|
||||||
|
txt = "This devices is assigned as unreliable for the user "
|
||||||
|
txt += "and never is possible to do an update of this device."
|
||||||
|
self.error_log(txt)
|
||||||
|
|
||||||
if commit:
|
if commit:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return self.snapshot
|
return self.snapshot
|
||||||
|
|
||||||
|
def error_log(self, txt):
|
||||||
|
snapshot = self.get_first_snapshot()
|
||||||
|
error = SnapshotsLog(
|
||||||
|
description=txt,
|
||||||
|
snapshot=snapshot,
|
||||||
|
snapshot_uuid=snapshot.uuid,
|
||||||
|
severity=Severity.Error,
|
||||||
|
sid=snapshot.sid,
|
||||||
|
version="{}".format(snapshot.version),
|
||||||
|
)
|
||||||
|
db.session.add(error)
|
||||||
|
|
||||||
|
def get_first_snapshot(self):
|
||||||
|
device = self.snapshot.device
|
||||||
|
for ac in device.actions:
|
||||||
|
if ac.type == 'Snapshot':
|
||||||
|
return ac
|
||||||
|
|
|
@ -46,7 +46,7 @@ class SnapshotsLog(Thing):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def get_device(self):
|
def get_device(self):
|
||||||
if self.snapshot and self.snapshot.active:
|
if self.snapshot:
|
||||||
if self.snapshot.device.binding:
|
if self.snapshot.device.binding:
|
||||||
return self.snapshot.device.binding.device.devicehub_id
|
return self.snapshot.device.binding.device.devicehub_id
|
||||||
return self.snapshot.device.devicehub_id
|
return self.snapshot.device.devicehub_id
|
||||||
|
|
Reference in New Issue