Implemeted default pooter

This commit is contained in:
Pünkösd Marcell 2020-04-14 14:02:35 +02:00
parent f97228b61c
commit 7fcc4bfa37
2 changed files with 16 additions and 4 deletions

View File

@ -1,9 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from marshmallow import fields from marshmallow import fields
from marshmallow_sqlalchemy import ModelSchema from marshmallow_sqlalchemy import ModelSchema
from model import Default
class DefaultSchema(ModelSchema): class DefaultSchema(ModelSchema):
class Meta: id = fields.UUID()
model = Default

View File

@ -5,6 +5,7 @@ from flask_classful import FlaskView, route
from model import db, Default, AIModel from model import db, Default, AIModel
from minio.error import BucketAlreadyExists, BucketAlreadyOwnedByYou, ResponseError, NoSuchKey from minio.error import BucketAlreadyExists, BucketAlreadyOwnedByYou, ResponseError, NoSuchKey
from schemas import AIModelSchema, DefaultSchema from schemas import AIModelSchema, DefaultSchema
from marshmallow.exceptions import ValidationError
from utils import json_required, storage from utils import json_required, storage
@ -56,4 +57,17 @@ class ModelView(FlaskView):
@json_required @json_required
@route('$default', methods=['PUT']) @route('$default', methods=['PUT'])
def put_default(self): def put_default(self):
return jsonify({})
try:
req = self.default_schema.load(request.json())
except ValidationError as e:
abort(404, str(e))
m = AIModel.query.fiter_by(id=req['id']).first_or_404()
Default.query.delete()
new_default = Default(m)
db.session.add(new_default)
db.session.commit()
return jsonify(self.aimodel_schema.dump(m))