added first pass of viewing by folders, see TODO for next steps

This commit is contained in:
2021-04-06 17:05:24 +10:00
parent 0ad62f5c07
commit 1ece519a2a
4 changed files with 98 additions and 9 deletions

View File

@@ -122,6 +122,13 @@ def ViewingOptions( request ):
how_many="50"
offset=0
size=128
print( f"ViewingOptions( {request.method} )" )
if 'files_sp' in request.path:
folders=True
cwd='static/storage'
else:
folders=False
cwd=None
if request.method=="POST":
noo=request.form['noo']
@@ -129,6 +136,9 @@ def ViewingOptions( request ):
offset=int(request.form['offset'])
grouping=request.form['grouping']
size = request.form['size']
folders = request.form['folders']
cwd = request.form['cwd']
print( f"setting cwd basedon form: {cwd}" )
if 'prev' in request.form:
offset -= int(how_many)
if offset < 0:
@@ -136,7 +146,7 @@ def ViewingOptions( request ):
if 'next' in request.form:
offset += int(how_many)
return noo, grouping, how_many, offset, size
return noo, grouping, how_many, offset, size, folders, cwd
################################################################################
# /file_list -> show detailed file list of files from import_path(s)
@@ -151,7 +161,7 @@ def file_list_ip():
@app.route("/files_ip", methods=["GET", "POST"])
def files_ip():
noo, grouping, how_many, offset, size = ViewingOptions( request )
noo, grouping, how_many, offset, size, folders, cwd = ViewingOptions( request )
entries=[]
# per import path, add entries to view
@@ -165,16 +175,18 @@ def files_ip():
else:
entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).filter(Dir.path_prefix.like(prefix+'%')).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all()
return render_template("files.html", page_title='View Files (Import Path)', entry_data=entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size )
return render_template("files.html", page_title='View Files (Import Path)', entry_data=entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size, folders=folders, cwd=cwd )
################################################################################
# /files -> show thumbnail view of files from storage_path
################################################################################
@app.route("/files_sp", methods=["GET", "POST"])
def files_sp():
noo, grouping, how_many, offset, size = ViewingOptions( request )
noo, grouping, how_many, offset, size, folders, cwd = ViewingOptions( request )
entries=[]
print( f"cwd={cwd}" )
# per storage path, add entries to view
settings=Settings.query.first()
paths = settings.storage_path.split("#")
@@ -183,10 +195,11 @@ def files_sp():
if noo == "Oldest":
entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).filter(Dir.path_prefix.like(prefix+'%')).order_by(File.year,File.month,File.day,Entry.name).offset(offset).limit(how_many).all()
entries+=Entry.query.join(Dir).join(EntryDirLink).filter(Dir.path_prefix.like(prefix+'%')).order_by(Entry.name).offset(offset).limit(how_many).all()
else:
entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).filter(Dir.path_prefix.like(prefix+'%')).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all()
return render_template("files.html", page_title='View Files (Storage Path)', entry_data=entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size )
return render_template("files.html", page_title='View Files (Storage Path)', entry_data=entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size, folders=folders, cwd=cwd )
################################################################################
# /search -> show thumbnail view of files from import_path(s)
@@ -194,7 +207,15 @@ def files_sp():
@app.route("/search", methods=["GET","POST"])
def search():
noo, grouping, how_many, offset, size = ViewingOptions( request )
noo, grouping, how_many, offset, size, folders, cwd = ViewingOptions( request )
# seems html cant do boolean, but uses strings so convert
if folders == "False":
folders=False
if folders == "True":
folders=True
print( f"folders={folders}, type={type(folders)}" )
file_data=Entry.query.join(File).filter(Entry.name.ilike(f"%{request.form['term']}%")).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all()
dir_data=Entry.query.join(File).join(EntryDirLink).join(Dir).filter(Dir.path_prefix.ilike(f"%{request.form['term']}%")).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all()
@@ -202,7 +223,7 @@ def search():
all_entries = file_data + dir_data + ai_data
return render_template("files.html", page_title='View Files', search_term=request.form['term'], entry_data=all_entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size )
return render_template("files.html", page_title='View Files', search_term=request.form['term'], entry_data=all_entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size, folders=folders, cwd=cwd )
################################################################################
# /files/scannow -> allows us to force a check for new files
@@ -298,3 +319,22 @@ def move_files():
@app.route("/static/<filename>")
def custom_static(filename):
return send_from_directory("static/", filename)
###############################################################################
# This func creates a new filter in jinja2 to test to see if the Dir being
# checked, is a top-level folder of 'cwd'
################################################################################
@app.template_filter('TopLevelFolderOf')
def _jinja2_filter_toplevelfolderof(path, cwd):
if os.path.dirname(path) == cwd:
return True
else:
return False
###############################################################################
# This func creates a new filter in jinja2 to test to hand back the parent path
# from a given path
################################################################################
@app.template_filter('ParentPath')
def _jinja2_filter_parentpath(path):
return os.path.dirname(path)