break upload logic calls out to seperate file

This commit is contained in:
2021-10-22 22:05:57 -06:00
parent c66954150a
commit 48e18382f5
2 changed files with 16 additions and 11 deletions
+8 -3
View File
@@ -5,10 +5,10 @@ from flask import(
Blueprint, current_app, flash, g, redirect, render_template, request, session, url_for
)
from werkzeug.exceptions import abort
from werkzeug.utils import secure_filename
from flaskfdx.auth import login_required
from flaskfdx.db import get_db
from flaskfdx.upload import process_file
bp = Blueprint('dashboard', __name__)
@@ -67,7 +67,12 @@ def upload():
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(current_app.config['UPLOAD_FOLDER'], filename))
# todo validity check before processing
filename, error = process_file(filetype, file)
if error:
print(error)
else:
file.save(os.path.join(current_app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('index'))
return render_template('dashboard/upload.html')
+8 -8
View File
@@ -112,16 +112,11 @@ def processDsw(file, database):
reportDate = getDate(srcSheet)
#open the database
conn = openDatabase(database)
if conn == None:
sys.exit('database could not be opened, does it exist')
# check if records already exist and then add records if not
if checkDate(conn, reportDate):
if checkDate(database, reportDate):
print("we have already processed " + reportDate)
else:
extractDsw(srcSheet, conn, reportDate)
extractDsw(srcSheet, database, reportDate)
def main():
@@ -132,8 +127,13 @@ def main():
parser.add_argument("database")
args = parser.parse_args()
#open the database
conn = openDatabase(args.database)
if conn == None:
sys.exit('database could not be opened, does it exist')
if args.type == 'dsw':
processDsw(args.inFile, args.database)
processDsw(args.inFile, conn)
else:
print('type not found or not entered')