speech.py 1.67 KB
Newer Older
1
from flask import Blueprint, redirect, url_for, request, flash, abort, send_file, Response
YSelf Tool's avatar
YSelf Tool committed
2 3
from flask.ext.login import login_required

Robin Sonnabend's avatar
Robin Sonnabend committed
4
from models.database import User, Statement, Speaker, Topic, Event
YSelf Tool's avatar
YSelf Tool committed
5 6
from models.forms import AddStatementForm

7 8
from shared import db, admin_permission, user_permission
from utils import render_layout
YSelf Tool's avatar
YSelf Tool committed
9 10 11 12

from datetime import datetime
import json

13 14
import config

YSelf Tool's avatar
YSelf Tool committed
15 16 17
speech = Blueprint("speech", __name__)


Robin Sonnabend's avatar
Robin Sonnabend committed
18
@speech.route("/")
YSelf Tool's avatar
YSelf Tool committed
19
def index():
Robin Sonnabend's avatar
Robin Sonnabend committed
20 21 22 23 24 25
    event_id = request.args.get("event", None)
    events = []
    if event_id is not None and event_id.isnumeric() and int(event_id) > -1:
        event = Event.query.filter_by(id=event_id).first()
        if event is not None:
            events.append(event)
YSelf Tool's avatar
YSelf Tool committed
26
    else:
Robin Sonnabend's avatar
Robin Sonnabend committed
27 28
        events = Event.query.all()
    return render_layout("speech_index.html", events=events, event=-1 if len(events) != 1 else events[0].id)
YSelf Tool's avatar
YSelf Tool committed
29 30 31

@speech.route("/update")
def update():
Robin Sonnabend's avatar
Robin Sonnabend committed
32 33 34 35 36 37
    event_id = request.args.get("event", None)
    events = []
    if event_id is not None and event_id.isnumeric() and int(event_id) > -1:
        event = Event.query.filter_by(id=event_id).first()
        if event is not None:
            events.append(event)
YSelf Tool's avatar
YSelf Tool committed
38
    else:
Robin Sonnabend's avatar
Robin Sonnabend committed
39 40
        events = Event.query.all()
    return render_layout("speech_content_index.html", events=events)
YSelf Tool's avatar
YSelf Tool committed
41

Robin Sonnabend's avatar
Robin Sonnabend committed
42 43 44
@speech.route("/update_index.js")
def update_index_js():
    update_interval = config.UPDATE_INDEX_INTERVAL or 1
45
    div = "rede-content-div"
46
    mode = request.args.get("mode", None)
Robin Sonnabend's avatar
Robin Sonnabend committed
47 48 49
    event_id = request.args.get("event", -1)
    target_url = url_for(".update", event=event_id)
    return render_layout("update.js", update_interval=update_interval, div=div, target_url=target_url, prefix="update_index_")
YSelf Tool's avatar
YSelf Tool committed
50