clarified bug-82, fixed issue with AI scan optimising still scanning when it should not, finalised back button work for view/viewlist
This commit is contained in:
86
files.py
86
files.py
@@ -174,6 +174,20 @@ def ClearJM_Message(id):
|
||||
db.session.commit()
|
||||
return
|
||||
|
||||
################################################################################
|
||||
# util function to just update the current/first/last positions needed for
|
||||
# viewing / using pa_user_state DB table
|
||||
################################################################################
|
||||
def UpdatePref( pref, OPT ):
|
||||
if OPT.current>0:
|
||||
pref.current=OPT.current
|
||||
if OPT.first_eid>0:
|
||||
pref.first_eid=OPT.first_eid
|
||||
if OPT.last_eid>0:
|
||||
pref.last_eid=OPT.last_eid
|
||||
db.session.add(pref)
|
||||
db.session.commit()
|
||||
|
||||
################################################################################
|
||||
# GetEntriesInFlatView: func. to retrieve DB entries appropriate for flat view
|
||||
################################################################################
|
||||
@@ -192,33 +206,20 @@ def GetEntriesInFlatView( OPT, prefix ):
|
||||
else:
|
||||
entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(Entry.name).offset(OPT.offset).limit(OPT.how_many).all()
|
||||
last_entry=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(Entry.name.desc()).limit(1)
|
||||
print(f"GetEnt FLAT --> OPT={OPT}, len={len(entries)}")
|
||||
if OPT.first_eid == 0 and OPT.offset == 0 and len(entries):
|
||||
OPT.first_eid = entries[0].id
|
||||
if OPT.last_eid == 0:
|
||||
le=last_entry.all()
|
||||
if len(le):
|
||||
OPT.last_eid = le[0].id
|
||||
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==OPT.path_type).first()
|
||||
UpdatePref( pref, OPT )
|
||||
|
||||
# FIXME: would prefer to only get this if needed (e.g. when last_eid is 0),
|
||||
# but with multiple dirs in say import path, then we only set last_eid on
|
||||
# the first dir... need to to think this through better, pass param maybe?
|
||||
le=last_entry.all()
|
||||
if len(le):
|
||||
OPT.last_eid = le[0].id
|
||||
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==OPT.path_type).first()
|
||||
UpdatePref( pref, OPT )
|
||||
|
||||
return entries
|
||||
|
||||
################################################################################
|
||||
# util function to just update the current/first/last positions needed for
|
||||
# viewing / using pa_user_state DB table
|
||||
################################################################################
|
||||
def UpdatePref( pref, OPT ):
|
||||
if OPT.current>0:
|
||||
pref.current=OPT.current
|
||||
if OPT.first_eid>0:
|
||||
pref.first_eid=OPT.first_eid
|
||||
if OPT.last_eid>0:
|
||||
pref.last_eid=OPT.last_eid
|
||||
print( f"UpdatePref: c={pref.current}, f={pref.first_eid}, l={pref.last_eid}" )
|
||||
db.session.add(pref)
|
||||
db.session.commit()
|
||||
|
||||
################################################################################
|
||||
# GetEntriesInFolderView: func. to retrieve DB entries appropriate for folder view
|
||||
# read inline comments to deal with variations / ordering...
|
||||
@@ -242,7 +243,7 @@ def GetEntriesInFolderView( OPT, prefix ):
|
||||
# this can occur if the path in settings does not exist as it wont be in # the DB
|
||||
if not dir:
|
||||
return entries
|
||||
if OPT.noo == "Z to A" or "Newest":
|
||||
if OPT.noo == "Z to A" or OPT.noo == "Newest":
|
||||
entries+= Entry.query.join(EntryDirLink).join(FileType).filter(EntryDirLink.dir_eid==dir.id).filter(FileType.name=='Directory').order_by(Entry.name.desc()).all()
|
||||
# just do A to Z / Oldest by default or if no valid option
|
||||
else:
|
||||
@@ -251,13 +252,25 @@ def GetEntriesInFolderView( OPT, prefix ):
|
||||
# add any files at the current CWD (based on dir_eid in DB)
|
||||
if OPT.noo == "Oldest":
|
||||
entries+=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(File.year,File.month,File.day,Entry.name).offset(OPT.offset).limit(OPT.how_many).all()
|
||||
last_entry=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).limit(1)
|
||||
elif OPT.noo == "Newest":
|
||||
entries+=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(OPT.offset).limit(OPT.how_many).all()
|
||||
last_entry=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(File.year,File.month,File.day,Entry.name).limit(1)
|
||||
elif OPT.noo == "Z to A":
|
||||
entries+=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(Entry.name.desc()).offset(OPT.offset).limit(OPT.how_many).all()
|
||||
last_entry=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(Entry.name).limit(1)
|
||||
# just do A to Z by default or if no valid option
|
||||
else:
|
||||
entries+=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(Entry.name).offset(OPT.offset).limit(OPT.how_many).all()
|
||||
last_entry=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(Entry.name.desc()).limit(1)
|
||||
if OPT.first_eid == 0 and OPT.offset == 0 and len(entries):
|
||||
OPT.first_eid = entries[0].id
|
||||
if OPT.last_eid == 0:
|
||||
le=last_entry.all()
|
||||
if len(le):
|
||||
OPT.last_eid = le[0].id
|
||||
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==OPT.path_type).first()
|
||||
UpdatePref( pref, OPT )
|
||||
|
||||
return entries
|
||||
|
||||
@@ -268,7 +281,6 @@ def GetEntriesInFolderView( OPT, prefix ):
|
||||
def GetEntries( OPT ):
|
||||
entries=[]
|
||||
if OPT.path_type == 'Search' or (OPT.path_type == 'View' and OPT.orig_ptype=='Search'):
|
||||
print( f"getting entries: OPT={OPT}" )
|
||||
search_term=OPT.orig_search_term
|
||||
if 'AI:' in search_term:
|
||||
search_term = search_term.replace('AI:','')
|
||||
@@ -320,7 +332,7 @@ def GetEntries( OPT ):
|
||||
# can only be 1 due to limit above
|
||||
for l in last_entry:
|
||||
OPT.last_eid = l.id
|
||||
print( f"c={OPT.current}, f={OPT.first_eid}, l={OPT.last_eid} -- STORE THESE in pa_user_state" )
|
||||
# store first/last eid into prefs
|
||||
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==OPT.path_type,PA_UserState.orig_ptype==OPT.orig_ptype,PA_UserState.orig_search_term==search_term).first()
|
||||
UpdatePref( pref, OPT )
|
||||
|
||||
@@ -330,10 +342,6 @@ def GetEntries( OPT ):
|
||||
# import, storage, or bin images, reset OPT.path_type so that the paths array below works
|
||||
if 'View' in OPT.path_type:
|
||||
eid = OPT.url[6:]
|
||||
print( f"we have a view, eid={eid}" )
|
||||
#e=Entry.query.get(eid)
|
||||
#OPT.path_type=e.in_dir.in_path.type.name
|
||||
print( f"pt={OPT.orig_ptype}, st={OPT.orig_search_term}" )
|
||||
OPT.path_type= OPT.orig_ptype
|
||||
|
||||
paths = []
|
||||
@@ -367,10 +375,8 @@ def clear_jm_msg(id):
|
||||
@app.route("/ChangeFileOpts", methods=["POST"])
|
||||
@login_required
|
||||
def ChangeFileOpts():
|
||||
# reset options based on form post, then redirect back to orig page
|
||||
# reset options based on form post, then redirect back to orig page (with a GET to allow back button to work)
|
||||
OPT=States( request )
|
||||
for el in request.form:
|
||||
print( f"{el}={request.form[el]}")
|
||||
return redirect( request.referrer )
|
||||
|
||||
################################################################################
|
||||
@@ -645,18 +651,22 @@ def viewlist():
|
||||
OPT.current = int(lst[-1])
|
||||
|
||||
resp['current']=OPT.current
|
||||
# OPT.first_eid can still be 0 IF we have gone past the first page, I could
|
||||
# better set this in states rather than kludge this if... think about it
|
||||
if OPT.first_eid>0:
|
||||
resp['first_eid']=OPT.first_eid
|
||||
resp['last_eid']=OPT.last_eid
|
||||
resp['eids']=eids
|
||||
resp['offset']=OPT.offset
|
||||
print( "DDP: SAVE PREF HERE TO GET NEW CURRENT AND FIX back button WITH view/XXX when you next/prev to different page" )
|
||||
|
||||
# save pref to keep the new current value, first/last
|
||||
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
|
||||
|
||||
################################################################################
|
||||
# /view/id -> grabs data from DB and views it (GET)
|
||||
################################################################################
|
||||
@login_required
|
||||
@app.route("/view/<id>", methods=["GET"])
|
||||
def view(id):
|
||||
@@ -676,9 +686,9 @@ def view(id):
|
||||
eids=eids.rstrip(",")
|
||||
return render_template("viewer.html", current=int(id), eids=eids, objs=objs, OPT=OPT )
|
||||
|
||||
################################################################################
|
||||
# /view/id -> grabs data from DB and views it
|
||||
################################################################################
|
||||
##################################################################################
|
||||
# /view/id -> grabs data from DB and views it (POST -> set state, redirect to GET)
|
||||
##################################################################################
|
||||
@app.route("/view/<id>", methods=["POST"])
|
||||
@login_required
|
||||
def view_img_post(id):
|
||||
@@ -696,7 +706,6 @@ def view_img_post(id):
|
||||
def transform():
|
||||
id = request.form['id']
|
||||
amt = request.form['amt']
|
||||
print( f"transform called with id={id}, amt={amt}")
|
||||
|
||||
jex=[]
|
||||
for el in request.form:
|
||||
@@ -793,7 +802,6 @@ def GetExistingPathsAsDiv(dt):
|
||||
ret='[ '
|
||||
first_dir=1
|
||||
for dir in dirs:
|
||||
print( f"process dir matching for {new_dt} => {dir}")
|
||||
if not first_dir:
|
||||
ret +=", "
|
||||
bits=dir.rel_path.split('-')
|
||||
|
||||
Reference in New Issue
Block a user