From 8c78d9e6334d04c2d615c67e3ef642aee606b8b4 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Fri, 10 Jun 2022 16:53:13 +1000 Subject: [PATCH] progress towards allowing overrides. dbox can now allow finding a person and clicking them to post to back-end.. More work to make this real, for now it goes through the routes but does not update the DB, see bottom of face.py for next steps --- face.py | 24 ++++++++++++++++++++ internal/js/view_support.js | 44 +++++++++++++++++++++++++++++++++++-- person.py | 42 ++++++++++++++++++++++++++++++++++- 3 files changed, 107 insertions(+), 3 deletions(-) diff --git a/face.py b/face.py index 2fb73cf..ef1ab95 100644 --- a/face.py +++ b/face.py @@ -2,6 +2,7 @@ from main import db, app, ma from sqlalchemy import Sequence from sqlalchemy.exc import SQLAlchemyError + # DEL ME SOON from flask_login import login_required from flask import render_template @@ -61,3 +62,26 @@ class FaceRefimgLink(db.Model): def __repr__(self): return f"'+person.firstname+' '+person.surname+'('+person.tag+')
' + } + $('#search_person_results').html( content ) + } + } ) + return false +} + + +// function that is called when we click on a face in the viewer and we want to +// potentially override the non-match / match... it shows the face, and then +// based on which menu item got us here, shows appropriate text to do next action function FaceDBox(key, item) { div ='

' @@ -279,9 +316,12 @@ function FaceDBox(key, item) div+= `

- +
- ` +
+
` } if ( key == 'wrong_person' ) { diff --git a/person.py b/person.py index e8b28ba..adf324b 100644 --- a/person.py +++ b/person.py @@ -9,7 +9,7 @@ from status import st, Status from flask_login import login_required, current_user from werkzeug.utils import secure_filename from shared import GenFace, GenThumb -from face import FaceRefimgLink +from face import Face, FaceRefimgLink import os import json import time @@ -225,3 +225,43 @@ def add_refimg(): except Exception as e: st.SetMessage( f"Failed to modify Refimg: {e}", "danger" ) return redirect( url_for( 'person', id=person.id) ) + +################################################################################ +# /find_persons/ -> POST (an arbitrary string to find a person (via +# name/tag match) +################################################################################ +@app.route("/find_persons/", methods=["POST"]) +@login_required +def find_persons(who): + resp={} + people = Person.query.filter( Person.tag.ilike(f'%{who}%') | Person.firstname.ilike(f'%{who}%') | Person.surname.ilike(f'%{who}%') ).all(); + + for p in people: + resp[p.id]={} + resp[p.id]['id']=p.id + resp[p.id]['tag']=p.tag + resp[p.id]['firstname']=p.firstname + resp[p.id]['surname']=p.surname + + print( resp ) + return resp + +################################################################################ +# /override_force_match -> POST +################################################################################ +@app.route("/override_force_match", methods=["POST"]) +@login_required +def override_force_match(): + person_id = request.form['person_id'] + face_id = request.form['face_id'] + p = Person.query.get(person_id); + if not p: + raise Exception("could not find person to add override too!") + f = Face.query.get(face_id); + if not f: + raise Exception("could not find face to add override for!") + + print( f"Being asked to force an override match for face_id {face_id}, for person: {p.tag} -- doing nothing for now" ) + st.SetMessage( f"Being asked to force an override match for face_id {face_id}, for person: {p.tag} -- doing nothing for now" ) + # might need to do something smarter here (reload to old view is good though & happens now, not sure why (last url)?) + return "ok"