Beispiel #1
0
class DisplayMixin:
    __doc__ = m.DisplayMixin.__doc__
    size = Float(description=m.DisplayMixin.size.comment,
                 validate=Range(2, 150),
                 required=True)
    technology = EnumField(enums.DisplayTech,
                           description=m.DisplayMixin.technology.comment)
    resolution_width = Integer(
        data_key='resolutionWidth',
        validate=Range(10, 20000),
        description=m.DisplayMixin.resolution_width.comment,
        required=True)
    resolution_height = Integer(
        data_key='resolutionHeight',
        validate=Range(10, 20000),
        description=m.DisplayMixin.resolution_height.comment,
        required=True)
    refresh_rate = Integer(data_key='refreshRate', validate=Range(10, 1000))
    contrast_ratio = Integer(data_key='contrastRatio',
                             validate=Range(100, 100000))
    touchable = Boolean(description=m.DisplayMixin.touchable.comment)
    aspect_ratio = String(dump_only=True,
                          description=m.DisplayMixin.aspect_ratio.__doc__)
    widescreen = Boolean(dump_only=True,
                         description=m.DisplayMixin.widescreen.__doc__)
Beispiel #2
0
class Computer(Device):
    __doc__ = m.Computer.__doc__
    components = NestedOn(
        'Component',
        many=True,
        dump_only=True,
        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',
                       description=m.Computer.ram_size.__doc__)
    data_storage_size = Integer(
        dump_only=True,
        data_key='dataStorageSize',
        description=m.Computer.data_storage_size.__doc__)
    processor_model = Str(dump_only=True,
                          data_key='processorModel',
                          description=m.Computer.processor_model.__doc__)
    graphic_card_model = Str(dump_only=True,
                             data_key='graphicCardModel',
                             description=m.Computer.graphic_card_model.__doc__)
    network_speeds = List(Integer(dump_only=True),
                          dump_only=True,
                          data_key='networkSpeeds',
                          description=m.Computer.network_speeds.__doc__)
    privacy = NestedOn('Event',
                       many=True,
                       dump_only=True,
                       collection_class=set,
                       description=m.Computer.privacy.__doc__)
Beispiel #3
0
class Battery(Component):
    __doc__ = m.Battery

    wireless = Boolean(description=m.Battery.wireless.comment)
    technology = EnumField(enums.BatteryTechnology,
                           description=m.Battery.technology.comment)
    size = Integer(required=True, description=m.Battery.size.comment)
Beispiel #4
0
class Price(EventWithOneDevice):
    __doc__ = m.Price.__doc__
    currency = EnumField(Currency,
                         required=True,
                         description=m.Price.currency.comment)
    price = Decimal(places=m.Price.SCALE,
                    rounding=m.Price.ROUND,
                    required=True,
                    description=m.Price.price.comment)
    software = EnumField(PriceSoftware,
                         dump_only=True,
                         description=m.Price.software.comment)
    version = Version(dump_only=True, description=m.Price.version.comment)
    rating = NestedOn(AggregateRate,
                      dump_only=True,
                      description=m.Price.rating_id.comment)
Beispiel #5
0
 class FindArgs(MarshmallowSchema):
     """
     Allowed arguments for the ``find``
     method (GET collection) endpoint
     """
     format = EnumField(LotFormat, missing=None)
     search = f.Str(missing=None)
Beispiel #6
0
class DataStorage(Component):
    __doc__ = m.DataStorage.__doc__

    size = Integer(validate=Range(0, 10**8),
                   unit=UnitCodes.mbyte,
                   description=m.DataStorage.size.comment)
    interface = EnumField(enums.DataStorageInterface)
    privacy = NestedOn('Event', dump_only=True)
Beispiel #7
0
class Agent(Thing):
    id = ma_fields.UUID(dump_only=True)
    name = SanitizedStr(validate=ma_validate.Length(max=STR_SM_SIZE))
    tax_id = SanitizedStr(lower=True,
                          validate=ma_validate.Length(max=STR_SM_SIZE),
                          data_key='taxId')
    country = EnumField(enums.Country)
    telephone = Phone()
    email = Email()
