From 7a17d9177999e0a87f373308e396eba4195b7e15 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 29 Jan 2022 18:53:30 +1100 Subject: [PATCH] now use eval() for GetEntries*Fold*, and much better fix for bug where next/prev was breaking with inputs with spaces in names -- dont need those inputs anyway, JUST pass next or prev and the rest comes from pa_user_state now --- files.py | 26 ++++++++------------------ internal/js/files_support.js | 8 -------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/files.py b/files.py index 6710733..dda49b0 100644 --- a/files.py +++ b/files.py @@ -238,6 +238,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, 0 + # dirs cant be sorted by date really, so do best I can for now 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 @@ -245,26 +246,15 @@ def GetEntriesInFolderView( OPT, prefix ): entries+= Entry.query.join(EntryDirLink).join(FileType).filter(EntryDirLink.dir_eid==dir.id).filter(FileType.name=='Directory').order_by(Entry.name).all() # add any files at the current CWD (based on dir_eid in DB) - if OPT.noo == "Oldest": - file_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) - elif OPT.noo == "Newest": - file_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) - elif OPT.noo == "Z to A": - file_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) - # just do A to Z by default or if no valid option - else: - file_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()) + join="Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id)" + file_entries= eval( f"{join}.{OPT.order}.offset(OPT.offset).limit(OPT.how_many).all()") + if OPT.offset == 0 and len(file_entries): OPT.first_eid = file_entries[0].id - if len(file_entries): - num_entries=last_entry.count() - le=last_entry.limit(1).all() - if len(le): - OPT.last_eid = le[0].id + num_entries = eval( f"{join}.count()" ) + last_entry = eval( f"{join}.{OPT.last_order}.limit(1).first()" ) + if last_entry: + OPT.last_eid = last_entry.id entries += file_entries; return entries, num_entries diff --git a/internal/js/files_support.js b/internal/js/files_support.js index affe785..e41639a 100644 --- a/internal/js/files_support.js +++ b/internal/js/files_support.js @@ -1,11 +1,3 @@ -// this is needed as serliazeArray doesnt handle spaces in values -// so we wrap it in this func -$.fn.serializeAndEncode = function() { - return $.map(this.serializeArray(), function(val) { - return [val.name, encodeURIComponent(val.value)].join('='); - }).join('&'); -}; - // grab all selected thumbnails and return a
containing the thumbnails // with extra yr and date attached as attributes so we can set the default // dir name for a move directory - not used in del, but no harm to include them