Commit 61a56285 authored by Hinrikus Wolf's avatar Hinrikus Wolf
Browse files

rename event to topic

parent 2a053b57
...@@ -4,3 +4,4 @@ test.db ...@@ -4,3 +4,4 @@ test.db
*.swp *.swp
config.py config.py
venv/ venv/
.spyderproject
...@@ -34,8 +34,8 @@ class User(db.Model, UserMixin): ...@@ -34,8 +34,8 @@ class User(db.Model, UserMixin):
) )
class Event(db.Model): class Topics(db.Model):
__tablename__ = "events" __tablename__ = "topics"
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, unique=True) name = db.Column(db.String, unique=True)
mode = db.Column(db.String) mode = db.Column(db.String)
...@@ -90,7 +90,8 @@ class Statement(db.Model): ...@@ -90,7 +90,8 @@ class Statement(db.Model):
return "<Statement(id={}, speaker={}, event={}, insertion_time={}, executed={}, execution_time={})>".format( return "<Statement(id={}, speaker={}, event={}, insertion_time={}, executed={}, execution_time={})>".format(
self.id, self.id,
self.speaker, self.speaker,
self.event, #self.event,
self.topic,
self.insertion_time, self.insertion_time,
self.executed, self.executed,
self.execution_time self.execution_time
......
...@@ -24,8 +24,8 @@ class AdminUserForm(Form): ...@@ -24,8 +24,8 @@ class AdminUserForm(Form):
class AddStatementForm(Form): class AddStatementForm(Form):
speaker_name = StringField("Speaker", validators=[InputRequired("Entering the speaker is required.")]) speaker_name = StringField("Speaker", validators=[InputRequired("Entering the speaker is required.")])
event = HiddenField("Event") topic = HiddenField("Topic")
class NewEventForm(Form): class NewTopicForm(Form):
name = StringField("Name", validators=[InputRequired("Entering the name is required.")]) name = StringField("Name", validators=[InputRequired("Entering the name is required.")])
mode = StringField("Mode", validators=[InputRequired("Entering the mode is required."), AnyOf(values=["balanced", "fifo"], message="Must be 'balanced' or 'fifo' atm.")]) mode = StringField("Mode", validators=[InputRequired("Entering the mode is required."), AnyOf(values=["balanced", "fifo"], message="Must be 'balanced' or 'fifo' atm.")])
...@@ -2,8 +2,8 @@ from flask import Blueprint, redirect, url_for, request, flash, abort, send_file ...@@ -2,8 +2,8 @@ from flask import Blueprint, redirect, url_for, request, flash, abort, send_file
from flask.ext.login import login_required from flask.ext.login import login_required
from passlib.hash import pbkdf2_sha256 from passlib.hash import pbkdf2_sha256
from models.database import User, Event from models.database import User, Topic
from models.forms import AdminUserForm, NewUserForm, NewEventForm from models.forms import AdminUserForm, NewUserForm, NewTopicForm
from shared import db, admin_permission, render_layout from shared import db, admin_permission, render_layout
...@@ -15,8 +15,8 @@ admin = Blueprint("admin", __name__) ...@@ -15,8 +15,8 @@ admin = Blueprint("admin", __name__)
@admin_permission.require() @admin_permission.require()
def index(): def index():
users = User.query.limit(10).all() users = User.query.limit(10).all()
events = Event.query.limit(10).all() topics = Topic.query.limit(10).all()
return render_layout("admin_index.html", users=users, events=events) return render_layout("admin_index.html", users=users, topics=topics)
@admin.route("/user/") @admin.route("/user/")
@login_required @login_required
...@@ -69,53 +69,53 @@ def user_new(): ...@@ -69,53 +69,53 @@ def user_new():
return render_layout("admin_user_new.html", form=form) return render_layout("admin_user_new.html", form=form)
@admin.route("/event/new", methods=["GET", "POST"]) @admin.route("/topic/new", methods=["GET", "POST"])
@login_required @login_required
@admin_permission.require() @admin_permission.require()
def event_new(): def topic_new():
form = NewEventForm() form = NewTopicForm()
if form.validate_on_submit(): if form.validate_on_submit():
if Event.query.filter_by(name=form.name.data).count() > 0: if Topic.query.filter_by(name=form.name.data).count() > 0:
flash("There already is an event with that name.", "alert-error") flash("There already is an topic with that name.", "alert-error")
return render_layout("admin_event_new.html", form=form) return render_layout("admin_topic_new.html", form=form)
event = Event(form.name.data, form.mode.data) topic = Topic(form.name.data, form.mode.data)
db.session.add(event) db.session.add(topic)
db.session.commit() db.session.commit()
return redirect(url_for(".event")) return redirect(url_for(".topic"))
return render_layout("admin_event_new.html", form=form) return render_layout("admin_topic_new.html", form=form)
@admin.route("/event/delete") @admin.route("/topic/delete")
@login_required @login_required
@admin_permission.require() @admin_permission.require()
def event_delete(): def topc_delete():
event_id = request.args.get("id", None) topic_id = request.args.get("id", None)
if event_id is not None: if topic_id is not None:
event = Event.query.filter_by(id=event_id).first() topic = Topic.query.filter_by(id=topic_id).first()
db.session.delete(event) db.session.delete(topic)
db.session.commit() db.session.commit()
flash("Event deleted.", "alert-success") flash("Topic deleted.", "alert-success")
return redirect(url_for(".event")) return redirect(url_for(".topic"))
@admin.route("/event/edit", methods=["GET", "POST"]) @admin.route("/topic/edit", methods=["GET", "POST"])
@login_required @login_required
@admin_permission.require() @admin_permission.require()
def event_edit(): def topic_edit():
event_id = request.args.get("id", None) topic_id = request.args.get("id", None)
if event_id is not None: if topic_id is not None:
event = db.session.query(Event).filter_by(id=event_id).first() topic = db.session.query(Topic).filter_by(id=topic_id).first()
form = NewEventForm(obj=event) form = NewTopicForm(obj=topic)
if form.validate_on_submit(): if form.validate_on_submit():
form.populate_obj(event) form.populate_obj(topic)
db.session.commit() db.session.commit()
return redirect(url_for(".index")) return redirect(url_for(".index"))
else: else:
return render_layout("admin_event_edit.html", form=form, id=event_id) return render_layout("admin_topic_edit.html", form=form, id=topic_id)
else: else:
return redirect(url_for(".index")) return redirect(url_for(".index"))
@admin.route("/event/") @admin.route("/topic/")
@login_required @login_required
@admin_permission.require() @admin_permission.require()
def event(): def topic():
events = Event.query.all() topics = Topic.query.all()
return render_layout("admin_event_index.html", events=events) return render_layout("admin_topic_index.html", topics=topics)
from flask import Blueprint, redirect, url_for, request, flash, abort, send_file, Response from flask import Blueprint, redirect, url_for, request, flash, abort, send_file, Response
from flask.ext.login import login_required from flask.ext.login import login_required
from models.database import User, Statement, Speaker, Event from models.database import User, Statement, Speaker, Topic
from models.forms import AddStatementForm from models.forms import AddStatementForm
from shared import db, admin_permission, user_permission, render_layout from shared import db, admin_permission, user_permission, render_layout
...@@ -13,9 +13,9 @@ import config ...@@ -13,9 +13,9 @@ import config
speech = Blueprint("speech", __name__) speech = Blueprint("speech", __name__)
def query_statements(mode, event_id): def query_statements(mode, topic_id):
statements = db.session.query(Statement).filter_by(event=event_id).all() statements = db.session.query(Statement).filter_by(topic=topic_id).all()
speakers = db.session.query(Speaker).filter_by(event=event_id).all() speakers = db.session.query(Speaker).filter_by(topic=topic_id).all()
if mode == "balanced" or mode == "pending": if mode == "balanced" or mode == "pending":
count = { speaker.id: 0 for speaker in speakers } count = { speaker.id: 0 for speaker in speakers }
for statement in statements: for statement in statements:
...@@ -40,46 +40,46 @@ def query_statements(mode, event_id): ...@@ -40,46 +40,46 @@ def query_statements(mode, event_id):
@speech.route("/index") @speech.route("/index")
def index(): def index():
event_id = request.args.get("event", None) topic_id = request.args.get("topic", None)
mode = request.args.get("mode", None) mode = request.args.get("mode", None)
meta = [] meta = []
if event_id is not None and event_id != "-1": if topic_id is not None and topic_id != "-1":
event = Event.query.filter_by(id=event_id).first() topic = Topic.query.filter_by(id=topic_id).first()
form = AddStatementForm() form = AddStatementForm()
form.event.data = event.id form.topic.data = topic.id
meta.append((query_statements(mode if mode is not None else event.mode, event_id), form, event)) meta.append((query_statements(mode if mode is not None else topic.mode, topic_id), form, topic))
else: else:
for event in Event.query.all(): for topic in Topic.query.all():
form = AddStatementForm() form = AddStatementForm()
form.event.data = event.id form.topic.data = topic.id
meta.append((query_statements(mode if mode is not None else event.mode, event.id), form, event)) meta.append((query_statements(mode if mode is not None else topic.mode, topic.id), form, topic))
event_id = -1 topic_id = -1
return render_layout("speech_index.html", meta=meta, event_id=event_id, mode=mode) return render_layout("speech_index.html", meta=meta, topic_id=topic_id, mode=mode)
@speech.route("/show") @speech.route("/show")
def show(): def show():
event_id = request.args.get("event", None) topic_id = request.args.get("topic", None)
mode = request.args.get("mode", None) mode = request.args.get("mode", None)
meta = [] meta = []
if event_id is not None and event_id is not "-1": if topic_id is not None and topic_id is not "-1":
event = Event.query.filter_by(id=event_id).first() topic = Topic.query.filter_by(id=topic_id).first()
meta.append((query_statements(mode if mode is not None else event.mode, event_id), event)) meta.append((query_statements(mode if mode is not None else topic.mode, topic_id), topic))
else: else:
for event in Event.query.all(): for topic in Topic.query.all():
meta.append((query_statements(mode if mode is not None else event.mode, event.id), event)) meta.append((query_statements(mode if mode is not None else topic.mode, topic.id), topic))
return render_layout("speech_show.html", mode=mode, meta=meta, event_id=event_id) return render_layout("speech_show.html", mode=mode, meta=meta, topic_id=topic_id)
@speech.route("/update") @speech.route("/update")
def update(): def update():
event_id = request.args.get("event", None) topic_id = request.args.get("topic", None)
mode = request.args.get("mode", None) mode = request.args.get("mode", None)
meta = [] meta = []
if event_id is not None and event_id != "-1": if topic_id is not None and topic_id != "-1":
event = Event.query.filter_by(id=event_id).first() topic = Topic.query.filter_by(id=topic_id).first()
meta.append((query_statements(mode if mode is not None else event.mode, event_id), event)) meta.append((query_statements(mode if mode is not None else topic.mode, topic_id), topic))
else: else:
for event in Event.query.all(): for topic in Topic.query.all():
meta.append((query_statements(mode if mode is not None else event.mode, event.id), event)) meta.append((query_statements(mode if mode is not None else topic.mode, topic.id), topic))
return render_layout("speech_content_show.html", mode=mode, meta=meta) return render_layout("speech_content_show.html", mode=mode, meta=meta)
...@@ -90,31 +90,31 @@ def add(): ...@@ -90,31 +90,31 @@ def add():
add_form = AddStatementForm() add_form = AddStatementForm()
if add_form.validate_on_submit(): if add_form.validate_on_submit():
speaker_name = add_form["speaker_name"].data speaker_name = add_form["speaker_name"].data
event_id = add_form["event"].data topic_id = add_form["topic"].data
if speaker_name is None or event_id is None: if speaker_name is None or topic_id is None:
flash("Missing data", "alert-error") flash("Missing data", "alert-error")
return redirect(url_for(".index")) return redirect(url_for(".index"))
speaker = Speaker.query.filter_by(name=speaker_name).filter_by(event=event_id).first() speaker = Speaker.query.filter_by(name=speaker_name).filter_by(topic=topic_id).first()
if not speaker: if not speaker:
speaker = Speaker(speaker_name, event_id) speaker = Speaker(speaker_name, topic_id)
db.session.add(speaker) db.session.add(speaker)
db.session.commit() db.session.commit()
if Statement.query.filter_by(speaker=speaker.id).filter_by(event=event_id).filter_by(executed=False).count() > 0: if Statement.query.filter_by(speaker=speaker.id).filter_by(topic=topic_id).filter_by(executed=False).count() > 0:
flash("Speaker already listet", "alert-error") flash("Speaker already listet", "alert-error")
return redirect(url_for(request.args.get("next") or ".show")) return redirect(url_for(request.args.get("next") or ".show"))
statement = Statement(speaker.id, event_id) statement = Statement(speaker.id, topic_id)
db.session.add(statement) db.session.add(statement)
db.session.commit() db.session.commit()
mode = request.args.get("mode", None) mode = request.args.get("mode", None)
event_id = request.args.get("event", None) topic_id = request.args.get("topic", None)
return redirect(url_for(request.args.get("next") or ".index", mode=mode, event=event_id)) return redirect(url_for(request.args.get("next") or ".index", mode=mode, topic=topic_id))
@speech.route("/cancel") @speech.route("/cancel")
@user_permission.require() @user_permission.require()
def cancel(): def cancel():
statement_id = request.args.get("statement", None) statement_id = request.args.get("statement", None)
event_id = request.args.get("event", -1) topic_id = request.args.get("topic", -1)
if not statement_id: if not statement_id:
flash("Missing statement id", "alert-error") flash("Missing statement id", "alert-error")
return redirect(url_for(request.args.get("next") or ".index")) return redirect(url_for(request.args.get("next") or ".index"))
...@@ -123,13 +123,13 @@ def cancel(): ...@@ -123,13 +123,13 @@ def cancel():
db.session.commit() db.session.commit()
flash("Statement canceled", "alert-success") flash("Statement canceled", "alert-success")
mode = request.args.get("mode", None) mode = request.args.get("mode", None)
return redirect(url_for(request.args.get("next") or ".index", mode=mode, event=event_id)) return redirect(url_for(request.args.get("next") or ".index", mode=mode, topic=topic_id))
@speech.route("/done") @speech.route("/done")
@user_permission.require() @user_permission.require()
def done(): def done():
statement_id = request.args.get("statement", None) statement_id = request.args.get("statement", None)
event_id = request.args.get("event", -1) topic_id = request.args.get("topic", -1)
if not statement_id: if not statement_id:
flash("Missing statement id", "alert-error") flash("Missing statement id", "alert-error")
return redirect(url_for(request.args.get("next") or ".index")) return redirect(url_for(request.args.get("next") or ".index"))
...@@ -139,14 +139,14 @@ def done(): ...@@ -139,14 +139,14 @@ def done():
else: else:
flash("Statement already done", "alert-error") flash("Statement already done", "alert-error")
mode = request.args.get("mode", None) mode = request.args.get("mode", None)
return redirect(url_for(request.args.get("next") or ".index", mode=mode, event=event_id)) return redirect(url_for(request.args.get("next") or ".index", mode=mode, topic=topic_id))
@speech.route("/update_show.js") @speech.route("/update_show.js")
def update_show_js(): def update_show_js():
update_interval = config.UPDATE_SHOW_INTERVAL or 1 update_interval = config.UPDATE_SHOW_INTERVAL or 1
div = "rede-content-div" div = "rede-content-div"
mode = request.args.get("mode", None) mode = request.args.get("mode", None)
event_id = request.args.get("event", -1) topic_id = request.args.get("topic", -1)
target_url = url_for(".update", mode=mode, event=event_id) target_url = url_for(".update", mode=mode, topic=topic_id)
return render_layout("update.js", update_interval=update_interval, div=div, target_url=target_url, prefix="update_show_") return render_layout("update.js", update_interval=update_interval, div=div, target_url=target_url, prefix="update_show_")
...@@ -10,7 +10,7 @@ from passlib.hash import pbkdf2_sha256 ...@@ -10,7 +10,7 @@ from passlib.hash import pbkdf2_sha256
import config import config
from shared import db, login_manager, render_layout from shared import db, login_manager, render_layout
from models.forms import LoginForm, NewUserForm from models.forms import LoginForm, NewUserForm
from models.database import User, Statement, Speaker, Event from models.database import User, Statement, Speaker, Toic
app = Flask(__name__) app = Flask(__name__)
app.config.from_object(config) app.config.from_object(config)
...@@ -38,24 +38,24 @@ def index(): ...@@ -38,24 +38,24 @@ def index():
user = User(fullname, username, password, ["admin", "user"]) user = User(fullname, username, password, ["admin", "user"])
db.session.add(user) db.session.add(user)
db.session.commit() db.session.commit()
events = Event.query.all() topics = Topic.query.all()
meta = [] meta = []
for event in events: for topic in topics:
ls = speech.query_statements(event.mode, event.id) ls = speech.query_statements(topic.mode, topic.id)
no_speaker = Speaker("No Speaker", event) no_speaker = Speaker("No Speaker", topic)
no_statement = Statement(no_speaker, event) no_statement = Statement(no_speaker, topic)
meta.append((ls[0] if len(ls) > 0 else (no_statement, no_speaker, ()), event)) meta.append((ls[0] if len(ls) > 0 else (no_statement, no_speaker, ()), topic))
return render_layout("index.html", meta=meta) return render_layout("index.html", meta=meta)
@app.route("/update") @app.route("/update")
def update(): def update():
events = Event.query.all() topics = Topic.query.all()
meta = [] meta = []
for event in events: for topic in topics:
ls = speech.query_statements(event.mode, event.id) ls = speech.query_statements(topic.mode, topic.id)
no_speaker = Speaker("No Speaker", event) no_speaker = Speaker("No Speaker", topic)
no_statement = Statement(no_speaker, event) no_statement = Statement(no_speaker, topic)
meta.append((ls[0] if len(ls) > 0 else (no_statement, no_speaker, ()), event)) meta.append((ls[0] if len(ls) > 0 else (no_statement, no_speaker, ()), topic))
return render_layout("content_index.html", meta=meta) return render_layout("content_index.html", meta=meta)
@app.route("/update.js") @app.route("/update.js")
......
...@@ -36,17 +36,17 @@ ...@@ -36,17 +36,17 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for event in events %} {% for topic in events %}
<tr> <tr>
<td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".event_edit", id=event.id) }}">{{ event.name }}</a></td> <td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".topic_edit", id=event.id) }}">{{ event.name }}</a></td>
<td class="mdl-data-table__cell--non-numeric">{{ event.mode }}</td> <td class="mdl-data-table__cell--non-numeric">{{ topic.mode }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<div class="mdl-cell mdl-cell--3-col mdl-cell--3-col-tablet mdl-cell--2-col-phone"> <div class="mdl-cell mdl-cell--3-col mdl-cell--3-col-tablet mdl-cell--2-col-phone">
<a class="mdl-button mdl-button--colored mdl-js-button" href="{{ url_for(".event") }}"> <a class="mdl-button mdl-button--colored mdl-js-button" href="{{ url_for(".topic") }}">
All events All topics
</a> </a>
</div> </div>
</div> </div>
......
{% extends "layout.html" %} {% extends "layout.html" %}
{% from "macros.html" import render_form %} {% from "macros.html" import render_form %}
{% block title %}Edit Event - Administration{% endblock %} {% block title %}Edit Topic - Administration{% endblock %}
{% block content %} {% block content %}
{{ render_form(form, action_url=url_for(".event_edit", id=id), action_text="Apply", title="Edit Event") }} {{ render_form(form, action_url=url_for(".topic_edit", id=id), action_text="Apply", title="Edit Topic") }}
{% endblock %} {% endblock %}
{% extends "admin_index.html" %} {% extends "admin_index.html" %}
{% block admin_title %}Events{% endblock %} {% block admin_title %}Topics{% endblock %}
{% block content %} {% block content %}
<div class="mdl-cell mdl-cell--3-col mdl-grid mdl-grid--no-spacing"> <div class="mdl-cell mdl-cell--3-col mdl-grid mdl-grid--no-spacing">
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for event in events %} {% for topic in events %}
<tr> <tr>
<td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".event_edit", id=event.id) }}">{{ event.name }}</a></td> <td class="mdl-data-table__cell--non-numeric"><a href="{{ url_for(".topic_edit", id=event.id) }}">{{ event.name }}</a></td>
<td class="mdl-data-table__cell--non-numeric">{{ event.mode }}</td> <td class="mdl-data-table__cell--non-numeric">{{ topic.mode }}</td>
<td class="mdl-data-table__cell--non-numeric"> <td class="mdl-data-table__cell--non-numeric">
<a href="{{ url_for('.event_delete', id=event.id) }}"> <a href="{{ url_for('.topic_delete', id=event.id) }}">
<i class="material-icons">delete</i> <i class="material-icons">delete</i>
</a> </a>
</td> </td>
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
</table> </table>
<div class="rede-separator"> <div class="rede-separator">
<div class="mdl-cell mdl-cell--1-col"> <div class="mdl-cell mdl-cell--1-col">
<a class="mdl-button mdl-button--colored mdl-js-button mdl-button--fab mdl-js-ripple-effect" href="{{ url_for('.event_new') }}"> <a class="mdl-button mdl-button--colored mdl-js-button mdl-button--fab mdl-js-ripple-effect" href="{{ url_for('.topic_new') }}">
<i class="material-icons">add</i> <i class="material-icons">add</i>
</a> </a>
</div> </div>
......
{% extends "layout.html" %} {% extends "layout.html" %}
{% from "macros.html" import render_form %} {% from "macros.html" import render_form %}
{% block title %}Add Event - Administration{% endblock %} {% block title %}Add Topic - Administration{% endblock %}
{% block content %} {% block content %}
{{ render_form(form, action_url=url_for(".event_new", id=id), action_text="Add", title="Create Event") }} {{ render_form(form, action_url=url_for(".topic_new", id=id), action_text="Add", title="Create Topic") }}
{% endblock %} {% endblock %}
{% for (statement, speaker, count), event in meta %} {% for (statement, speaker, count), topic in meta %}
<div class="mdl-color--white mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--4-col-tablet mdl-cell--4-col-phone mdl-card"> <div class="mdl-color--white mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--4-col-tablet mdl-cell--4-col-phone mdl-card">
<div class="mdl-card__title"> <div class="mdl-card__title">
<h3 class="mdl-card__title-text">{{ event.name }}: {{ speaker.name }}</h3> <h3 class="mdl-card__title-text">{{ topic.name }}: {{ speaker.name }}</h3>
</div> </div>
<div class="mdl-card__actions"> <div class="mdl-card__actions">
{% if current_user.is_authenticated() and "user" in current_user.roles %} {% if current_user.is_authenticated() and "user" in current_user.roles %}
<a href="{{ url_for("speech.index", event=event.id) }}"> <a href="{{ url_for("speech.index", topic=event.id) }}">