from sqlalchemy import select from flask import request, jsonify from flask_login import login_required from shared import PA from main import db, app ################################################################################ # Amendments are used to define types of changes being made to an entry (e.g. # rotate, flip) should contain relatively transient content (e.g. we might be # processing a long-running job now, and then add a rotate, the rotate wont # finish for minutes, so these classes allow the UI to handle that gracefully ################################################################################ ################################################################################ # Class describing AmendmentType in the DB (via sqlalchemy) ################################################################################ class AmendmentType(PA,db.Model): __tablename__ = "amendment_type" id = db.Column(db.Integer, db.Sequence('file_type_id_seq'), primary_key=True ) job_name = db.Column(db.String, nullable=False ) which = db.Column(db.String, nullable=False ) what = db.Column(db.String, nullable=False ) colour = db.Column(db.String, nullable=False ) ################################################################################ # Class describing which Entry has a pending Amendment in the DB (via sqlalchemy) ################################################################################ class EntryAmendment(PA,db.Model): __tablename__ = "entry_amendment" eid = db.Column(db.Integer, db.ForeignKey("entry.id"), primary_key=True ) job_id = db.Column(db.Integer, db.ForeignKey("job.id"), primary_key=True ) amend_type = db.Column(db.Integer, db.ForeignKey("amendment_type.id")) type = db.relationship("AmendmentType", backref="entry_amendment") job = db.relationship("Job", back_populates="amendments") ################################################################################ # check if this job is something we need to log an EntryAmendment for, based on # job name and potentially amt in extras, to find the type of amendment ################################################################################ def inAmendmentTypes(job): if not hasattr(job, 'extra' ) or not job.extra: return None amt=None for jex in job.extra: if jex.name == "amt": amt=jex.value # FIXME: should just cache this once per build, only would change with code updates for at in getAmendments(): # for transform_image, amt=flip*, 90/180/270 - so amt will be set, use it, otherwise just use job.name if (amt and f"{job.name}:{amt}" == at.job_name) or (at.job_name == job.name): return at.id return None ################################################################################ # Class describing which Entry has a pending Amendment in the DB (via sqlalchemy) ################################################################################ def getAmendments(): # get Amend types (get EAT data once - used in inAmendmentTypes() stmt=select(AmendmentType) eat=db.session.execute(stmt).scalars().all() return eat