not required chassis in all system

This commit is contained in:
Cayo Puigdefabregas 2020-12-17 10:45:01 +01:00
parent aef220a5dc
commit 5241c73a98
5 changed files with 30 additions and 28 deletions

View File

@ -430,9 +430,12 @@ class Computer(Device):
receiver = db.relationship(User, primaryjoin=receiver_id == User.id)
deliverynote_address = db.Column(CIText(), nullable=True)
def __init__(self, chassis, **kwargs) -> None:
chassis = ComputerChassis(chassis)
super().__init__(chassis=chassis, **kwargs)
def __init__(self, *args, **kwargs) -> None:
if args:
chassis = ComputerChassis(args[0])
super().__init__(chassis=chassis, **kwargs)
else:
super().__init__(*args, **kwargs)
@property
def actions(self) -> list:

View File

@ -101,7 +101,6 @@ class Computer(Device):
collection_class=OrderedSet,
description='The components that are inside this computer.')
chassis = EnumField(enums.ComputerChassis,
required=True,
description=m.Computer.chassis.comment)
ram_size = Integer(dump_only=True,
data_key='ramSize',

View File

@ -112,16 +112,27 @@ class DeviceSearch(db.Model):
if isinstance(device, Computer):
# Aggregate the values of all the components of pc
Comp = aliased(Component)
tokens.extend((
(db.func.string_agg(db.cast(Comp.id, db.TEXT), ' '), search.Weight.D),
(db.func.string_agg(Comp.model, ' '), search.Weight.C),
(db.func.string_agg(Comp.manufacturer, ' '), search.Weight.D),
(db.func.string_agg(Comp.serial_number, ' '), search.Weight.B),
(db.func.string_agg(Comp.type, ' '), search.Weight.B),
('Computer', search.Weight.C),
('PC', search.Weight.C),
(inflection.humanize(device.chassis.name), search.Weight.B),
))
if device.chassis:
tokens.extend((
(db.func.string_agg(db.cast(Comp.id, db.TEXT), ' '), search.Weight.D),
(db.func.string_agg(Comp.model, ' '), search.Weight.C),
(db.func.string_agg(Comp.manufacturer, ' '), search.Weight.D),
(db.func.string_agg(Comp.serial_number, ' '), search.Weight.B),
(db.func.string_agg(Comp.type, ' '), search.Weight.B),
('Computer', search.Weight.C),
('PC', search.Weight.C),
(inflection.humanize(device.chassis.name), search.Weight.B),
))
else:
tokens.extend((
(db.func.string_agg(db.cast(Comp.id, db.TEXT), ' '), search.Weight.D),
(db.func.string_agg(Comp.model, ' '), search.Weight.C),
(db.func.string_agg(Comp.manufacturer, ' '), search.Weight.D),
(db.func.string_agg(Comp.serial_number, ' '), search.Weight.B),
(db.func.string_agg(Comp.type, ' '), search.Weight.B),
('Computer', search.Weight.C),
('PC', search.Weight.C),
))
properties = session \
.query(search.Search.vectorize(*tokens)) \

View File

@ -1,5 +1,5 @@
from contextlib import suppress
from enum import Enum, IntEnum, unique, EnumMeta
from enum import Enum, IntEnum, unique
from typing import Set, Union
import inflection
@ -207,20 +207,9 @@ class DisplayTech(Enum):
return self.name
class DefaultEnumMeta(EnumMeta):
default = object()
def __call__(cls, value=default, *args, **kwargs):
# import pdb; pdb.set_trace()
if value is DefaultEnumMeta.default:
# Assume the first enum is default
return next(iter(cls))
return super().__call__(value, *args, **kwargs)
@unique
class ComputerChassis(Enum, metaclass=DefaultEnumMeta):
class ComputerChassis(Enum):
"""The chassis of a computer."""
Nothing = None
Tower = 'Tower'
Docking = 'Docking'
AllInOne = 'All in one'

View File

@ -684,7 +684,7 @@ def test_snapshot_not_failed_null_chassis(app: Devicehub, user: UserClient):
tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
snapshot_error = file('desktop-9644w8n-lenovo-0169622.snapshot')
snapshot_error['device']['chassis'] = 'Nothing'
snapshot_error['device']['chassis'] = None
uuid = snapshot_error['uuid']
snapshot, res = user.post(res=Snapshot, data=snapshot_error)