added code to support changing noo/how_many/folders and do this with json data back and forth, update the UI, all works - only search is missing now. Lots of dead code can still be deleted
This commit is contained in:
65
files.py
65
files.py
@@ -21,11 +21,12 @@ from datetime import datetime, timedelta
|
||||
import pytz
|
||||
import html
|
||||
from flask_login import login_required, current_user
|
||||
from states import States, PA_UserState
|
||||
from query import Query
|
||||
from types import SimpleNamespace
|
||||
|
||||
# Local Class imports
|
||||
################################################################################
|
||||
from states import States, PA_UserState
|
||||
from query import Query
|
||||
from job import Job, JobExtra, Joblog, NewJob, SetFELog
|
||||
from path import PathType, Path, MovePathDetails
|
||||
from person import Refimg, Person, PersonRefimgLink
|
||||
@@ -472,8 +473,7 @@ def get_dir_entries():
|
||||
|
||||
# get content of dir_id
|
||||
stmt=( select(Entry.id).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir_id) )
|
||||
# FIXME: what do we do with ordering anyway???
|
||||
#stmt=stmt.order_by(*order_map.get(OPT.noo) )
|
||||
stmt=stmt.order_by(*order_map.get(OPT.noo) )
|
||||
ids=db.session.execute(stmt).scalars().all()
|
||||
entries_schema = EntrySchema(many=True)
|
||||
entries = Entry.query.filter(Entry.id.in_(ids)).all()
|
||||
@@ -485,39 +485,28 @@ def get_dir_entries():
|
||||
################################################################################
|
||||
def GetQueryData( OPT ):
|
||||
query_data={}
|
||||
query_data['query_id']=None
|
||||
query_data['entry_list']=None
|
||||
|
||||
if OPT.path_type == 'Search':
|
||||
print ("NOT YET")
|
||||
return query_data
|
||||
|
||||
# always get the top of the (OPT.prefix) Path's eid and keep it for OPT.folders toggling/use
|
||||
dir_stmt=( select(Entry.id).join(Dir).join(PathDirLink).join(Path).filter(Dir.rel_path == '').filter(Path.path_prefix==OPT.prefix) )
|
||||
dir_stmt=( select(Entry.id).join(Dir).join(PathDirLink).join(Path).
|
||||
filter(Dir.rel_path == '').filter(Path.path_prefix==OPT.prefix) )
|
||||
# this should return the 1 Dir (that we want to see the content of) - and with only 1, no need to worry about order
|
||||
dir_arr=db.session.execute(dir_stmt).scalars().all()
|
||||
dir_id=dir_arr[0]
|
||||
# used to know the parent/root (in folder view), in flat view - just ignore/safe though
|
||||
query_data['root_eid']=dir_id
|
||||
|
||||
if OPT.folders:
|
||||
# start folder view with only the root folder
|
||||
stmt=( select(Entry.id).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir_id) )
|
||||
query_data['entry_list']=db.session.execute(stmt).scalars().all()
|
||||
else:
|
||||
# get every File that is in the OPT.prefix Path
|
||||
stmt=( select(Entry.id).join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix == OPT.prefix) )
|
||||
stmt=stmt.order_by(*order_map.get(OPT.noo) )
|
||||
query_data['entry_list']= db.session.execute(stmt).scalars().all()
|
||||
stmt=( select(Entry.id).join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).
|
||||
filter(Path.path_prefix == OPT.prefix) )
|
||||
|
||||
stmt=stmt.order_by(*order_map.get(OPT.noo) )
|
||||
query_data['entry_list']=db.session.execute(stmt).scalars().all()
|
||||
|
||||
# not sure I need this in hindsight - any value at all???
|
||||
# # first time we get the data q_offset is 0, current=first one, search never gets here, so search_term=''
|
||||
# # FIXME: Doubt we need cwd -- I only need originals to either invalidate this list, or recreate it... need to think about that a lot more
|
||||
# query = Query( path_type=OPT.path_type, noo=OPT.noo, q_offset=0, folder=OPT.folders, grouping=OPT.grouping, root=OPT.root, cwd=OPT.cwd, search_term='',
|
||||
# entry_list=query_data['entry_list'], current=query_data['entry_list'][0], created=datetime.now(pytz.utc) )
|
||||
# db.session.add(query)
|
||||
# db.session.commit()
|
||||
#
|
||||
# query_data['query_id']=query.id
|
||||
return query_data
|
||||
|
||||
################################################################################
|
||||
@@ -570,13 +559,25 @@ def GetEntries( OPT ):
|
||||
|
||||
return entries
|
||||
|
||||
################################################################################
|
||||
# /change_file_opts -> allow sort order, how_many per page, etc. to change, and
|
||||
# then send back the new query_data to update entryList
|
||||
################################################################################
|
||||
@app.route("/change_file_opts", methods=["POST"])
|
||||
@login_required
|
||||
def change_file_opts():
|
||||
# reset options based on form post, then redirect back to orig page (with a GET to allow back button to work)
|
||||
OPT=States( request )
|
||||
return redirect( request.referrer )
|
||||
def change_file_opts2():
|
||||
data = request.get_json() # Parse JSON body
|
||||
# allow dot-notation for OPT
|
||||
OPT = SimpleNamespace(**data)
|
||||
if OPT.folders == 'True':
|
||||
OPT.folders=True
|
||||
else:
|
||||
OPT.folders=False
|
||||
# so create a new entryList, and handle that on the client
|
||||
query_data = GetQueryData( OPT )
|
||||
return make_response( jsonify( query_data=query_data ) )
|
||||
|
||||
|
||||
################################################################################
|
||||
# /file_list -> show detailed file list of files from import_path(s)
|
||||
################################################################################
|
||||
@@ -862,12 +863,6 @@ def newview():
|
||||
data = request.get_json() # Parse JSON body
|
||||
eid = data.get('eid', 0) # Extract list of ids
|
||||
|
||||
# need appropriate schema? to get FaceData with entry, lists should just be
|
||||
# what we have in entryList so it can help with next/prev
|
||||
|
||||
# include Entry for name/path, ffl (model_used), frl (distance), Face (for w/h, etc), Person (id,tag)
|
||||
#stmt=select(Entry).filter(Entry.id==eid)
|
||||
|
||||
stmt = (
|
||||
select(Entry)
|
||||
.options(
|
||||
@@ -877,8 +872,7 @@ def newview():
|
||||
.where(Entry.id == eid)
|
||||
)
|
||||
|
||||
print( stmt )
|
||||
# this needs unique because:
|
||||
# this needs unique() because:
|
||||
# entry (one row for id=660)
|
||||
# file (one row, since file_details is a one-to-one relationship)
|
||||
# face (many rows, since a file can have many faces)
|
||||
@@ -886,7 +880,6 @@ def newview():
|
||||
# The SQL query returns a Cartesian product for the joins involving collections (like faces). For example, if your file has 3 faces,
|
||||
# the result set will have 3 rows, each with the same entry and file data, but different face, refimg, and person data.
|
||||
data=db.session.execute(stmt).unique().scalars().all()
|
||||
print( data )
|
||||
return jsonify(entries_schema.dump(data))
|
||||
|
||||
################################################################################
|
||||
|
||||
Reference in New Issue
Block a user