summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Geyso <nico.geyso@fu-berlin.de>2014-12-07 18:25:29 +0100
committerNico Geyso <nico.geyso@fu-berlin.de>2014-12-07 18:25:29 +0100
commit79788b3590aba6384611a2c29012bbd821c290ee (patch)
tree183dcc14c9bc5394c32bb664d1361d783860ceb0
parent4ea12c4b97fc7775ab5ae3cb4607f715b880aede (diff)
downloadklausuren-79788b3590aba6384611a2c29012bbd821c290ee.tar.gz
klausuren-79788b3590aba6384611a2c29012bbd821c290ee.tar.bz2
klausuren-79788b3590aba6384611a2c29012bbd821c290ee.zip
Added write functionality to Storage backend
-rw-r--r--README36
-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
6 files changed, 29 insertions, 39 deletions
diff --git a/README b/README
index 359b573..83a0b9c 100644
--- a/README
+++ b/README
@@ -1,21 +1,18 @@
-Fit
-===
+Klausurenarchiv
+===============
-Fit ist das Klausurenarchiv von Spline an der Freien Universität Berlin.
-Jegliche Daten werden in einem Git-Repository (vom Typ 'bare') verwaltet.
Klausuren können über ein Webinterface einfach hoch- und heruntergezuladen
-werden. Fit ist in Python2 mit Hilfe von Flask und pygit2 geschrieben.
+werden. Fit ist in Python2 mit Hilfe von Flask geschrieben.
Setup
-------
- $ git clone .../fit.git # Source-Code herunterladen
- $ cd fit
- $ cp settings.py.sample settings.py # Konfigurationsdatei erstellen
- $ nano settings.py
- $ pip install -r requirements.txt # Abhängikeiten installieren
- $ export LD_LIBRARY_PATH=/usr/local/lib/ # libgit2.so zum LD Path hinzufügen
- $ python app.py # Test-Server starten
+ $ git clone git://git.spline.de/klausurenarchiv # Source-Code herunterladen
+ $ cd klausurenarchiv
+ $ cp config.cfg.dist config.cfg # Konfigurationsdatei erstellen
+ $ vim/emacs/nano config.cfg
+ $ pip install -r requirements.txt # Abhängikeiten installieren
+ $ python manage.py runserver # Test-Server starten
Config
@@ -39,19 +36,6 @@ das Klausurenarchiv mit Hilfe von uwsgi gestartet werden:
$ LD_LIBRARY_PATH=/usr/local/lib/ uwsgi -s /tmp/uwsgi.sock -w app:app &
$ chmod 777 /tmp/uwsgi.sock
-Damit die Zip- und Tar-Gz-Archive korrekt erstellt werden, sollten noch Cronjobs
-für jeden Studiengang eingerichtet werden:
-
-$ cronjob -e
-0 * * * * cd INSTALL_PATH/static/studies/informatik.git && /usr/bin/git archive -o ../informatik.zip HEAD
-
-
Munin
-----
-Für das Munin-Plugin sollte unter /etc/munin/plugins folgendes Skript hinterlegt
-werden:
-
- #!/bin/bash
-
- cd INSTALL_PATH
- LD_LIBRARY_PATH=/usr/local/lib/ python munin.py $1
+to add
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) }}