added reference image class, also tweaked DB classes to have foreign keys, so you cant delete a person connected to a file (tested). Also made refimg class do some quirky bootstrap/jquery to get file dialogs not looking like crap

This commit is contained in:
2021-01-12 23:58:12 +11:00
parent a3a95f636e
commit ed3a85b8f0
4 changed files with 105 additions and 6 deletions

11
main.py
View File

@@ -30,6 +30,17 @@ Bootstrap(app)
from settings import Settings from settings import Settings
from files import Files from files import Files
from person import Person from person import Person
from refimg import Refimg
from ai import *
####################################### CLASSES / DB model #######################################
class Person_Refimg_Link(db.Model):
__tablename__ = "person_refimg_link"
person_id = db.Column(db.Integer, db.ForeignKey('person.id'), unique=True, nullable=False, primary_key=True)
refimg_id = db.Column(db.Integer, db.ForeignKey('refimg.id'), unique=True, nullable=False, primary_key=True)
def __repr__(self):
return "<person_id: {}, refimg_id>".format(self.person_id, self.refimg_id)
####################################### GLOBALS ####################################### ####################################### GLOBALS #######################################
# allow jinja2 to call these python functions directly # allow jinja2 to call these python functions directly

View File

@@ -6,6 +6,8 @@ from sqlalchemy import Sequence
from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.exc import SQLAlchemyError
from status import st, Status from status import st, Status
from files import Files
################################################################################ ################################################################################
# Class describing Person in the database, and via sqlalchemy, connected to the DB as well # Class describing Person in the database, and via sqlalchemy, connected to the DB as well
################################################################################ ################################################################################
@@ -18,6 +20,14 @@ class Person(db.Model):
def __repr__(self): def __repr__(self):
return "<tag: {}, firstname: {}, surname: {}>".format(self.tag,self.firstname, self.surname) return "<tag: {}, firstname: {}, surname: {}>".format(self.tag,self.firstname, self.surname)
class File_Person_Link(db.Model):
__tablename__ = "file_person_link"
file_id = db.Column(db.Integer, db.ForeignKey('files.id'), unique=True, nullable=False, primary_key=True)
person_id = db.Column(db.Integer, db.ForeignKey('person.id'), unique=True, nullable=False, primary_key=True)
def __repr__(self):
return "<file_id: {}, person_id: {}>".format(self.file_id, self.person_id)
################################################################################ ################################################################################
# Helper class that inherits a .dump() method to turn class Person into json / useful in jinja2 # Helper class that inherits a .dump() method to turn class Person into json / useful in jinja2
################################################################################ ################################################################################
@@ -100,9 +110,3 @@ def person(id):
person = Person.query.get(id) person = Person.query.get(id)
form = PersonForm(request.values, obj=person) form = PersonForm(request.values, obj=person)
return render_template("person.html", object=person, form=form, page_title = page_title, alert=st.GetAlert(), message=st.GetMessage() ) return render_template("person.html", object=person, form=form, page_title = page_title, alert=st.GetAlert(), message=st.GetMessage() )
################################################################################
# helper fund to GetPersons -> person_list -> jinja2 for person drop-down in book.html
################################################################################
def GetPersons():
return Person.query.order_by('surname','firstname').all()

69
templates/refimg.html Normal file
View File

@@ -0,0 +1,69 @@
{% extends "base.html" %}
{% block main_content %}
<div class="container">
<h3 class="offset-lg-2">{{page_title}}</h3>
<div class="row">
<form class="form form-inline col-xl-12" action="" method="POST">
{% for field in form %}
{% if field.type == 'HiddenField' or field.type == 'CSRFTokenField' %}
{{field}}<br>
{% elif field.type != 'SubmitField' %}
<div class="form-row col-lg-12">
{% if 'Edit' in page_title %}
{{ field.label( class="col-lg-2" ) }}
<div class="input-group col-lg-8">
<div class="input-group-prepend">
<input id="fname_id" type="hidden" name="fname" value="{{field.data}}">
</div>
<div class="input-group-append">
<span id="fname_span" name="fname" class="form-control">{{field.data}}</span>
<label class="btn btn-outline-primary">
Change File
<input type="file" onChange="DoMagic()" style="display: none;" id="new_file_chooser">
</label>
</div class="input-group-append">
{% else %}
{{ field.label( class="col-lg-2" ) }}
<input id="fname_id" type="hidden" name="fname" value="{{field.data}}">
<div class="input-group col-lg-8">
<div class="input-group-prepend">
<span id="fname_span" name="fname" class="form-control">{{field.data}}</span>
</div>
<div class="input-group-append">
<label class="btn btn-outline-primary">
Choose File
<input type="file" onChange="DoMagic()" style="display:none;" id="new_file_chooser">
</label>
</div class="input-group-append">
</div>
{% endif %}
</div class="form-row col-lg-12">
{% endif %}
{% endfor %}
<div class="row col-lg-12">
<br>
</div class="row">
<div class="form-row col-lg-12">
{{ form.submit( class="btn btn-primary offset-lg-2 col-lg-2" )}}
{% if 'Edit' in page_title %}
{{ form.delete( class="btn btn-outline-danger col-lg-2" )}}
{% endif %}
</div class="form-row">
</form>
</div class="row">
</div class="container">
{% endblock main_content %}
{% block script_content %}
<script>
function DoMagic() {
str=$("#new_file_chooser").val()
console.log(str)
str=str.replace('C:\\fakepath\\', '' )
console.log(str)
$("#fname_span").html(str)
$("#fname_id").val(str)
$("#new_file_chooser").val('')
}
</script>
{% endblock script_content %}

15
templates/refimgs.html Normal file
View File

@@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block main_content %}
<h3>Show All Reference Images</h3>
<table id="refimg_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
<thead>
<tr class="thead-light"><th>Filename</th></tr>
</thead>
<tbody>
{% for refimg in refimgs %}
<tr><td><a href="{{url_for('refimg', id=refimg.id )}}">{{refimg.fname}}</td></tr>
{% endfor %}
</tbody>
</table>
{% endblock main_content %}