add device for form using the snapshot form
This commit is contained in:
parent
2fde6e5cf5
commit
bd2f261dc3
|
@ -9,7 +9,7 @@ from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.device.models import Device, Computer, Smartphone, Cellphone, \
|
from ereuse_devicehub.resources.device.models import Device, Computer, Smartphone, Cellphone, \
|
||||||
Tablet, Monitor, Mouse, Keyboard, \
|
Tablet, Monitor, Mouse, Keyboard, \
|
||||||
MemoryCardReader, SAI
|
MemoryCardReader, SAI
|
||||||
from ereuse_devicehub.resources.action.models import RateComputer, Snapshot
|
from ereuse_devicehub.resources.action.models import RateComputer, Snapshot, VisualTest
|
||||||
from ereuse_devicehub.resources.action.schemas import Snapshot as SnapshotSchema
|
from ereuse_devicehub.resources.action.schemas import Snapshot as SnapshotSchema
|
||||||
from ereuse_devicehub.resources.lot.models import Lot
|
from ereuse_devicehub.resources.lot.models import Lot
|
||||||
from ereuse_devicehub.resources.enums import SnapshotSoftware, Severity
|
from ereuse_devicehub.resources.enums import SnapshotSoftware, Severity
|
||||||
|
@ -245,7 +245,7 @@ class NewDeviceForm(FlaskForm):
|
||||||
"MemoryCardReader": MemoryCardReader}
|
"MemoryCardReader": MemoryCardReader}
|
||||||
|
|
||||||
if not self.generation.data:
|
if not self.generation.data:
|
||||||
self.generation.data = 0
|
self.generation.data = 1
|
||||||
|
|
||||||
if not self.weight.data:
|
if not self.weight.data:
|
||||||
self.weight.data = 0.1
|
self.weight.data = 0.1
|
||||||
|
@ -265,7 +265,7 @@ class NewDeviceForm(FlaskForm):
|
||||||
if not is_valid:
|
if not is_valid:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.generation.data < 0:
|
if self.generation.data < 1:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.weight.data < 0.1:
|
if self.weight.data < 0.1:
|
||||||
|
@ -292,12 +292,48 @@ class NewDeviceForm(FlaskForm):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
self.instance = self.devices[self.type.data]()
|
|
||||||
self.populate_obj(self.instance)
|
json_snapshot = {
|
||||||
db.session.add(self.instance)
|
'type': 'Snapshot',
|
||||||
# import pdb; pdb.set_trace()
|
'software': 'Web',
|
||||||
db.session.commit()
|
'version': '11.0',
|
||||||
return self.instance
|
'device': {
|
||||||
|
'type': self.type.data,
|
||||||
|
'model': self.model.data,
|
||||||
|
'manufacturer': self.manufacturer.data,
|
||||||
|
'serialNumber': self.serial_number.data,
|
||||||
|
'brand': self.brand.data,
|
||||||
|
'version': self.version.data,
|
||||||
|
'generation': self.generation.data,
|
||||||
|
'sku': self.sku.data,
|
||||||
|
'weight': self.weight.data,
|
||||||
|
'width': self.width.data,
|
||||||
|
'height': self.height.data,
|
||||||
|
'depth': self.depth.data,
|
||||||
|
'variant': self.variant.data,
|
||||||
|
'image': self.image.data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.imei.data or self.meid.data:
|
||||||
|
json_snapshot['device']['imei'] = self.imei.data
|
||||||
|
json_snapshot['device']['meid'] = self.meid.data
|
||||||
|
|
||||||
|
if self.resolution.data or self.screen.data:
|
||||||
|
json_snapshot['device']['resolution'] = self.resolution.data
|
||||||
|
json_snapshot['device']['screen'] = self.screen.data
|
||||||
|
|
||||||
|
if self.appearance.data or self.functionality.data:
|
||||||
|
json_snapshot['device']['actions'] = [{
|
||||||
|
'type': 'VisualTest',
|
||||||
|
'appearanceRange': self.appearance.data,
|
||||||
|
'functionalityRange': self.functionality.data
|
||||||
|
}]
|
||||||
|
|
||||||
|
upload_form = UploadSnapshotForm()
|
||||||
|
upload_form.snapshots = [("Web", json_snapshot)]
|
||||||
|
upload_form.result = {}
|
||||||
|
upload_form.save()
|
||||||
|
|
||||||
|
|
||||||
class NewActionForm(FlaskForm):
|
class NewActionForm(FlaskForm):
|
||||||
|
|
Reference in New Issue