moved over to new ENTRY based data structures for loading from DB and viewing content
This commit is contained in:
48
files.py
48
files.py
@@ -26,18 +26,52 @@ from job import Job, Joblog, NewJob
|
|||||||
# Class describing File in the database, and via sqlalchemy, connected to the DB as well
|
# Class describing File in the database, and via sqlalchemy, connected to the DB as well
|
||||||
# This has to match one-for-one the DB table
|
# This has to match one-for-one the DB table
|
||||||
################################################################################
|
################################################################################
|
||||||
class File(db.Model):
|
class EntryDirLink(db.Model):
|
||||||
|
__tablename__ = "entry_dir_link"
|
||||||
|
entry_id = db.Column(db.Integer, db.ForeignKey("entry.id"), primary_key=True )
|
||||||
|
dir_eid = db.Column(db.Integer, db.ForeignKey("dir.eid"), primary_key=True )
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<entry_id: {}, dir_eid: {}>".format(self.entry_id, self.dir_eid)
|
||||||
|
|
||||||
|
class Dir(db.Model):
|
||||||
|
__tablename__ = "dir"
|
||||||
|
eid = db.Column(db.Integer, db.ForeignKey("entry.id"), primary_key=True )
|
||||||
|
path_prefix = db.Column(db.String, unique=False, nullable=False )
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<eid: {}, path_prefix: {}>".format(self.eid, self.path_prefix)
|
||||||
|
|
||||||
|
class Entry(db.Model):
|
||||||
|
__tablename__ = "entry"
|
||||||
id = db.Column(db.Integer, db.Sequence('file_id_seq'), primary_key=True )
|
id = db.Column(db.Integer, db.Sequence('file_id_seq'), primary_key=True )
|
||||||
name = db.Column(db.String, unique=True, nullable=False )
|
name = db.Column(db.String, unique=True, nullable=False )
|
||||||
type = db.Column(db.String, unique=False, nullable=False)
|
type_id = db.Column(db.Integer, db.ForeignKey("file_type.id"))
|
||||||
path_prefix = db.Column(db.String, unique=False, nullable=False)
|
type = db.relationship("FileType")
|
||||||
|
dir_details = db.relationship( "Dir")
|
||||||
|
file_details = db.relationship( "New_File" )
|
||||||
|
in_dir = db.relationship ("Dir", secondary="entry_dir_link" )
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
class New_File(db.Model):
|
||||||
|
__tablename__ = "new_file"
|
||||||
|
eid = db.Column(db.Integer, db.ForeignKey("entry.id"), primary_key=True )
|
||||||
size_mb = db.Column(db.Integer, unique=False, nullable=False)
|
size_mb = db.Column(db.Integer, unique=False, nullable=False)
|
||||||
# hash might not be unique, this could be the source of dupe problems
|
|
||||||
hash = db.Column(db.Integer, unique=True, nullable=True)
|
hash = db.Column(db.Integer, unique=True, nullable=True)
|
||||||
thumbnail = db.Column(db.String, unique=False, nullable=True)
|
thumbnail = db.Column(db.String, unique=False, nullable=True)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<id: {}, name: {}>".format(self.id, self.name )
|
return "<eid: {}, size_mb={}, hash={}>".format(self.eid, self.size_mb, self.hash )
|
||||||
|
|
||||||
|
class FileType(db.Model):
|
||||||
|
__tablename__ = "file_type"
|
||||||
|
id = db.Column(db.Integer, db.Sequence('file_type_id_seq'), primary_key=True )
|
||||||
|
name = db.Column(db.String, unique=True, nullable=False )
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<id: {}, name={}>".format(self.id, self.name )
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -45,14 +79,14 @@ class File(db.Model):
|
|||||||
################################################################################
|
################################################################################
|
||||||
@app.route("/file_list", methods=["GET"])
|
@app.route("/file_list", methods=["GET"])
|
||||||
def file_list():
|
def file_list():
|
||||||
return render_template("file_list.html", page_title='View Files (details)', file_data=File.query.all())
|
return render_template("file_list.html", page_title='View Files (details)', entry_data=Entry.query.all())
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# /files -> show thumbnail view of files from import_path(s)
|
# /files -> show thumbnail view of files from import_path(s)
|
||||||
################################################################################
|
################################################################################
|
||||||
@app.route("/files", methods=["GET"])
|
@app.route("/files", methods=["GET"])
|
||||||
def files():
|
def files():
|
||||||
return render_template("files.html", page_title='View Files', file_data=File.query.all())
|
return render_template("files.html", page_title='View Files', entry_data=Entry.query.all())
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# /files/scannow -> allows us to force a check for new files
|
# /files/scannow -> allows us to force a check for new files
|
||||||
|
|||||||
2
main.py
2
main.py
@@ -28,7 +28,7 @@ Bootstrap(app)
|
|||||||
|
|
||||||
################################# Now, import non-book classes ###################################
|
################################# Now, import non-book classes ###################################
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
from files import File
|
from files import Entry
|
||||||
from person import Person
|
from person import Person
|
||||||
from refimg import Refimg
|
from refimg import Refimg
|
||||||
from job import Job, GetNumActiveJobs
|
from job import Job, GetNumActiveJobs
|
||||||
|
|||||||
@@ -4,25 +4,25 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<table class="table table-striped table-sm col-xl-12">
|
<table class="table table-striped table-sm col-xl-12">
|
||||||
<thead><tr class="thead-light"><th>Name</th><th>Size (MB)</th><th>Path Prefix</th><th>Hash</th></tr></thead><tbody>
|
<thead><tr class="thead-light"><th>Name</th><th>Size (MB)</th><th>Path Prefix</th><th>Hash</th></tr></thead><tbody>
|
||||||
{% for obj in file_data %}
|
{% for obj in entry_data %}
|
||||||
<tr><td>
|
<tr><td>
|
||||||
{% if obj.type == "Directory" %}
|
{% if obj.type.name == "Directory" %}
|
||||||
<i style="font-size:48;" class="fas fa-folder"></i><br><span class="figure-caption">{{obj.name}}</span>
|
<i style="font-size:48;" class="fas fa-folder"></i><br><span class="figure-caption">{{obj.name}}</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<figure class="figure" font-size: 24px;>
|
<figure class="figure" font-size: 24px;>
|
||||||
<div style="position:relative; width:100%">
|
<div style="position:relative; width:100%">
|
||||||
{% if obj.type=="Image" %}
|
{% if obj.type.name=="Image" %}
|
||||||
{% set icon="fa-file-image" %}
|
{% set icon="fa-file-image" %}
|
||||||
<a href="{{obj.path_prefix}}/{{obj.name}}">
|
<a href="{{obj.in_dir[0].path_prefix}}/{{obj.name}}">
|
||||||
{% elif obj.type == "Video" %}
|
{% elif obj.type.name == "Video" %}
|
||||||
{% set icon="fa-film" %}
|
{% set icon="fa-film" %}
|
||||||
{% elif obj.type == "Directory" %}
|
{% elif obj.type.name == "Directory" %}
|
||||||
{% set icon="fa-folder" %}
|
{% set icon="fa-folder" %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set icon="fa-question-circle" %}
|
{% set icon="fa-question-circle" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<img class="thumb" style="display:block" height="48" src="data:image/jpeg;base64,{{obj.thumbnail}}"></img>
|
<img class="thumb" style="display:block" height="48" src="data:image/jpeg;base64,{{obj.file_details[0].thumbnail}}"></img>
|
||||||
{% if obj.type=="Image" %}
|
{% if obj.type.name=="Image" %}
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div style="position:absolute; top: 2; left: 2;">
|
<div style="position:absolute; top: 2; left: 2;">
|
||||||
@@ -32,7 +32,13 @@
|
|||||||
<figcaption class="figure-caption">{{obj.name}}</figcaption>
|
<figcaption class="figure-caption">{{obj.name}}</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td></td><td>{{obj.size_mb}}</td><td>{{obj.path_prefix}}</td><td>{{obj.hash}}</tr>
|
</td>
|
||||||
|
{% if obj.type.name != "Directory" %}
|
||||||
|
<td>{{obj.file_details[0].size_mb}}</td><td>{{obj.in_dir[0].path_prefix}}</td><td>{{obj.file_details[0].hash}}</td>
|
||||||
|
{% else %}
|
||||||
|
<td></td><td></td><td></td>
|
||||||
|
{% endif %}
|
||||||
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody></table>
|
</tbody></table>
|
||||||
</div class="row">
|
</div class="row">
|
||||||
|
|||||||
@@ -24,15 +24,15 @@
|
|||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% for obj in file_data %}
|
{% for obj in entry_data %}
|
||||||
{% if obj.type != "Directory" %}
|
{% if obj.type.name != "Directory" %}
|
||||||
<center>
|
<center>
|
||||||
<figure class="figure px-2" font-size: 24px;>
|
<figure class="figure px-2" font-size: 24px;>
|
||||||
{% if obj.type=="Image" %}
|
{% if obj.type.name=="Image" %}
|
||||||
<a href="{{obj.path_prefix}}/{{obj.name}}"><img class="thumb" height="128" src="data:image/jpeg;base64,{{obj.thumbnail}}"></img></a>
|
<a href="{{obj.in_dir[0].path_prefix}}/{{obj.name}}"><img class="thumb" height="128" src="data:image/jpeg;base64,{{obj.file_details[0].thumbnail}}"></img></a>
|
||||||
{% elif obj.type == "Video" %}
|
{% elif obj.type.name == "Video" %}
|
||||||
<div style="position:relative; width:100%">
|
<div style="position:relative; width:100%">
|
||||||
<img class="thumb" style="display:block" height="128" src="data:image/jpeg;base64,{{obj.thumbnail}}"></img>
|
<img class="thumb" style="display:block" height="128" src="data:image/jpeg;base64,{{obj.file_details[0].thumbnail}}"></img>
|
||||||
<div style="position:absolute; top: 2; left: 2;">
|
<div style="position:absolute; top: 2; left: 2;">
|
||||||
<i style="font-size:32;background-color:black;color:white" class="fas fa-film"></i>
|
<i style="font-size:32;background-color:black;color:white" class="fas fa-film"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user