Beispiel #8
0
class MeasureBattery(Test):
    __doc__ = m.MeasureBattery.__doc__
    size = Integer(required=True, description=m.MeasureBattery.size.comment)
    voltage = Integer(required=True,
                      description=m.MeasureBattery.voltage.comment)
    cycle_count = Integer(required=True,
                          description=m.MeasureBattery.cycle_count.comment)
    health = EnumField(enums.BatteryHealth,
                       description=m.MeasureBattery.health.comment)
Beispiel #9
0
class WorkbenchRate(ManualRate):
    __doc__ = m.WorkbenchRate.__doc__
    processor = Float()
    ram = Float()
    data_storage = Float()
    graphic_card = Float()
    bios = Float()
    bios_range = EnumField(Bios,
                           description=m.WorkbenchRate.bios_range.comment,
                           data_key='biosRange')
    data_storage_range = EnumField(RatingRange,
                                   dump_only=True,
                                   data_key='dataStorageRange')
    ram_range = EnumField(RatingRange, dump_only=True, data_key='ramRange')
    processor_range = EnumField(RatingRange,
                                dump_only=True,
                                data_key='processorRange')
    graphic_card_range = EnumField(RatingRange,
                                   dump_only=True,
                                   data_key='graphicCardRange')
Beispiel #10
0
class Computer(Device):
    __doc__ = m.Computer.__doc__
    # TODO TimeOut 1. Comment components if there are time out.
    components = NestedOn(
        'Component',
        many=True,
        dump_only=True,
        collection_class=OrderedSet,
        description='The components that are inside this computer.')
    chassis = EnumField(enums.ComputerChassis,
                        description=m.Computer.chassis.comment)
    ram_size = Integer(dump_only=True,
                       data_key='ramSize',
                       description=m.Computer.ram_size.__doc__)
    data_storage_size = Integer(
        dump_only=True,
        data_key='dataStorageSize',
        description=m.Computer.data_storage_size.__doc__)
    processor_model = Str(dump_only=True,
                          data_key='processorModel',
                          description=m.Computer.processor_model.__doc__)
    graphic_card_model = Str(dump_only=True,
                             data_key='graphicCardModel',
                             description=m.Computer.graphic_card_model.__doc__)
    network_speeds = List(Integer(dump_only=True),
                          dump_only=True,
                          data_key='networkSpeeds',
                          description=m.Computer.network_speeds.__doc__)
    privacy = NestedOn('Action',
                       many=True,
                       dump_only=True,
                       collection_class=set,
                       description=m.Computer.privacy.__doc__)
    amount = Integer(validate=f.validate.Range(min=0, max=100),
                     description=m.Computer.amount.__doc__)
    # author_id = NestedOn(s_user.User, only_query='author_id')
    owner_id = UUID(data_key='ownerID')
    transfer_state = EnumField(enums.TransferState,
                               description=m.Computer.transfer_state.comment)
    receiver_id = UUID(data_key='receiverID')
Beispiel #11
0
class Printer(Device):
    __doc__ = m.Printer.__doc__

    wireless = Boolean(required=True,
                       missing=False,
                       description=m.Printer.wireless.comment)
    scanning = Boolean(required=True,
                       missing=False,
                       description=m.Printer.scanning.comment)
    technology = EnumField(enums.PrinterTechnology,
                           required=True,
                           description=m.Printer.technology.comment)
    monochrome = Boolean(required=True,
                         missing=True,
                         description=m.Printer.monochrome.comment)
