Browse Source

Upload Implementation

master
Eddie 2 years ago
parent
commit
fe6914597c
  1. 1
      .gitignore
  2. 7
      README.md
  3. 1
      app/__init__.py
  4. 34
      app/index.py
  5. 9
      app/schema.sql
  6. 4
      app/templates/base.html
  7. 0
      app/uploads/init.txt

1
.gitignore vendored

@ -152,3 +152,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
uploads/*.md

7
README.md

@ -1,3 +1,8 @@
# flask_boilerplate
Kleines Startsetup für eine Flask Webapp mit Login und Datenbank
Kleines Startsetup für eine Flask Webapp mit Login und Datenbank
Befehle
flask --app app run
flask --app app init-db

1
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:

34
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 '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
'''

9
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
);

4
app/templates/base.html

@ -1,8 +1,8 @@
<!doctype html>
<title>{% block title %}{% endblock %} - Flaskr</title>
<title>{% block title %}{% endblock %} - Markdown Presenter</title>
<link rel="stylesheet" href="{{ url_for('static', filename='bootstrap.css') }}">
<nav>
<h1>Flaskr</h1>
<h1>Eddsons Markdown Presenter</h1>
<ul>
{% if g.user %}
<li><span>{{ g.user['username'] }}</span>

0
app/uploads/init.txt

Loading…
Cancel
Save