From fe6914597c1a4fa115a9a3e1fc665b7ed543a282 Mon Sep 17 00:00:00 2001 From: Eddie Date: Fri, 6 Jan 2023 16:38:26 +0100 Subject: [PATCH] Upload Implementation --- .gitignore | 1 + README.md | 7 ++++++- app/__init__.py | 1 + app/index.py | 34 ++++++++++++++++++++++++++++++++++ app/schema.sql | 9 +++++---- app/templates/base.html | 4 ++-- app/uploads/init.txt | 0 7 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 app/uploads/init.txt diff --git a/.gitignore b/.gitignore index 55be276..8b685c4 100644 --- a/.gitignore +++ b/.gitignore @@ -152,3 +152,4 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +uploads/*.md \ No newline at end of file diff --git a/README.md b/README.md index ee48a62..e374f19 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ # flask_boilerplate -Kleines Startsetup für eine Flask Webapp mit Login und Datenbank \ No newline at end of file +Kleines Startsetup für eine Flask Webapp mit Login und Datenbank + +Befehle + +flask --app app run +flask --app app init-db \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py index aa05365..c297afc 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -9,6 +9,7 @@ def create_app(test_config=None): app.config.from_mapping( SECRET_KEY='dev', DATABASE=os.path.join(app.instance_path, 'app.sqlite'), + ) if test_config is None: diff --git a/app/index.py b/app/index.py index d27b54d..16311b3 100644 --- a/app/index.py +++ b/app/index.py @@ -1,3 +1,4 @@ +import os from flask import ( Blueprint, flash, g, redirect, render_template, request, url_for ) @@ -5,7 +6,10 @@ from werkzeug.exceptions import abort from app.auth import login_required from app.db import get_db +from werkzeug.utils import secure_filename +ALLOWED_EXTENSIONS = {'md'} +UPLOAD_FOLDER = os.getcwd() + '/app/uploads' bp = Blueprint('index', __name__) @@ -21,3 +25,33 @@ def index(): return render_template('index.html', loginEvents = loginEvents) +def allowed_file(filename): + return '.' in filename and \ + filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS + +@bp.route('/upload', methods=['GET', 'POST']) +def upload_file(): + if request.method == 'POST': + # check if the post request has the file part + if 'file' not in request.files: + flash('No file part') + return redirect(request.url) + file = request.files['file'] + # If the user does not select a file, the browser submits an + # empty file without a filename. + if file.filename == '': + 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(UPLOAD_FOLDER, filename)) + return redirect(url_for('index')) + return ''' + + Upload new File +

Upload new File

+
+ + +
+ ''' \ No newline at end of file diff --git a/app/schema.sql b/app/schema.sql index 82cc351..af0b4a6 100644 --- a/app/schema.sql +++ b/app/schema.sql @@ -7,9 +7,10 @@ CREATE TABLE user ( password TEXT NOT NULL ); -CREATE TABLE loginEvent ( +CREATE TABLE MarkdownFile ( id INTEGER PRIMARY KEY AUTOINCREMENT, - walletId TEXT NOT NULL, - created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - eventType TEXT NOT NULL + title TEXT NOT NULL, + body TEXT NOT NULL, + qrCode TEXT NOT NULL, + uuid TEXT NOT NULL ); \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html index a258ef6..f7d66de 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -1,8 +1,8 @@ -{% block title %}{% endblock %} - Flaskr +{% block title %}{% endblock %} - Markdown Presenter