'''

@author: olivier.massot, sept 218
'''
from flask import request
from flask.app import Flask
from jinja2.environment import Template
from path import Path
from werkzeug.utils import secure_filename
from tempfile import TemporaryDirectory


main_dir = Path(__file__).parent.parent

app = Flask(__name__)

@app.route('/', methods=['GET'])
def index():
    with open("templates\\index.j2", "r", encoding="utf-8") as f:
        template = Template(f.read())
    return template.render()

@app.route('/', methods=['POST'])
def submit():
    f = request.files['dossier']
#     with TemporaryDirectory() as tmpdir:
    f.save("upload/" + secure_filename(f.filename))
        
    return f.filename

@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        f = request.files['the_file']
        f.save('uploads/' + secure_filename(f.filename))