another large clean up of code, all POSTs are now using make_response() and returning json OR are for a form that flask handles with rendering direct html. Where there is a POST with json response, the jscript now calls CheckForJobs() to show it in the F/E. Removed several debugs. Fixed up undocumented BUG where import datetime was wrong, and prefix/suffix also to offer directories near the date of an image. Removed unused routes for clearing messages

This commit is contained in:
2023-01-12 16:47:43 +11:00
parent 8d9cf5279e
commit ef9f26189a
12 changed files with 45 additions and 58 deletions

View File

@@ -15,7 +15,7 @@ import numpy
import cv2
import time
import re
from datetime import datetime
from datetime import datetime, timedelta
import pytz
from flask_login import login_required, current_user
from states import States, PA_UserState
@@ -366,16 +366,6 @@ def GetEntries( OPT ):
UpdatePref( pref, OPT )
return entries
################################################################################
# /clear_jm_msg -> with a dismissable error (ie. anything not success, that is
# not showing duplicates (so rare errors) - allow them to be dismissed
################################################################################
@app.route("/clear_jm_msg/<id>", methods=["POST"])
@login_required
def clear_jm_msg(id):
ClearJM_Message(id)
return redirect( url_for("main_page") )
@app.route("/ChangeFileOpts", methods=["POST"])
@login_required
def ChangeFileOpts():
@@ -500,7 +490,7 @@ def fix_dups():
rows = db.engine.execute( "select e1.id as id1, f1.hash, d1.rel_path as rel_path1, d1.eid as did1, e1.name as fname1, p1.id as path1, p1.type_id as path_type1, e2.id as id2, d2.rel_path as rel_path2, d2.eid as did2, e2.name as fname2, p2.id as path2, p2.type_id as path_type2 from entry e1, file f1, dir d1, entry_dir_link edl1, path_dir_link pdl1, path p1, entry e2, file f2, dir d2, entry_dir_link edl2, path_dir_link pdl2, path p2 where e1.id = f1.eid and e2.id = f2.eid and d1.eid = edl1.dir_eid and edl1.entry_id = e1.id and edl2.dir_eid = d2.eid and edl2.entry_id = e2.id and p1.type_id != (select id from path_type where name = 'Bin') and p1.id = pdl1.path_id and pdl1.dir_eid = d1.eid and p2.type_id != (select id from path_type where name = 'Bin') and p2.id = pdl2.path_id and pdl2.dir_eid = d2.eid and f1.hash = f2.hash and e1.id != e2.id and f1.size_mb = f2.size_mb order by path1, rel_path1, fname1");
if rows.returns_rows == False:
SetFELog(f"Err, no dups - should now clear the FE 'danger' message?", "warning")
SetFELog(f"Err, No more duplicates? Old link followed, or something is wrong!", "warning")
return redirect("/")
if 'pagesize' not in request.form:
@@ -653,7 +643,7 @@ def viewlist():
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.orig_ptype==OPT.orig_ptype,PA_UserState.view_eid==OPT.view_eid).first()
UpdatePref( pref, OPT )
return resp
return make_response( resp )
################################################################################
# /view/id -> grabs data from DB and views it (GET)
@@ -785,7 +775,7 @@ def _jinja2_filter_parentpath(path):
###############################################################################
# route to allow the Move Dialog Box to pass a date (YYYYMMDD) and returns a
# json? list of existing dir names that could be near it in time. Starting
# json list of existing dir names that could be near it in time. Starting
# simple, by using YYYYMM-1, YYYYMM, YYYYMM+1 dirs
###############################################################################
@app.route("/getexistingpaths/<dt>", methods=["POST"])
@@ -795,13 +785,15 @@ def GetExistingPathsAsDiv(dt):
dirs_arr=[]
for delta in range(-7, 8):
try:
new_dtime=datetime.datetime.strptime(dt, "%Y%m%d") + datetime.timedelta(days=delta)
new_dtime=datetime.strptime(dt, "%Y%m%d") + timedelta(days=delta)
except:
# this is not a date, so we cant work out possible dirs, just
# return an empty set
return "[]"
return make_response( '[]' )
new_dt=new_dtime.strftime('%Y%m%d')
# find dirs named with this date
dirs_arr+=Dir.query.distinct(Dir.rel_path).filter(Dir.rel_path.ilike('%'+new_dt+'%')).all();
# find dirs with non-dirs (files) with this date
dirs_arr+=Dir.query.distinct(Dir.rel_path).join(EntryDirLink).join(Entry).filter(Entry.type_id!=dir_ft.id).filter(Entry.name.ilike('%'+new_dt+'%')).all()
# remove duplicates from array
@@ -811,12 +803,17 @@ def GetExistingPathsAsDiv(dt):
ret='[ '
first_dir=1
for dir in dirs:
print(dir)
# 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
# regardless, it cant be used for a existpath button in the F/E, ignore it
if dir.rel_path == '':
continue
if not first_dir:
ret +=", "
bits=dir.rel_path.split('-')
ret+= '{ '
ret+= '"prefix":"' + bits[0] + '", '
ret+= '"prefix":"' + bits[0] + '-", '
if len(bits)>1:
ret+= '"suffix":"' + bits[1] + '"'
else:
@@ -824,4 +821,4 @@ def GetExistingPathsAsDiv(dt):
ret+= ' } '
first_dir=0
ret+= ' ]'
return ret
return make_response( ret )