big clean up of Options -> States, total rework, now actually handles pa_user_state -> States as Import/Storage/Bin/Search or View. If Search has orig_search_term saved. If view, has orig_ptype (and orig_search_term if orig_ptype is Search) -- removed OPT.paths -> these are now worked out when we GetEntries based on pa_user_state. This now allows us to GET all URLs for image viewing allowing me to use the back-button without issues in PROD - well we will see once I commit :)

This commit is contained in:
2022-01-20 17:25:01 +11:00
parent 5461cb4036
commit 78acb9bd66
5 changed files with 132 additions and 76 deletions

View File

@@ -20,7 +20,7 @@ import re
import json
import datetime
from flask_login import login_required, current_user
from states import Options
from states import States
################################################################################
# Local Class imports
@@ -28,7 +28,7 @@ from states import Options
from job import Job, JobExtra, Joblog, NewJob
from path import PathType, Path
from person import Refimg, Person, PersonRefimgLink
from settings import Settings
from settings import Settings, SettingsIPath, SettingsSPath, SettingsRBPath
from shared import SymlinkName
from dups import Duplicates
from face import Face, FaceFileLink, FaceRefimgLink
@@ -238,8 +238,8 @@ def GetEntriesInFolderView( OPT, prefix ):
################################################################################
def GetEntries( OPT ):
entries=[]
if OPT.path_type == 'Search':
search_term=OPT.search_term
if OPT.path_type == 'Search' or (OPT.path_type == 'View' and OPT.orig_ptype=='Search'):
search_term=OPT.orig_search_term
if 'AI:' in search_term:
search_term = search_term.replace('AI:','')
all_entries = Entry.query.join(File).join(FaceFileLink).join(Face).join(FaceRefimgLink).join(Refimg).join(PersonRefimgLink).join(Person).filter(Person.tag.ilike(f"%{search_term}%")).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(OPT.offset).limit(OPT.how_many).all()
@@ -269,7 +269,25 @@ def GetEntries( OPT ):
all_entries.append(a)
return all_entries
for path in OPT.paths:
# if we are a view, then it will be of something else, e.g. a list of
# 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 = []
if OPT.path_type == 'Storage':
paths = SettingsSPath()
elif OPT.path_type == 'Import':
paths = SettingsIPath()
elif OPT.path_type == 'Bin':
paths.append(SettingsRBPath())
for path in paths:
if not os.path.exists(path):
continue
prefix = SymlinkName(OPT.path_type,path,path+'/')
@@ -295,7 +313,7 @@ def clear_jm_msg(id):
@app.route("/file_list_ip", methods=["GET", "POST"])
@login_required
def file_list_ip():
OPT=Options( request )
OPT=States( request )
# now we have reset the offset, etc. into the prefs, we can use a GET and this will be back/forward browser button safe
if request.method=='POST':
redirect("/file_list_ip")
@@ -308,7 +326,7 @@ def file_list_ip():
@app.route("/files_ip", methods=["GET", "POST"])
@login_required
def files_ip():
OPT=Options( request )
OPT=States( request )
# now we have reset the offset, etc. into the prefs, we can use a GET and this will be back/forward browser button safe
if request.method=='POST':
redirect("/files_ip")
@@ -323,7 +341,7 @@ def files_ip():
@app.route("/files_sp", methods=["GET", "POST"])
@login_required
def files_sp():
OPT=Options( request )
OPT=States( request )
# now we have reset the offset, etc. into the prefs, we can use a GET and this will be back/forward browser button safe
if request.method=='POST':
redirect("/files_sp")
@@ -339,7 +357,7 @@ def files_sp():
@app.route("/files_rbp", methods=["GET", "POST"])
@login_required
def files_rbp():
OPT=Options( request )
OPT=States( request )
# now we have reset the offset, etc. into the prefs, we can use a GET and this will be back/forward browser button safe
if request.method=='POST':
redirect("/files_rbp")
@@ -356,7 +374,7 @@ def files_rbp():
@app.route("/search/<search_term>", methods=["GET"])
@login_required
def search(search_term):
OPT=Options( request )
OPT=States( request )
OPT.search_term = search_term
# always show flat results for search to start with
OPT.folders=False
@@ -510,7 +528,7 @@ def move_files():
@app.route("/viewlist", methods=["POST"])
@login_required
def viewlist():
OPT=Options( request )
OPT=States( request )
# Get next/prev set of data - e.g. if next set, then it will use orig_url
# to go forward how_many from offset and then use viewer.html to show that
# first obj of the new list of entries
@@ -551,22 +569,19 @@ def viewlist():
@login_required
@app.route("/view/<id>", methods=["GET"])
def view(id):
OPT=Options( request )
OPT=States( request )
objs = {}
print( OPT )
entries=GetEntries( OPT )
eids=""
for e in entries:
print( f"in loop deal with: {e.id}")
objs[e.id]=e
eids += f"{e.id},"
# if this is a dir, we wont view it with a click anyway, so move on...
if not e.file_details:
print( f"seems {e.name} is not a file? -- {e.type}" )
continue
# put locn data back into array format
for face in e.file_details.faces:
face.locn = json.loads(face.locn)
print("now render the viewer" )
eids=eids.rstrip(",")
return render_template("viewer.html", current=int(id), eids=eids, objs=objs, OPT=OPT )
@@ -576,7 +591,9 @@ def view(id):
@app.route("/view/<id>", methods=["POST"])
@login_required
def view_img_post(id):
OPT=Options( request )
# set pa_user_states...
OPT=States( request )
# then use back-button friendly URL (and use pa_user_states to view the right image in the right list
return redirect( "/view/" + id );
# route called from front/end - if multiple images are being transformed, each transorm == a separate call