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):
|
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("ai_model.id"), nullable=False, primary_key=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, cascade="save-update, merge, delete, delete-orphan"))
|
||||||
# aimodel = db.relationship("AIModel", backref=db.backref("default", lazy=True))
|
|
||||||
|
@ -5,5 +5,11 @@ from model import AIModel
|
|||||||
|
|
||||||
|
|
||||||
class AIModelSchema(ModelSchema):
|
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:
|
class Meta:
|
||||||
model = AIModel
|
model = AIModel
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from marshmallow import fields
|
from marshmallow import fields, Schema
|
||||||
from marshmallow_sqlalchemy import ModelSchema
|
|
||||||
|
|
||||||
|
|
||||||
class DefaultSchema(ModelSchema):
|
class DefaultSchema(Schema):
|
||||||
id = fields.UUID()
|
id = fields.UUID()
|
||||||
|
@ -104,29 +104,29 @@ class ModelView(FlaskView):
|
|||||||
else:
|
else:
|
||||||
m = AIModel.query.fiter_by(id=_id).first_or_404()
|
m = AIModel.query.fiter_by(id=_id).first_or_404()
|
||||||
|
|
||||||
try:
|
return "asd"
|
||||||
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'])
|
|
||||||
|
|
||||||
@route('<_id>/details')
|
@route('<_id>/details')
|
||||||
def get_details(self, _id: str):
|
def get_details(self, _id: str):
|
||||||
|
|
||||||
if _id == "$default":
|
if _id == "$default":
|
||||||
default = Default.query.first_or_404() # TODO: Kitalálni, hogy inkább a latestestest-el térjen-e vissza
|
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:
|
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))
|
return jsonify(self.aimodel_schema.dump(m))
|
||||||
|
|
||||||
def delete(self, _id: str):
|
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.delete(m)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@ -138,14 +138,14 @@ class ModelView(FlaskView):
|
|||||||
def put_default(self):
|
def put_default(self):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
req = self.default_schema.load(request.json())
|
req = self.default_schema.load(request.json)
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
abort(404, str(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()
|
Default.query.delete()
|
||||||
new_default = Default(m)
|
new_default = Default(aimodel=m)
|
||||||
db.session.add(new_default)
|
db.session.add(new_default)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -17,3 +17,4 @@ eyed3
|
|||||||
pydub
|
pydub
|
||||||
scipy
|
scipy
|
||||||
matplotlib
|
matplotlib
|
||||||
|
sklearn
|
Loading…
Reference in New Issue
Block a user