Beispiel #12
0
class TestDataStorage(Test):
    __doc__ = m.TestDataStorage.__doc__
    length = EnumField(TestDataStorageLength, required=True)
    status = SanitizedStr(lower=True,
                          validate=Length(max=STR_SIZE),
                          required=True)
    lifetime = TimeDelta(precision=TimeDelta.HOURS)
    assessment = Boolean()
    reallocated_sector_count = Integer(data_key='reallocatedSectorCount')
    power_cycle_count = Integer(data_key='powerCycleCount')
    reported_uncorrectable_errors = Integer(
        data_key='reportedUncorrectableErrors')
    command_timeout = Integer(data_key='commandTimeout')
    current_pending_sector_count = Integer(
        data_key='currentPendingSectorCount')
    offline_uncorrectable = Integer(data_key='offlineUncorrectable')
    remaining_lifetime_percentage = Integer(
        data_key='remainingLifetimePercentage')
Beispiel #13
0
class AggregateRate(Rate):
    __doc__ = m.AggregateRate.__doc__
    workbench = NestedOn(WorkbenchRate,
                         dump_only=True,
                         description=m.AggregateRate.workbench_id.comment)
    manual = NestedOn(ManualRate,
                      dump_only=True,
                      description=m.AggregateRate.manual_id.comment)
    processor = Float(dump_only=True)
    ram = Float(dump_only=True)
    data_storage = Float(dump_only=True)
    graphic_card = Float(dump_only=True)
    bios = EnumField(Bios, dump_only=True)
    bios_range = EnumField(Bios,
                           description=m.WorkbenchRate.bios_range.comment,
                           data_key='biosRange')
    appearance_range = EnumField(
        AppearanceRange,
        required=True,
        data_key='appearanceRange',
        description=m.ManualRate.appearance_range.comment)
    functionality_range = EnumField(
        FunctionalityRange,
        required=True,
        data_key='functionalityRange',
        description=m.ManualRate.functionality_range.comment)
    labelling = Boolean(description=m.ManualRate.labelling.comment)
    data_storage_range = EnumField(RatingRange,
                                   dump_only=True,
                                   data_key='dataStorageRange')
    ram_range = EnumField(RatingRange, dump_only=True, data_key='ramRange')
    processor_range = EnumField(RatingRange,
                                dump_only=True,
                                data_key='processorRange')
    graphic_card_range = EnumField(RatingRange,
                                   dump_only=True,
                                   data_key='graphicCardRange')
Beispiel #14
0
class Event(Thing):
    __doc__ = m.Event.__doc__
    id = UUID(dump_only=True)
    name = SanitizedStr(default='',
                        validate=Length(max=STR_BIG_SIZE),
                        description=m.Event.name.comment)
    closed = Boolean(missing=True, description=m.Event.closed.comment)
    severity = EnumField(Severity, description=m.Event.severity.comment)
    description = SanitizedStr(default='',
                               description=m.Event.description.comment)
    start_time = DateTime(data_key='startTime',
                          description=m.Event.start_time.comment)
    end_time = DateTime(data_key='endTime',
                        description=m.Event.end_time.comment)
    snapshot = NestedOn('Snapshot', dump_only=True)
    agent = NestedOn(s_agent.Agent, description=m.Event.agent_id.comment)
    author = NestedOn(s_user.User, dump_only=True, exclude=('token', ))
    components = NestedOn(s_device.Component, dump_only=True, many=True)
    parent = NestedOn(s_device.Computer,
                      dump_only=True,
                      description=m.Event.parent_id.comment)
    url = URL(dump_only=True, description=m.Event.url.__doc__)
Beispiel #15
0
class Deliverynote(Thing):
    id = f.UUID(dump_only=True)
    document_id = SanitizedStr(validate=f.validate.Length(max=STR_SIZE),
                               required=True,
                               data_key='documentID')
    creator = NestedOn(s_user.User, dump_only=True)
    supplier_email = SanitizedStr(validate=f.validate.Length(max=STR_SIZE),
                                  load_only=True,
                                  required=True,
                                  data_key='supplierEmail')
    supplier = NestedOn(s_user.User, dump_only=True)
    receiver = NestedOn(s_user.User, dump_only=True)
    date = f.DateTime('iso', required=True)
    amount = f.Integer(validate=f.validate.Range(min=0, max=100),
                       description=m.Deliverynote.amount.__doc__)
    expected_devices = f.List(f.Dict,
                              required=True,
                              data_key='expectedDevices')
    transferred_devices = f.List(f.Integer(),
                                 required=False,
                                 data_key='transferredDevices')
    transfer_state = EnumField(TransferState,
                               description=m.Lot.transfer_state.comment)
