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 --- README | 36 ++++++++++-------------------------- app/backend.py | 11 ++++++++--- app/main.py | 11 ++++++----- app/templates/layout.html | 6 +++--- app/templates/module_list.html | 2 +- app/templates/upload.html | 2 +- 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('//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 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 @@

{% if not request.base_url.endswith(url_for('.upload', study=study, module = module))%} {% if not request.base_url.endswith(url_for('errorhandler')) %} - neue Klausur hochladen + neue Klausur hochladen {% endif %} {% else %} - zurück + zurück {% endif %}

-

{{study.capitalize()}}

+

{{study.capitalize()}}

{% endif %}
    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 @@
      {% for module in modules %}
    • - {{module}} + {{module}}
    • {% else %}
    • Keine Klausuren bisher hochgeladen!
    • 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 @@
      + action="{{url_for('.upload', study=study, module=module)}}"> {{ form.csrf_token }} {{ render_field(form.exam) }} -- cgit v1.2.3-1-g7c22