This commit is contained in:
andis
2017-08-11 20:34:17 +02:00
parent 51acbfbd38
commit 81fa9cc575
10 changed files with 202 additions and 79 deletions

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import flask
from flask import Flask,jsonify,send_from_directory, render_template
from flask import Flask,jsonify,send_from_directory, render_template, request,redirect,url_for
from config import Config
import yaml
import os
@@ -14,12 +14,12 @@ package_directory = os.path.dirname(os.path.abspath(__file__))
cfg = Config(file(os.path.join(package_directory, 'config.cfg')))
def render_index(mths,code=200):
def render_index(mths,opened=None,code=200):
return render_template("index.html",mths=mths,
title=cfg.title.decode("utf8"),
title=cfg.title.decode("utf8"),opened=opened
), code
from classifier import get_pipe
mail_threads=db_session.query(MailThread).all()
#mail_threads=db_session.query(MailThread).all()
#pipe1,le=get_pipe("pipe1",b"answered")
#pipe2,le2=get_pipe("pipe2b", b"maintopic")
#pipe3,le3=get_pipe("pipe2b", b"lang")
@@ -33,28 +33,62 @@ mail_threads=db_session.query(MailThread).all()
# t.maintopic=maintopic[i]
# t.lang=lang[i]
maintopic_values=["studium", "information","ausleihen"]
@app.route("/")
def hello():
mth=db_session.query(MailThread).order_by(desc(MailThread.date)).all()
return render_index(mth)
@app.route("/answered/<id>/<value>")
def store_answered(id, value):
def store_value(id,key,value):
mth=db_session.query(MailThread).filter(MailThread.firstmail==int(id)).first()
value= value in ["true", "True", "1", "t"]
mth.answered=bool(value)
mth.opened=bool(value)
return render_index([mth])
if key =="answered":
value = value in ["true", "True", "1", "t"]
mth.answered=bool(value)
mth.opened=bool(value)
if key=="maintopic" and value in maintopic_values:
mth.maintopic=str(value)
if key =="trained":
value = value in ["true", "True", "1", "t"]
mth.istrained=bool(value)
@app.route("/<int:id>")
def store_answered(id):
key = request.args.get('key')
value = request.args.get('value')
if not key is None and not value is None:
store_value(id,key,value)
return render_index([mth], opened=id)
@app.route("/studium")
@app.route("/studium/")
def studium():
mth=db_session.query(MailThread).filter(MailThread.maintopic=="studium").order_by(desc(MailThread.date)).all()
return render_index(mth)
@app.route("/<maintopic>")
@app.route("/<maintopic>/")
def maintopic(maintopic):
mth=db_session.query(MailThread).filter(MailThread.maintopic=="%s" % maintopic).order_by(desc(MailThread.date)).all()
return render_index(mth)
@app.route("/<maintopic>/<int:id>")
def maintopic_store(maintopic,id):
if maintopic == "trained":
mth=db_session.query(MailThread).filter(MailThread.istrained==True).order_by(desc(MailThread.date)).all()
else:
mth=db_session.query(MailThread).filter(MailThread.maintopic=="%s" % maintopic).order_by(desc(MailThread.date)).all()
key = request.args.get('key')
value = request.args.get('value')
if not key is None and not value is None:
store_value(id,key,value)
return redirect(url_for('maintopic_store', id=id, maintopic=maintopic), 302)
else:
return render_index(mth,opened=id)