Beispiel #16
0
class Receive(EventWithMultipleDevices):
    __doc__ = m.Receive.__doc__
    role = EnumField(ReceiverRole)
Beispiel #17
0
class Keyboard(ComputerAccessory):
    __doc__ = m.Keyboard.__doc__

    layout = EnumField(Layouts)
Beispiel #18
0
class Step(Schema):
    __doc__ = m.Step.__doc__
    type = String(description='Only required when it is nested.')
    start_time = DateTime(required=True, data_key='startTime')
    end_time = DateTime(required=True, data_key='endTime')
    severity = EnumField(Severity, description=m.Event.severity.comment)
Beispiel #19
0
class Device(Thing):
    __doc__ = m.Device.__doc__
    id = Integer(description=m.Device.id.comment, dump_only=True)
    hid = SanitizedStr(lower=True,
                       dump_only=True,
                       description=m.Device.hid.comment)
    tags = NestedOn('Tag',
                    many=True,
                    collection_class=OrderedSet,
                    description='A set of tags that identify the device.')
    model = SanitizedStr(lower=True,
                         validate=Length(max=STR_BIG_SIZE),
                         description=m.Device.model.comment)
    manufacturer = SanitizedStr(lower=True,
                                validate=Length(max=STR_SIZE),
                                description=m.Device.manufacturer.comment)
    serial_number = SanitizedStr(lower=True,
                                 validate=Length(max=STR_BIG_SIZE),
                                 data_key='serialNumber')
    brand = SanitizedStr(validate=Length(max=STR_BIG_SIZE),
                         description=m.Device.brand.comment)
    generation = Integer(validate=Range(1, 100),
                         description=m.Device.generation.comment)
    weight = Float(validate=Range(0.1, 5),
                   unit=UnitCodes.kgm,
                   description=m.Device.weight.comment)
    width = Float(validate=Range(0.1, 5),
                  unit=UnitCodes.m,
                  description=m.Device.width.comment)
    height = Float(validate=Range(0.1, 5),
                   unit=UnitCodes.m,
                   description=m.Device.height.comment)
    depth = Float(validate=Range(0.1, 5),
                  unit=UnitCodes.m,
                  description=m.Device.depth.comment)
    events = NestedOn('Event',
                      many=True,
                      dump_only=True,
                      description=m.Device.events.__doc__)
    events_one = NestedOn('Event',
                          many=True,
                          load_only=True,
                          collection_class=OrderedSet)
    problems = NestedOn('Event',
                        many=True,
                        dump_only=True,
                        description=m.Device.problems.__doc__)
    url = URL(dump_only=True, description=m.Device.url.__doc__)
    lots = NestedOn(
        'Lot',
        many=True,
        dump_only=True,
        description='The lots where this device is directly under.')
    rate = NestedOn('AggregateRate',
                    dump_only=True,
                    description=m.Device.rate.__doc__)
    price = NestedOn('Price',
                     dump_only=True,
                     description=m.Device.price.__doc__)
    trading = EnumField(states.Trading,
                        dump_only=True,
                        description=m.Device.trading.__doc__)
    physical = EnumField(states.Physical,
                         dump_only=True,
                         description=m.Device.physical.__doc__)
    physical_possessor = NestedOn('Agent',
                                  dump_only=True,
                                  data_key='physicalPossessor')
    production_date = DateTime('iso',
                               description=m.Device.updated.comment,
                               data_key='productionDate')
    working = NestedOn('Event',
                       many=True,
                       dump_only=True,
                       description=m.Device.working.__doc__)

    @pre_load
    def from_events_to_events_one(self, data: dict):
        """
        Not an elegant way of allowing submitting events to a device
        (in the context of Snapshots) without creating an ``events``
        field at the model (which is not possible).
        :param data:
        :return:
        """
        # Note that it is secure to allow uploading events_one
        # as the only time an user can send a device object is
        # in snapshots.
        data['events_one'] = data.pop('events', [])
        return data

    @post_load
    def validate_snapshot_events(self, data):
        """Validates that only snapshot-related events can be uploaded."""
        from ereuse_devicehub.resources.event.models import EraseBasic, Test, Rate, Install, \
            Benchmark
        for event in data['events_one']:
            if not isinstance(event,
                              (Install, EraseBasic, Rate, Test, Benchmark)):
                raise ValidationError('You cannot upload {}'.format(event),
                                      field_names=['events'])
