diff --git a/TODO b/TODO
index 8647601..b6aae8a 100644
--- a/TODO
+++ b/TODO
@@ -1,9 +1,9 @@
## GENERAL
* on viewer:
- allow face to be used to:
- - create person
+ [DONE] - create person
[DONE] - add to existing person
- --> still need to consider whether we trigger an AI search immediately
+ --> still need to consider whether we trigger an AI search immediately (for these 2 options)
[DONE] - ignore/not a face/too young
[DONE] - redraw 'ignore's as a greyed out box?
[DONE] - menu should only allow override IF we have put override on...
diff --git a/internal/js/view_support.js b/internal/js/view_support.js
index b8eff74..a239401 100644
--- a/internal/js/view_support.js
+++ b/internal/js/view_support.js
@@ -291,11 +291,27 @@ function OverrideForceMatch( person_id, key )
} )
}
+function CreatePersonAndRefimg( key )
+{
+ d='&face_id='+item[key].id
+ +'&tag='+$('#tag').val()
+ +'&firstname='+$('#firstname').val()
+ +'&surname='+$('#surname').val()
+ +'&refimg_data='+item[key].refimg_data
+ $.ajax({ type: 'POST', data: d, url: '/match_with_create_person',
+ success: function(data) {
+ objs[current].faces[item[key].which_face].who=data.who
+ objs[current].faces[item[key].which_face].distance=data.distance
+ $('#dbox').modal('hide')
+ $('#faces').prop('checked',true)
+ DrawImg()
+ }
+ })
+}
+
function AddRefImgTo( person_id, key )
{
- d='&face_id='+item[key].id+'&person_id='+person_id+
- '&file_eid='+current+'&refimg_data='+item[key].refimg_data
- console.log( d )
+ d='&face_id='+item[key].id+'&person_id='+person_id+'&refimg_data='+item[key].refimg_data
$.ajax({ type: 'POST', data: d, url: '/add_refimg_to_person',
success: function(data) {
objs[current].faces[item[key].which_face].who=data.who
@@ -411,6 +427,9 @@ function FaceDBox(key, item)
success: function(img_data) {
item[key].refimg_data=img_data
$('#face_img').html( '' )
+ // used for create_new_person only, so this will do nothing for
+ // option menu items
+ $('#refimg_data').val(img_data)
}
} )
div+='
'
@@ -431,7 +450,24 @@ function FaceDBox(key, item)
}
if ( key == 'no_match_new_person' )
{
- div+=' create new person NOT YET'
+ div+=''
+ div+=`
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `
+ div+=''
}
if ( key == 'no_match_new_refimg' )
{
diff --git a/person.py b/person.py
index 36a6c17..52d073c 100644
--- a/person.py
+++ b/person.py
@@ -97,7 +97,7 @@ class PersonForm(FlaskForm):
def AddRefimgToPerson( filename, person ):
refimg = Refimg( fname=os.path.basename( filename ) )
try:
- #False == dont autorotate, its not needed on this image
+ #False == dont autorotate, its not needed on this image
refimg.thumbnail, refimg.orig_w, refimg.orig_h = GenThumb( filename, False )
settings = Settings.query.first()
model=AIModel.query.get(settings.default_refimg_model)
@@ -120,6 +120,24 @@ def AddRefimgToPerson( filename, person ):
st.SetMessage( f"Failed to modify Refimg: {e}", "danger" )
return
+################################################################################
+# TempRefimgFile: helper function that takes data POST'd (from dialog box to
+# add face to new/existing person). Converts data into a jpg file to be used by
+# wrapper funcs to AI / refimg <-> person. filename will be .jpg
+################################################################################
+def TempRefimgFile( data, tag ):
+ # undo the munging sending via http has done
+ data=data.replace(' ', '+' )
+
+ # convert b64 encoded to a temp file to process...
+ bytes_decoded = base64.b64decode(data)
+ img = Image.open(BytesIO(bytes_decoded))
+ out_jpg = img.convert("RGB")
+ # save file to /tmp/.jpg
+ fname="/tmp/" + tag + ".jpg"
+ out_jpg.save(fname)
+ return fname
+
################################################################################
# Routes for person data
#
@@ -163,6 +181,18 @@ def new_person():
else:
return render_template("person.html", person=None, form=form, page_title=page_title )
+@app.route("/match_with_create_person", methods=["POST"])
+@login_required
+def match_with_create_person():
+ p = Person( tag=request.form["tag"], surname=request.form["surname"], firstname=request.form["firstname"] )
+ # add this fname (of temp refimg) to person
+ fname=TempRefimgFile( request.form['refimg_data'], p.tag )
+ AddRefimgToPerson( fname, p )
+ resp={}
+ resp['who']=p.tag
+ resp['distance']='0.0'
+ return resp
+
################################################################################
# /person/ -> GET/POST(save or delete) -> shows/edits/delets a single person
################################################################################
@@ -266,7 +296,6 @@ def find_persons(who):
return resp
-
################################################################################
# /add_refimg_to_person/ -> POST
################################################################################
@@ -277,28 +306,10 @@ def add_refimg_to_person():
f = Face.query.get( request.form['face_id'] )
p = Person.query.get( request.form['person_id'] )
- file_eid = request.form['file_eid']
- refimg_data = request.form['refimg_data']
-
- # undo the munging sending via http has done
- refimg_data=refimg_data.replace(' ', '+' )
-
- print( refimg_data )
-
- # convert b64 encoded to a temp file to process...
- bytes_decoded = base64.b64decode(refimg_data)
- img = Image.open(BytesIO(bytes_decoded))
- out_jpg = img.convert("RGB")
- # save file to /tmp/
- fname="/tmp/" + p.tag + '.jpg'
- out_jpg.save(fname)
-
# add this fname (of temp refimg) to person
+ fname=TempRefimgFile( request.form['refimg_data'], p.tag )
AddRefimgToPerson( fname, p )
- # DDP:
- # need to create a new job to re-do AI now we have a new refimg in the mix
-
resp['who']=p.tag
resp['distance']='0.0'
return resp