diff --git a/app/db.py b/app/db.py index 74dea73..a41bfe5 100644 --- a/app/db.py +++ b/app/db.py @@ -29,6 +29,7 @@ def init_db(): db.executescript(f.read().decode('utf8')) + @click.command('init-db') @with_appcontext def init_db_command(): diff --git a/app/index.py b/app/index.py index 16311b3..f3a7a99 100644 --- a/app/index.py +++ b/app/index.py @@ -1,6 +1,6 @@ -import os +import os, uuid from flask import ( - Blueprint, flash, g, redirect, render_template, request, url_for + Blueprint, flash, g, redirect, render_template, request, url_for, session ) from werkzeug.exceptions import abort @@ -17,12 +17,7 @@ bp = Blueprint('index', __name__) @login_required def index(): db = get_db() - loginEvents = db.execute( - 'SELECT *' - ' FROM loginEvent' - ' ORDER BY created DESC' - ).fetchall() - return render_template('index.html', loginEvents = loginEvents) + return render_template('index.html') def allowed_file(filename): @@ -30,6 +25,7 @@ def allowed_file(filename): filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS @bp.route('/upload', methods=['GET', 'POST']) +@login_required def upload_file(): if request.method == 'POST': # check if the post request has the file part @@ -44,7 +40,11 @@ def upload_file(): return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) - file.save(os.path.join(UPLOAD_FOLDER, filename)) + path = os.path.join(UPLOAD_FOLDER, filename) + file.save(path) + createMarkdownEntry(path) + os.remove(path) + return redirect(url_for('index')) return ''' @@ -54,4 +54,21 @@ def upload_file(): - ''' \ No newline at end of file + ''' + + +def createMarkdownEntry(path): + db = get_db() + title = os.path.basename(path) + title = title.split('.') + file = open(path) + data = file.read() + file.close() + uniqueID = str(uuid.uuid4()) + qrCode = 'QR' + db.execute( + 'INSERT INTO markdownFile (title, body, qrCode, uuid, creator) VALUES (?, ?, ?, ?, ?)', + (title[0], data, qrCode, uniqueID, session['user_id']) + ) + db.commit() + return \ No newline at end of file diff --git a/app/schema.sql b/app/schema.sql index af0b4a6..c1435a1 100644 --- a/app/schema.sql +++ b/app/schema.sql @@ -7,10 +7,11 @@ CREATE TABLE user ( password TEXT NOT NULL ); -CREATE TABLE MarkdownFile ( +CREATE TABLE markdownFile ( id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, body TEXT NOT NULL, qrCode TEXT NOT NULL, - uuid TEXT NOT NULL + uuid TEXT NOT NULL, + creator INTEGER NOT NULL ); \ No newline at end of file