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
Xavier Bustamante Talavera 804a696390 Correctly place teal imports
2018-09-07 12:38:02 +02:00

26 lines
721 B
Python

import uuid
from flask import current_app as app, request
from teal.resource import View
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)