updated BUGs in general to remove older / fixed BUGs relating to the confusion of current/eids, etc.

update amendments in tables.sql to include job_id in entry_ammendment
added amend.py to move amendment-related code into its own file
when we create a job (NewJob) and that job matches an amendmentType (via job_name or job_name:amt <- where amt relates to how we do a transform_image), then
  we enter a new EntryAmendment
pa_job_mgr knows when a Transform job ends, and removes relevant EntryAmendment
files*.js use EntryAmendment data to render thumbnails with relevant AmendmentType and
  if a normal page load (like /files_ip), and there is an EntryAmendment, mark
  up the thumb, run  the check jobs to look for completion of the job, removeal
  of the EntryAmendment and update the entry based on 'transformed' image
OVERALL: this is a functioning version that uses EntryAmendments and can handle
loading a new page with outstanding amendments and 'deals' with it.  This is a
good base, but does not cater for remove_files or move_files
This commit is contained in:
2025-10-20 19:23:52 +11:00
parent a38c54812c
commit 905910ecf0

64
amend.py Normal file
View File

@@ -0,0 +1,64 @@
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")
################################################################################
# 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