"""Image Status Model. Image Status model for returning asset-related status for an image """ from sqlalchemy import Column from sqlalchemy import DateTime from sqlalchemy import Enum from sqlalchemy import Integer from sqlalchemy import String from images import response from images.connectors import mysql from images.models import base ASSET_TYPES = ['audio', 'image', 'caption', 'subtitles'] STATUS_TYPES = ['upload_complete', 'error', 'finished', 'new', 'deleted'] class ImportAsset(base.BaseModel): """Class representing the import_asset table from art_relations.""" __tablename__ = 'import_asset' id = Column(Integer, primary_key=True) import_asset_batch_id = Column(Integer) foldername = Column(String) filename = Column(String) asset_type = Column(Enum(*ASSET_TYPES)) status = Column(Enum(*STATUS_TYPES)) upload_completed = Column(DateTime) encoding_completed = Column(DateTime) result = Column(String) def get_import_asset_for_image(import_asset_id): """Get import asset information for an image. Gets the import asset that corresponds to the image which corresponds to the image's asset status Args: import_asset_id (int): import_asset_id for the requested image Returns: response.Response: the status of the import asset for the image. """ with mysql.db_session() as session: full_query = session.query(ImportAsset).filter_by(id=import_asset_id) import_asset = full_query.first() if not import_asset: return response.create_not_found_response( message='image asset not found') message = { 'import_asset_id': import_asset.id, 'filename': import_asset.filename, 'status': import_asset.status, 'path': None, 'result': import_asset.result} return response.Response(message=message)