div tzg
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>{{title}}</title>
|
||||
<script src="static/jquery-3.2.0.min.js" ></script>
|
||||
<link rel="stylesheet" href="static/bootstrap/css/bootstrap.min.css"/>
|
||||
<script src="static/bootstrap/js/bootstrap.min.js" ></script>
|
||||
<script src="/static/jquery-3.2.0.min.js" ></script>
|
||||
<link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css"/>
|
||||
<script src="/static/bootstrap/js/bootstrap.min.js" ></script>
|
||||
</head>
|
||||
<body>
|
||||
<style>
|
||||
.card.opened-True {
|
||||
.card.answ-1,.card.answ-True {
|
||||
background: lightgreen;
|
||||
}
|
||||
</style>
|
||||
@@ -19,19 +19,20 @@
|
||||
<div id="accordion" role="tablist" aria-multiselectable="true">
|
||||
|
||||
{% for m in mths %}
|
||||
<div class="card opened-{{m.opened}}" style="padding-top: 2pt; padding-bottom:2pt; border-radius:0;margin-top:1pt; margin-bottom:1pt">
|
||||
<div class="card answ-{{m.is_answered()}}" style="padding-top: 2pt; padding-bottom:2pt; border-radius:0;margin-top:1pt; margin-bottom:1pt">
|
||||
<div class="" role="tab" id="heading{{m.firstmail}}">
|
||||
<b class="mb-0">
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#collapse{{m.firstmail}}" aria-expanded="true" aria-controls="collapse1">
|
||||
{{m.tstr()}}
|
||||
{% if m.istrained %} trained: {% endif %} {{m.tstr()}}
|
||||
</a>
|
||||
</b>
|
||||
</div>
|
||||
|
||||
<div id="collapse{{m.firstmail}}" class="collapse" role="tabpanel" aria-labelledby="headingOne">
|
||||
<div id="collapse{{m.firstmail}}" class="collapse {{'show' if m.firstmail==opened}}" role="tabpanel" aria-labelledby="headingOne">
|
||||
|
||||
<div class="card-block">
|
||||
{{m.maintopic}}
|
||||
<div class="card-block">
|
||||
<a href="{{m.firstmail}}?key=answered&value={{(not m.is_answered())}}">answered:{{(not m.is_answered())}}</a>
|
||||
{{m.maintopic}}, {{ m.istrained }} <a href="{{m.firstmail}}?key=trained&value={{(not m.istrained)}}">trained:{{(not m.istrained)}}</a>
|
||||
<div style="white-space: pre-wrap;font:Courier, monospace; font-size:small; width:50em; border: thin blue solid;">
|
||||
{{ m.print_text() }}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user