diff --git a/files.py b/files.py index fca05ed..528eab7 100644 --- a/files.py +++ b/files.py @@ -133,6 +133,7 @@ def ViewingOptions( request ): offset=0 size=128 if 'files_sp' in request.path: + noo="A to Z" folders=True cwd='static/Storage' elif 'files_rbp' in request.path: @@ -170,6 +171,19 @@ def ViewingOptions( request ): return noo, grouping, how_many, offset, size, folders, cwd, root +def GetEntriesInFlatView( cwd, prefix, noo, offset, how_many ): + entries=[] + + if noo == "Oldest": + entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year,File.month,File.day,Entry.name).offset(offset).limit(how_many).all() + elif noo == "Newest": + entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() + elif noo == "Z to A": + entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(Entry.name.desc()).offset(offset).limit(how_many).all() + else: + entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(Entry.name).offset(offset).limit(how_many).all() + return entries + def GetEntriesInFolderView( cwd, prefix, noo, offset, how_many ): entries=[] # okay the root cwd is fake, so treat it specially - its Dir can be found by path with dir.rel_path='' @@ -183,12 +197,22 @@ def GetEntriesInFolderView( cwd, prefix, noo, offset, how_many ): if len(rp) and rp[0] == '/': rp=rp[1:] dir=Entry.query.join(Dir).join(PathDirLink).join(Path).filter(Dir.rel_path==rp).filter(Path.path_prefix==prefix).order_by(Entry.name).first() - entries+= Entry.query.join(EntryDirLink).join(FileType).filter(EntryDirLink.dir_eid==dir.id).filter(FileType.name=='Directory').all() + if noo == "Z to A" or "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 + else: + 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 noo == "Oldest": entries+=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(File.year,File.month,File.day,Entry.name).offset(offset).limit(how_many).all() - else: + elif noo == "Newest": 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(offset).limit(how_many).all() + elif noo == "Z to A": + entries+=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(Entry.name.desc()).offset(offset).limit(how_many).all() + # just do A to Z by default or if no valid option + else: + entries+=Entry.query.join(File).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir.id).order_by(Entry.name).offset(offset).limit(how_many).all() return entries ################################################################################ @@ -212,14 +236,10 @@ def files_ip(): paths = settings.import_path.split("#") for path in paths: prefix = SymlinkName("Import",path,path+'/') - - if folders: - entries+=GetEntriesInFolderView( cwd, prefix, noo, offset, how_many ) - else: - if noo == "Oldest": - entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year,File.month,File.day,Entry.name).offset(offset).limit(how_many).all() + if folders: + entries+=GetEntriesInFolderView( cwd, prefix, noo, offset, how_many ) else: - entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() + entries+=GetEntriesInFlatView( cwd, prefix, noo, offset, how_many ) 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, root=root ) @@ -236,14 +256,10 @@ def files_sp(): paths = settings.storage_path.split("#") for path in paths: prefix = SymlinkName("Storage",path,path+'/') - if folders: entries+=GetEntriesInFolderView( cwd, prefix, noo, offset, how_many ) else: - if noo == "Oldest": - entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year,File.month,File.day,Entry.name).offset(offset).limit(how_many).all() - else: - entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() + entries+=GetEntriesInFlatView( cwd, prefix, noo, offset, how_many ) 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, root=root ) @@ -261,14 +277,10 @@ def files_rbp(): paths = settings.recycle_bin_path.split("#") for path in paths: prefix = SymlinkName("Bin",path,path+'/') - if folders: entries+=GetEntriesInFolderView( cwd, prefix, noo, offset, how_many ) else: - if noo == "Oldest": - entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year,File.month,File.day,Entry.name).offset(offset).limit(how_many).all() - else: - entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).join(PathDirLink).join(Path).filter(Path.path_prefix==prefix).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() + entries+=GetEntriesInFlatView( cwd, prefix, noo, offset, how_many ) return render_template("files.html", page_title='View Files (Bin Path)', entry_data=entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size, folders=folders, cwd=cwd, root=root ) diff --git a/templates/files.html b/templates/files.html index b4b9472..89c6ff6 100644 --- a/templates/files.html +++ b/templates/files.html @@ -24,7 +24,7 @@ {% endif %}