This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/resources/event/views.py

44 lines
1.3 KiB
Python
Raw Normal View History

2018-04-27 17:16:43 +00:00
from distutils.version import StrictVersion
from flask import request
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.device.sync import Sync
from ereuse_devicehub.resources.event.enums import SoftwareType
from ereuse_devicehub.resources.event.models import Event, Snapshot, TestHardDrive
2018-04-10 15:06:39 +00:00
from teal.resource import View
class EventView(View):
2018-04-27 17:16:43 +00:00
def one(self, id: int):
2018-04-10 15:06:39 +00:00
"""Gets one event."""
2018-04-27 17:16:43 +00:00
return Event.query.filter_by(id=id).one()
SUPPORTED_WORKBENCH = StrictVersion('11.0')
class SnapshotView(View):
def post(self):
"""Creates a Snapshot."""
snapshot = Snapshot(**request.get_json()) # todo put this in schema.load()?
# noinspection PyArgumentList
c = snapshot.components if snapshot.software == SoftwareType.Workbench else None
snapshot.device, snapshot.components, snapshot.events = Sync.run(snapshot.device, c)
db.session.add(snapshot)
# transform it back
return self.schema.jsonify(snapshot)
class TestHardDriveView(View):
def post(self):
t = request.get_json() # type: dict
# noinspection PyArgumentList
test = TestHardDrive(snapshot_id=t.pop('snapshot'), device_id=t.pop('device'), **t)
return test
class StressTestView(View):
def post(self):
t = request.get_json() # type: dict