first pass of import logging, its not being used, data is in real tables, but faked. will probably have to switch to gunicorn and threading to allow import and serving pages when we use slower AI routines
This commit is contained in:
59
importlog.py
Normal file
59
importlog.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from wtforms import SubmitField, StringField, FloatField, HiddenField, validators, Form
|
||||
from flask_wtf import FlaskForm
|
||||
from flask import request, render_template, redirect
|
||||
from main import db, app, ma
|
||||
from sqlalchemy import Sequence
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from status import st, Status
|
||||
from datetime import datetime, timedelta
|
||||
import pytz
|
||||
|
||||
################################################################################
|
||||
# Class describing Action in the database, and via sqlalchemy, connected to the DB as well
|
||||
################################################################################
|
||||
class Importlog(db.Model):
|
||||
id = db.Column(db.Integer, db.Sequence('importlog_id_seq'), primary_key=True )
|
||||
start_time = db.Column(db.DateTime(timezone=True))
|
||||
last_update = db.Column(db.DateTime(timezone=True))
|
||||
state = db.Column(db.String)
|
||||
num_passes = db.Column(db.Integer)
|
||||
current_pass = db.Column(db.Integer)
|
||||
num_files = db.Column(db.Integer)
|
||||
current_file_num = db.Column(db.Integer)
|
||||
current_file = db.Column(db.String)
|
||||
|
||||
def __repr__(self):
|
||||
return "<id: {}, start_time: {}, last_update: {}, state: {}, num_passes: {}, current_passes: {}, num_files: {}, current_file_num: {}, current_file: {}>".format(self.id, self.start_time, self.last_update, self.state, self.num_passes, self.current_pass, self.num_files, self.num_files, self.current_file_num, self.current_file)
|
||||
|
||||
class Importlogline(db.Model):
|
||||
action_id = db.Column(db.Integer, db.ForeignKey('import.id'), primary_key=True )
|
||||
log = db.Column(db.String)
|
||||
|
||||
################################################################################
|
||||
# /imports -> show current settings
|
||||
################################################################################
|
||||
@app.route("/imports", methods=["GET"])
|
||||
def imports():
|
||||
page_title='Import actions'
|
||||
imports = Importlog.query.all()
|
||||
return render_template("imports.html", imports=imports, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
|
||||
|
||||
|
||||
###############################################################################
|
||||
# /import/<id> -> GET -> shows status/history of imports
|
||||
################################################################################
|
||||
@app.route("/import/<id>", methods=["GET"])
|
||||
def importlog(id):
|
||||
page_title='Show Import Details'
|
||||
importlog = Importlog.query.get(id)
|
||||
duration=(datetime.now(pytz.utc)-importlog.start_time)
|
||||
duration= duration-timedelta(microseconds=duration.microseconds)
|
||||
return render_template("importlog.html", imp=importlog, st=importlog.start_time.strftime("%d/%m/%Y %I:%M:%S %p"), duration=duration, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
|
||||
|
||||
###############################################################################
|
||||
# This func creates a new filter in jinja2 to format the time from the db in a
|
||||
# way that is more readable (converted to local tz too)
|
||||
################################################################################
|
||||
@app.template_filter('vicdate')
|
||||
def _jinja2_filter_datetime(date, fmt=None):
|
||||
return date.strftime("%d/%m/%Y %I:%M:%S %p")
|
||||
Reference in New Issue
Block a user