Beispiel #20
0
class Laptop(Computer):
    __doc__ = m.Laptop.__doc__
    layout = EnumField(Layouts, description=m.Laptop.layout.comment)
Beispiel #21
0
class Snapshot(EventWithOneDevice):
    __doc__ = m.Snapshot.__doc__
    """
    The Snapshot updates the state of the device with information about
    its components and events performed at them.

    See docs for more info.
    """
    uuid = UUID()
    software = EnumField(
        SnapshotSoftware,
        required=True,
        description='The software that generated this Snapshot.')
    version = Version(required=True,
                      description='The version of the software.')
    events = NestedOn(Event, many=True, dump_only=True)
    expected_events = List(
        EnumField(SnapshotExpectedEvents),
        data_key='expectedEvents',
        description='Keep open this Snapshot until the following events'
        'are performed. Setting this value will activate'
        'the async Snapshot.')

    elapsed = TimeDelta(precision=TimeDelta.SECONDS)
    components = NestedOn(
        s_device.Component,
        many=True,
        description='A list of components that are inside of the device'
        'at the moment of this Snapshot.'
        'Order is preserved, so the component num 0 when'
        'submitting is the component num 0 when returning it back.')

    @validates_schema
    def validate_workbench_version(self, data: dict):
        if data['software'] == SnapshotSoftware.Workbench:
            if data['version'] < app.config['MIN_WORKBENCH']:
                raise ValidationError('Min. supported Workbench version is '
                                      '{} but yours is {}.'.format(
                                          app.config['MIN_WORKBENCH'],
                                          data['version']),
                                      field_names=['version'])

    @validates_schema
    def validate_components_only_workbench(self, data: dict):
        if data['software'] != SnapshotSoftware.Workbench:
            if data.get('components', None) is not None:
                raise ValidationError('Only Workbench can add component info',
                                      field_names=['components'])

    @validates_schema
    def validate_only_workbench_fields(self, data: dict):
        """Ensures workbench has ``elapsed`` and ``uuid`` and no others."""
        # todo test
        if data['software'] == SnapshotSoftware.Workbench:
            if not data.get('uuid', None):
                raise ValidationError(
                    'Snapshots from Workbench must have uuid',
                    field_names=['uuid'])
            if data.get('elapsed', None) is None:
                raise ValidationError(
                    'Snapshots from Workbench must have elapsed',
                    field_names=['elapsed'])
        else:
            if data.get('uuid', None):
                raise ValidationError(
                    'Only Snapshots from Workbench can have uuid',
                    field_names=['uuid'])
            if data.get('elapsed', None):
                raise ValidationError(
                    'Only Snapshots from Workbench can have elapsed',
                    field_names=['elapsed'])
Beispiel #22
0
class ErasePhysical(EraseBasic):
    __doc__ = m.ErasePhysical.__doc__
    method = EnumField(PhysicalErasureMethod,
                       description=PhysicalErasureMethod.__doc__)
Beispiel #23
0
class EraseBasic(EventWithOneDevice):
    __doc__ = m.EraseBasic.__doc__
    steps = NestedOn('Step', many=True)
    standards = f.List(EnumField(enums.ErasureStandards), dump_only=True)
    certificate = URL(dump_only=True)