partial implementation of first_eid, last_eid -- I think the vals work -- they do for searches anyway, but not stored in pa_user_state yet

This commit is contained in:
2022-01-25 00:48:14 +11:00
parent 65ebfe2d31
commit 08ca9b4e74
7 changed files with 182 additions and 69 deletions

View File

@@ -244,10 +244,15 @@ def GetEntries( OPT ):
if 'AI:' in search_term:
search_term = search_term.replace('AI:','')
all_entries = Entry.query.join(File).distinct().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()
if OPT.last_eid == 0:
last_entry=Entry.query.join(File).distinct().join(FaceFileLink).join(Face).join(FaceRefimgLink).join(Refimg).join(PersonRefimgLink).join(Person).filter(Person.tag.ilike(f"%{search_term}%")).order_by(File.year,File.month,File.day,Entry.name.desc()).limit(1).all()
if len(last_entry):
OPT.last_eid = last_entry[0].id
else:
file_data=Entry.query.join(File).filter(Entry.name.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()
dir_data=Entry.query.join(File).join(EntryDirLink).join(Dir).filter(Dir.rel_path.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()
ai_data=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()
# remove any duplicates from combined data
all_entries = []
for f in file_data:
@@ -268,6 +273,26 @@ def GetEntries( OPT ):
break
if add_it:
all_entries.append(a)
# for all searches first_entry is worked out when first_eid not set yet & offset is 0 and we have some entries
if OPT.first_eid == 0 and OPT.offset == 0 and len(all_entries):
OPT.first_eid = all_entries[0].id
if OPT.last_eid == 0:
by_fname= f"select e.id from entry e where e.name ilike '%%{search_term}%%'"
by_dirname=f"select e.id from entry e, entry_dir_link edl where edl.entry_id = e.id and edl.dir_eid in ( select d.eid from dir d where d.rel_path ilike '%%{search_term}%%' )"
by_ai =f"select e.id from entry e, face_file_link ffl, face_refimg_link frl, person_refimg_link prl, person p where e.id = ffl.file_eid and frl.face_id = ffl.face_id and frl.refimg_id = prl.refimg_id and prl.person_id = p.id and p.tag ilike '%%{search_term}%%'"
sel_no_order=f"select e.*, f.* from entry e, file f where e.id=f.eid and e.id in ( {by_fname} union {by_dirname} union {by_ai} ) "
order_desc=f"f.year desc, f.month desc, f.day desc, e.name"
order_asc=f"f.year, f.month, f.day, e.name desc"
last_entry_sql= f"{sel_no_order} order by {order_asc} limit 1"
last_entry=db.engine.execute( last_entry_sql )
# can only be 1 due to limit above
for l in last_entry:
OPT.last_eid = l.id
print( f"f={OPT.first_eid}, l={OPT.last_eid} -- STORE THESE in pa_user_state" )
return all_entries
# if we are a view, then it will be of something else, e.g. a list of
@@ -535,13 +560,11 @@ def move_files():
st.SetMessage( f"Created&nbsp;<a href=/job/{job.id}>Job #{job.id}</a>&nbsp;to move selected file(s)")
return redirect("/jobs")
################################################################################
# /viewlist -> get new set of eids and set current to new img to view
################################################################################
@app.route("/viewlist", methods=["POST"])
@login_required
@app.route("/viewlist", methods=["POST"])
def viewlist():
OPT=States( request )
OPT.last_entry_in_db=0
# 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
@@ -556,39 +579,62 @@ def viewlist():
OPT.last_entry_in_db=1
objs = {}
eids=""
resp={}
resp['objs']={}
for e in entries:
if not e.file_details:
print( f"seems {e.name} is not a file? -- {e.type}" )
continue
objs[e.id]=e
# get new eids for viewer.html
eids=eids+f"{e.id},"
# put locn data back into array format
for face in e.file_details.faces:
face.locn = json.loads(face.locn)
resp['objs'][e.id]={}
resp['objs'][e.id]['url'] = e.FullPathOnFS()
resp['objs'][e.id]['name'] = e.name
resp['objs'][e.id]['type'] = e.type.name
if e.file_details.faces:
resp['objs'][e.id]['face_model'] = e.file_details.faces[0].facefile_lnk.model_used
resp['objs'][e.id]['faces'] = []
# put locn data back into array format
fid=0
for face in e.file_details.faces:
face.locn = json.loads(face.locn)
fd= {}
fd['x'] = face.locn[3]
fd['y'] = face.locn[0]
fd['w'] = face.locn[1]-face.locn[3]
fd['h'] = face.locn[2]-face.locn[0]
if face.refimg:
fd['who'] = face.refimg.person.tag
fd['distance'] = round(face.refimg_lnk.face_distance,2)
resp['objs'][e.id]['faces'].append(fd)
fid+=1
eids=eids.rstrip(",")
lst = eids.split(',')
if 'next' in request.form:
current = int(lst[0])
if 'prev' in request.form:
current = int(lst[-1])
if hasattr( OPT, 'last_entry_in_db' ):
if OPT.last_entry_in_db:
# force this back to the last image of the last page - its the last in the DB, so set OPT for it
current = int(lst[-1])
OPT.last_entry_in_db=current
return render_template("viewer.html", current=current, eids=eids, objs=objs, OPT=OPT )
resp['current']=current
resp['eids']=eids
resp['offset']=OPT.offset
resp['last_entry_in_db']=OPT.last_entry_in_db
return resp
@login_required
@app.route("/view/<id>", methods=["GET"])
def view(id):
OPT=States( request )
OPT.last_entry_in_db=0
objs = {}
entries=GetEntries( OPT )
eids=""
for e in entries:
print( f"id={e.id}, len(faces)={len(e.file_details.faces)}")
print(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...
@@ -596,7 +642,6 @@ def view(id):
continue
# put locn data back into array format
for face in e.file_details.faces:
print( f"face.locn before json: {face.locn}" )
face.locn = json.loads(face.locn)
eids=eids.rstrip(",")
return render_template("viewer.html", current=int(id), eids=eids, objs=objs, OPT=OPT )