Fixed stuff
This commit is contained in:
parent
8a82bf07c5
commit
536fc2a164
@ -4,6 +4,5 @@ from sqlalchemy.dialects.postgresql import UUID
|
||||
|
||||
|
||||
class Default(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, auto_increment=True)
|
||||
# aimodel_id = db.Column(UUID(as_uuid=True), db.ForeignKey("AIModel.id"), nullable=False)
|
||||
# aimodel = db.relationship("AIModel", backref=db.backref("default", lazy=True))
|
||||
aimodel_id = db.Column(UUID(as_uuid=True), db.ForeignKey("ai_model.id"), nullable=False, primary_key=True)
|
||||
aimodel = db.relationship("AIModel", backref=db.backref("default", lazy=True, cascade="save-update, merge, delete, delete-orphan"))
|
||||
|
@ -5,5 +5,11 @@ from model import AIModel
|
||||
|
||||
|
||||
class AIModelSchema(ModelSchema):
|
||||
|
||||
default = fields.Method("boolize_default", dump_only=True)
|
||||
|
||||
def boolize_default(self, ai_model) -> bool:
|
||||
return bool(ai_model.default)
|
||||
|
||||
class Meta:
|
||||
model = AIModel
|
||||
|
@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
from marshmallow import fields
|
||||
from marshmallow_sqlalchemy import ModelSchema
|
||||
from marshmallow import fields, Schema
|
||||
|
||||
|
||||
class DefaultSchema(ModelSchema):
|
||||
class DefaultSchema(Schema):
|
||||
id = fields.UUID()
|
||||
|
@ -104,29 +104,29 @@ class ModelView(FlaskView):
|
||||
else:
|
||||
m = AIModel.query.fiter_by(id=_id).first_or_404()
|
||||
|
||||
try:
|
||||
data = storage.connection.get_object(current_app.config['MINIO_BUCKET_NAME'], str(m.id))
|
||||
except NoSuchKey:
|
||||
abort(500, "The ID is stored in the database but not int the Object Store")
|
||||
|
||||
return Response(data.stream(), mimetype=data.headers['Content-type'])
|
||||
return "asd"
|
||||
|
||||
@route('<_id>/details')
|
||||
def get_details(self, _id: str):
|
||||
|
||||
if _id == "$default":
|
||||
default = Default.query.first_or_404() # TODO: Kitalálni, hogy inkább a latestestest-el térjen-e vissza
|
||||
m = default.default
|
||||
m = default.aimodel
|
||||
else:
|
||||
m = AIModel.query.fiter_by(id=_id).first_or_404()
|
||||
m = AIModel.query.filter_by(id=_id).first_or_404()
|
||||
|
||||
return jsonify(self.aimodel_schema.dump(m))
|
||||
|
||||
def delete(self, _id: str):
|
||||
|
||||
m = AIModel.query.fiter_by(id=_id).first_or_404()
|
||||
if _id == '$default':
|
||||
default = Default.query.first_or_404()
|
||||
m = default.aimodel
|
||||
else:
|
||||
m = AIModel.query.fiter_by(id=_id).first_or_404()
|
||||
|
||||
storage.connection.remove_object(current_app.config['MINIO_BUCKET_NAME'], m.id)
|
||||
storage.connection.remove_object(current_app.config['MINIO_MODEL_BUCKET_NAME'], str(m.id))
|
||||
storage.connection.remove_object(current_app.config['MINIO_MEANS_BUCKET_NAME'], str(m.id))
|
||||
|
||||
db.session.delete(m)
|
||||
db.session.commit()
|
||||
@ -138,14 +138,14 @@ class ModelView(FlaskView):
|
||||
def put_default(self):
|
||||
|
||||
try:
|
||||
req = self.default_schema.load(request.json())
|
||||
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()
|
||||
m = AIModel.query.filter_by(id=req['id']).first_or_404()
|
||||
|
||||
Default.query.delete()
|
||||
new_default = Default(m)
|
||||
new_default = Default(aimodel=m)
|
||||
db.session.add(new_default)
|
||||
db.session.commit()
|
||||
|
||||
|
@ -16,4 +16,5 @@ numpy
|
||||
eyed3
|
||||
pydub
|
||||
scipy
|
||||
matplotlib
|
||||
matplotlib
|
||||
sklearn
|
Loading…
Reference in New Issue
Block a user