Put new functionality in to allow choosing existing folder in move code - it goes back and forwards 7 days from the date of this file and finds matching files and uses those dirs, or just dirname matches for those dates and offers them up. Also improved Move code to reject dodgy paths

This commit is contained in:
2022-01-09 12:20:29 +11:00
parent 0cb4c1879c
commit dc21d65dd7
4 changed files with 69 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
from wtforms import SubmitField, StringField, HiddenField, validators, Form
from flask_wtf import FlaskForm
from flask import request, render_template, redirect, send_from_directory, url_for
from flask import request, render_template, redirect, send_from_directory, url_for, jsonify
from path import MovePathDetails
from main import db, app, ma
from sqlalchemy import Sequence
@@ -18,6 +18,7 @@ import cv2
import time
import re
import json
import datetime
from flask_login import login_required, current_user
from options import Options
@@ -615,3 +616,42 @@ def _jinja2_filter_toplevelfolderof(path, cwd):
@app.template_filter('ParentPath')
def _jinja2_filter_parentpath(path):
return os.path.dirname(path)
###############################################################################
# route to allow the Move Dialog Box to pass a date (YYYYMMDD) and returns a
# json? list of existing dir names that could be near it in time. Starting
# simple, by using YYYYMM-1, YYYYMM, YYYYMM+1 dirs
###############################################################################
@app.route("/getexistingpaths/<dt>", methods=["POST"])
@login_required
def GetExistingPathsAsDiv(dt):
dir_ft=FileType.query.filter(FileType.name=='Directory').first()
dirs_arr=[]
for delta in range(-7, 8):
new_dtime=datetime.datetime.strptime(dt, "%Y%m%d") + datetime.timedelta(days=delta)
new_dt=new_dtime.strftime('%Y%m%d')
dirs_arr+=Dir.query.distinct(Dir.rel_path).filter(Dir.rel_path.ilike('%'+new_dt+'%')).all();
dirs_arr+=Dir.query.distinct(Dir.rel_path).join(EntryDirLink).join(Entry).filter(Entry.type_id!=dir_ft.id).filter(Entry.name.ilike('%'+new_dt+'%')).all()
# remove duplicates from array
dirs = set(dirs_arr)
# turn DB output into json and return it to the f/e
ret='[ '
first_dir=1
for dir in dirs:
print( f"process dir matching for {new_dt} => {dir}")
if not first_dir:
ret +=", "
bits=dir.rel_path.split('-')
ret+= '{ '
ret+= '"prefix":"' + bits[0] + '", '
if len(bits)>1:
ret+= '"suffix":"' + bits[1] + '"'
else:
ret+= '"suffix":"''"'
ret+= ' } '
first_dir=0
ret+= ' ]'
return ret