From 2db7f59a403ada4d68f44a5b57331bdbe27e6b09 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 30 Jan 2021 23:26:52 +1100 Subject: [PATCH] made basic newest/oldest week/month/year part of gui actually retreive what we want, and have a title per grouping, but the grouping title is hard-coded for now, will need more data to do a better test, also hacky submit button for now until I decide how to enact the gui change requested --- files.py | 45 ++++++++++++++++++++++++++++++++------------ pa_job_manager.py | 2 +- templates/files.html | 26 ++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 16 deletions(-) diff --git a/files.py b/files.py index 68f8ce6..13dd3e3 100644 --- a/files.py +++ b/files.py @@ -70,7 +70,6 @@ class File(db.Model): __tablename__ = "file" eid = db.Column(db.Integer, db.ForeignKey("entry.id"), primary_key=True ) size_mb = db.Column(db.Integer, unique=False, nullable=False) - hash = db.Column(db.Integer, unique=True, nullable=True) thumbnail = db.Column(db.String, unique=False, nullable=True) hash = db.Column(db.Integer) year = db.Column(db.Integer) @@ -79,7 +78,7 @@ class File(db.Model): woy = db.Column(db.Integer) def __repr__(self): - return "".format(self.eid, self.size_mb, self.hash ) + return f"" class FileType(db.Model): __tablename__ = "file_type" @@ -100,19 +99,41 @@ def file_list(): ################################################################################ # /files -> show thumbnail view of files from import_path(s) ################################################################################ -@app.route("/files", methods=["GET"]) +@app.route("/files", methods=["GET", "POST"]) def files(): - order_by="asc" - grouping="day" - which="week" - if which == "week": + noo="Oldest" + grouping="Day" + which="Week" + + if request.method=="POST": + noo=request.form['noo'] + which=request.form['which'] + grouping=request.form['grouping'] + + print( f"noo={noo}, which={which}, grouping={grouping}") + + entries=[] + if noo == "Oldest": year=File.query.order_by(File.year).first() + month=File.query.filter(File.year==year.year).order_by(File.month).first() woy=File.query.filter(File.year==year.year).order_by(File.woy).first() - if order_by == "desc": - entries=Entry.query.join(File).filter(File.year==year.year).filter(File.woy==woy.woy).order_by(Entry.name.desc()).all() - else: - entries=Entry.query.join(File).filter(File.year==year.year).filter(File.woy==woy.woy).order_by(Entry.name.desc()).all() - return render_template("files.html", page_title='View Files', entry_data=entries ) + if which == "Week": + entries=Entry.query.join(File).filter(File.year==year.year).filter(File.woy==woy.woy).order_by(Entry.name).all() + elif which == "month": + entries=Entry.query.join(File).filter(File.year==year.year).filter(File.month==month.month).order_by(Entry.name).all() + elif which == "Year": + entries=Entry.query.join(File).filter(File.year==year.year).order_by(Entry.name).all() + else: + year=File.query.order_by(File.year.desc()).first() + month=File.query.filter(File.year==year.year).order_by(File.month.desc()).first() + woy=File.query.filter(File.year==year.year).order_by(File.woy.desc()).first() + if which == "Week": + entries=Entry.query.join(File).filter(File.year==year.year).filter(File.woy==woy.woy).order_by(Entry.name).all() + elif which == "Month": + entries=Entry.query.join(File).filter(File.year==year.year).filter(File.month==month.month).order_by(Entry.name).all() + elif which == "Year": + entries=Entry.query.join(File).filter(File.year==year.year).order_by(Entry.name).all() + return render_template("files.html", page_title='View Files', entry_data=entries, grouping=grouping, which=which ) ################################################################################ # /search -> show thumbnail view of files from import_path(s) diff --git a/pa_job_manager.py b/pa_job_manager.py index 93637ed..9f8feae 100644 --- a/pa_job_manager.py +++ b/pa_job_manager.py @@ -260,9 +260,9 @@ def ProcessImportDirs(parent_job=None): job2.extra.append(jex2) session.add(job2) session.commit() - """ if parent_job: AddLogForJob(parent_job, "adding job id={} {} (wait for: {})".format( job2.id, job2.id, job2.name, job2.wait_for ) ) + """ jex3=JobExtra( name="path", value=path ) job3=Job(start_time=now, last_update=now, name="processai", state="New", wait_for=job2.id, pa_job_state="New", current_file_num=0 ) job3.extra.append(jex3) diff --git a/templates/files.html b/templates/files.html index 97880ec..2450959 100644 --- a/templates/files.html +++ b/templates/files.html @@ -2,16 +2,18 @@ {% block main_content %}

+
+
- - @@ -19,7 +21,7 @@
- @@ -46,9 +48,27 @@
+
+ {% set last = namespace(printed=0) %} {% for obj in entry_data %} + {% if which == "Week" %} + {% if last.printed != obj.file_details[0].day %} +
Day: {{obj.file_details[0].day}} of {{obj.file_details[0].month}}/{{obj.file_details[0].year}}
+ {% set last.printed = obj.file_details[0].day %} + {% endif %} + {% elif which == "Month" %} + {% if last.printed != obj.file_details[0].woy %} +
Week #: {{obj.file_details[0].woy}} of {{obj.file_details[0].year}}
+ {% set last.printed = obj.file_details[0].woy %} + {% endif %} + {% elif which == "Year" %} + {% if last.printed != obj.file_details[0].month %} +
Month: {{obj.file_details[0].month}} of {{obj.file_details[0].year}}
+ {% set last.printed = obj.file_details[0].month %} + {% endif %} + {% endif %} {% if obj.type.name != "Directory" %}