From 79788b3590aba6384611a2c29012bbd821c290ee Mon Sep 17 00:00:00 2001 From: Nico Geyso Date: Sun, 7 Dec 2014 18:25:29 +0100 Subject: Added write functionality to Storage backend --- app/main.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'app/main.py') diff --git a/app/main.py b/app/main.py index cdc8d0b..cf6a99e 100644 --- a/app/main.py +++ b/app/main.py @@ -6,8 +6,10 @@ from flask import Blueprint, render_template, request, flash, redirect,\ from werkzeug import secure_filename from .forms import UploadForm + main = Blueprint('main', __name__) + @main.route('//upload/', methods=['GET', 'POST']) @main.route('//upload/', methods=['GET', 'POST']) def upload(study, module = None): @@ -31,16 +33,15 @@ def upload(study, module = None): year = form.year.data filename = secure_filename(form.exam.data.filename) - path = os.path.join(module,year,filename) - try: - oid = g.studies[study].add_file(form.exam.data.stream.getvalue(), path) + data = form.exam.data.stream.getvalue() except: - oid = g.studies[study].add_file(form.exam.data.stream.read(), path) + data = form.exam.data.stream.read() + g.studies[study].add_file(module, year, filename, data) flash("Datei %s gespeichert." % filename) - return redirect(url_for('study_index', study = study, module = module)) + return redirect(url_for('.study_index', study = study, module = module)) try: form.module.data = [k for (k,v) in form.module.choices if v == module][0] except: pass -- cgit v1.2.3-1-g7c22