remove overkill use of make_response

This commit is contained in:
2025-10-20 19:16:25 +11:00
parent 8969cd452e
commit dc6b831481

View File

@@ -1,5 +1,5 @@
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from flask import request, render_template, redirect, send_from_directory, url_for, jsonify, make_response from flask import request, render_template, redirect, send_from_directory, url_for, jsonify
from marshmallow import Schema, fields from marshmallow import Schema, fields
from main import db, app, ma from main import db, app, ma
from sqlalchemy import Sequence, text, select, union, or_ from sqlalchemy import Sequence, text, select, union, or_
@@ -242,6 +242,7 @@ class EntryAmendmentSchema(ma.SQLAlchemyAutoSchema):
model = EntryAmendment model = EntryAmendment
load_instance = True load_instance = True
eid = ma.auto_field() eid = ma.auto_field()
job_id = ma.auto_field()
type = ma.Nested(AmendmentTypeSchema) type = ma.Nested(AmendmentTypeSchema)
################################################################################ ################################################################################
@@ -469,7 +470,7 @@ def change_file_opts():
query_data = GetSearchQueryData( OPT ) query_data = GetSearchQueryData( OPT )
else: else:
query_data = GetQueryData( OPT ) query_data = GetQueryData( OPT )
return make_response( jsonify( query_data=query_data ) ) return jsonify( query_data=query_data )
################################################################################ ################################################################################
@@ -655,7 +656,7 @@ def move_files():
jex.append( JobExtra( name=f"{el}", value=str(request.form[el]) ) ) jex.append( JobExtra( name=f"{el}", value=str(request.form[el]) ) )
job=NewJob( name="move_files", num_files=0, wait_for=None, jex=jex, desc="to move selected file(s)" ) job=NewJob( name="move_files", num_files=0, wait_for=None, jex=jex, desc="to move selected file(s)" )
# data is not used, but send response to trigger CheckForJobs() # data is not used, but send response to trigger CheckForJobs()
return make_response( jsonify( job_id=job.id ) ) return jsonify( job_id=job.id )
@login_required @login_required
@app.route("/view/", methods=["POST"]) @app.route("/view/", methods=["POST"])
@@ -697,7 +698,7 @@ def transform():
jex.append( JobExtra( name=f"{el}", value=str(request.form[el]) ) ) jex.append( JobExtra( name=f"{el}", value=str(request.form[el]) ) )
job=NewJob( name="transform_image", num_files=0, wait_for=None, jex=jex, desc="to transform selected file(s)" ) job=NewJob( name="transform_image", num_files=0, wait_for=None, jex=jex, desc="to transform selected file(s)" )
return make_response( jsonify( job_id=job.id ) ) return jsonify( job_id=job.id )
################################################################################ ################################################################################
# /check_transform_job -> URL that is called repeatedly by front-end waiting for the # /check_transform_job -> URL that is called repeatedly by front-end waiting for the
@@ -714,9 +715,11 @@ def check_transform_job():
j=jsonify( finished=False ) j=jsonify( finished=False )
if job.pa_job_state == 'Completed': if job.pa_job_state == 'Completed':
id=[jex.value for jex in job.extra if jex.name == "id"][0] id=[jex.value for jex in job.extra if jex.name == "id"][0]
e=Entry.query.join(File).filter(Entry.id==id).first() stmt=select(Entry).where(Entry.id==id)
j=jsonify( finished=True, thumbnail=e.file_details.thumbnail ) ent=db.session.execute(stmt).scalars().all()
return make_response( j ) ent_data=entries_schema.dump(ent)
j=jsonify( finished=True, entry=ent_data[0] )
return j
################################################################################ ################################################################################
# /include -> return contents on /include and does not need a login, so we # /include -> return contents on /include and does not need a login, so we
@@ -762,7 +765,7 @@ def get_existing_paths(dt):
except: except:
# this is not a date, so we cant work out possible dirs, just # this is not a date, so we cant work out possible dirs, just
# return an empty set # return an empty set
return make_response( '[]' ) return jsonify( '[]' )
new_dt=new_dtime.strftime('%Y%m%d') new_dt=new_dtime.strftime('%Y%m%d')
# find dirs named with this date # find dirs named with this date
dirs_arr+=Dir.query.filter(Dir.rel_path.ilike('%'+new_dt+'%')).all(); dirs_arr+=Dir.query.filter(Dir.rel_path.ilike('%'+new_dt+'%')).all();
@@ -776,8 +779,8 @@ def get_existing_paths(dt):
ret='[ ' ret='[ '
first_dir=1 first_dir=1
for dir in dirs: for dir in dirs:
# this can occur if there is a file with this date name in the top-levle of the path, its legit, but only really happens in DEV # this can occur if there is a file with this date name in the top-level of the path, its legit, but only really happens in DEV
# regardless, it cant be used for a existpath button in the F/E, ignore it # regardless, it cant be used for a existing path button in the F/E, ignore it
if dir.rel_path == '': if dir.rel_path == '':
continue continue
if not first_dir: if not first_dir:
@@ -795,7 +798,7 @@ def get_existing_paths(dt):
ret+= ' } ' ret+= ' } '
first_dir=0 first_dir=0
ret+= ' ]' ret+= ' ]'
return make_response( ret ) return jsonify ( ret )
# quick helper func to return timestamps of jscript files # quick helper func to return timestamps of jscript files
# we use this as a quick/hacky way of versioning them # we use this as a quick/hacky way of versioning them