|
|
@ -1,3 +1,4 @@ |
|
|
|
|
|
|
|
import os |
|
|
|
from flask import ( |
|
|
|
from flask import ( |
|
|
|
Blueprint, flash, g, redirect, render_template, request, url_for |
|
|
|
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.auth import login_required |
|
|
|
from app.db import get_db |
|
|
|
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__) |
|
|
|
bp = Blueprint('index', __name__) |
|
|
|
|
|
|
|
|
|
|
@ -21,3 +25,33 @@ def index(): |
|
|
|
return render_template('index.html', loginEvents = loginEvents) |
|
|
|
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> |
|
|
|
|
|
|
|
''' |