summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/backend.py11
-rw-r--r--app/main.py11
-rw-r--r--app/templates/layout.html6
-rw-r--r--app/templates/module_list.html2
-rw-r--r--app/templates/upload.html2
5 files changed, 19 insertions, 13 deletions
diff --git a/app/backend.py b/app/backend.py
index 25a5506..6c59edd 100644
--- a/app/backend.py
+++ b/app/backend.py
@@ -28,7 +28,12 @@ class Storage:
year = splitted[-1]
module = splitted[-2]
if year.isdigit():
- yield((year, files))#, os.path.join(root,f))
+ yield (year, files)
- def add_file(self, data, path):
- pass
+ def add_file(self, module, year, filename, data):
+ dir_name = self._join(module, year)
+ if not os.path.exists(dir_name):
+ os.makedirs(dir_name)
+ path = self._join(module, year, filename)
+ with open(path, 'wb') as f:
+ f.write(data)
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('/<study>/upload/', methods=['GET', 'POST'])
@main.route('/<study>/upload/<module>', 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
diff --git a/app/templates/layout.html b/app/templates/layout.html
index 06901e9..14ec7c5 100644
--- a/app/templates/layout.html
+++ b/app/templates/layout.html
@@ -19,13 +19,13 @@
<p>
{% if not request.base_url.endswith(url_for('.upload', study=study, module = module))%}
{% if not request.base_url.endswith(url_for('errorhandler')) %}
- <a href="{{url_for('main.upload', study=study, module=module)}}">neue Klausur hochladen</a>
+ <a href="{{url_for('.upload', study=study, module=module)}}">neue Klausur hochladen</a>
{% endif %}
{% else %}
- <a href="{{url_for('main.study_index', study=study, module=module)}}">zurück</a>
+ <a href="{{url_for('.study_index', study=study, module=module)}}">zurück</a>
{% endif %}
</p>
- <h2><a href="{{url_for('main.study_index', study=study)}}">{{study.capitalize()}}</a></h2>
+ <h2><a href="{{url_for('.study_index', study=study)}}">{{study.capitalize()}}</a></h2>
{% endif %}
<ul class="flashes">
diff --git a/app/templates/module_list.html b/app/templates/module_list.html
index 9e1409c..9469020 100644
--- a/app/templates/module_list.html
+++ b/app/templates/module_list.html
@@ -5,7 +5,7 @@
<ul>
{% for module in modules %}
<li>
- <a href="{{url_for('main.study_index', study = study, module=module)}}">{{module}}</a>
+ <a href="{{url_for('.study_index', study = study, module=module)}}">{{module}}</a>
</li>
{% else %}
<li>Keine Klausuren bisher hochgeladen!</li>
diff --git a/app/templates/upload.html b/app/templates/upload.html
index 67c47ea..0e00354 100644
--- a/app/templates/upload.html
+++ b/app/templates/upload.html
@@ -26,7 +26,7 @@
<div id="upload">
<form method="POST" enctype="multipart/form-data"
- action="{{url_for('main.upload', study=study, module=module)}}">
+ action="{{url_for('.upload', study=study, module=module)}}">
{{ form.csrf_token }}
{{ render_field(form.exam) }}