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/lot/views.py

26 lines
721 B
Python
Raw Normal View History

2018-08-08 19:25:53 +00:00
import uuid
from flask import current_app as app, request
2018-09-07 10:38:02 +00:00
from teal.resource import View
2018-08-08 19:25:53 +00:00
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.lot.models import Lot
class LotView(View):
def post(self):
json = request.get_json(validate=False)
e = app.resources[json['type']].schema.load(json)
Model = db.Model._decl_class_registry.data[json['type']]()
lot = Model(**e)
db.session.add(lot)
db.session.commit()
ret = self.schema.jsonify(lot)
ret.status_code = 201
return ret
def one(self, id: uuid.UUID):
"""Gets one event."""
event = Lot.query.filter_by(id=id).one()
return self.schema.jsonify(event)