removed debugs, added faces to class File, use f print string format, hacky json.loads of face locn data to put it back to being an array -- and of course storing that in the class

This commit is contained in:
2021-07-17 16:38:50 +10:00
parent 24c4b962e5
commit ae39c26b8f

View File

@@ -16,6 +16,7 @@ import numpy
import cv2
import time
import re
import json
from flask_login import login_required, current_user
################################################################################
@@ -71,7 +72,7 @@ class Entry(db.Model):
in_dir = db.relationship ("Dir", secondary="entry_dir_link", uselist=False )
def __repr__(self):
return "<id: {}, name: {}, type={}, dir_details={}, file_details={}, in_dir={}>".format(self.id, self.name, self.type, self.dir_details, self.file_details, self.in_dir)
return f"<id: {self.id}, name: {self.name}, type={self.type}, dir_details={self.dir_details}, file_details={self.file_details}, in_dir={self.in_dir}"
class File(db.Model):
__tablename__ = "file"
@@ -83,9 +84,10 @@ class File(db.Model):
month = db.Column(db.Integer)
day = db.Column(db.Integer)
woy = db.Column(db.Integer)
faces = db.relationship ("Face", secondary="face_file_link" )
def __repr__(self):
return f"<eid: {self.eid}, size_mb={self.size_mb}, hash={self.hash}, year={self.year}, month={self.month}, day={self.day}, woy={self.woy}>"
return f"<eid: {self.eid}, size_mb={self.size_mb}, hash={self.hash}, year={self.year}, month={self.month}, day={self.day}, woy={self.woy}, faces={self.faces}>"
class FileType(db.Model):
__tablename__ = "file_type"
@@ -321,7 +323,6 @@ def search():
if 'AI:' in term:
term = term.replace('AI:','')
all_entries = Entry.query.join(File).join(FaceFileLink).join(Face).join(FaceRefimgLink).join(Refimg).join(PersonRefimgLink).join(Person).filter(Person.tag.ilike(f"%{term}%")).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all()
print( all_entries )
else:
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.rel_path.ilike(f"%{request.form['term']}%")).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all()
@@ -459,6 +460,9 @@ def viewnext():
lst = eids.split(',')
new_id = lst[lst.index(id)+1]
obj = Entry.query.join(File).filter(Entry.id==new_id).first()
# put locn data back into array format
for face in obj.file_details.faces:
face.locn = json.loads(face.locn)
return render_template("viewer.html", obj=obj, eids=eids)
@app.route("/viewprev", methods=["GET","POST"])
@@ -470,12 +474,19 @@ def viewprev():
lst = eids.split(',')
new_id = lst[lst.index(id)-1]
obj = Entry.query.join(File).filter(Entry.id==new_id).first()
# put locn data back into array format
for face in obj.file_details.faces:
face.locn = json.loads(face.locn)
return render_template("viewer.html", obj=obj, eids=eids)
@app.route("/view/<id>", methods=["GET","POST"])
@login_required
def view_img(id):
obj = Entry.query.join(File).filter(Entry.id==id).first()
# put locn data back into array format
for face in obj.file_details.faces:
face.locn = json.loads(face.locn)
if request.method=="POST":
eids=request.form['eids']
else: