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

rename event to topic

parent 2a053b57
......@@ -4,3 +4,4 @@ test.db
*.swp
config.py
venv/
.spyderproject
......@@ -34,8 +34,8 @@ class User(db.Model, UserMixin):
)
class Event(db.Model):
__tablename__ = "events"
class Topics(db.Model):
__tablename__ = "topics"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, unique=True)
mode = db.Column(db.String)
......@@ -90,7 +90,8 @@ class Statement(db.Model):
return "<Statement(id={}, speaker={}, event={}, insertion_time={}, executed={}, execution_time={})>".format(
self.id,
self.speaker,
self.event,
#self.event,
self.topic,
self.insertion_time,
self.executed,
self.execution_time
......
......@@ -24,8 +24,8 @@ class AdminUserForm(Form):
class AddStatementForm(Form):
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.")])
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
from flask.ext.login import login_required
from passlib.hash import pbkdf2_sha256
from models.database import User, Event
from models.forms import AdminUserForm, NewUserForm, NewEventForm
from models.database import User, Topic
from models.forms import AdminUserForm, NewUserForm, NewTopicForm
from shared import db, admin_permission, render_layout
......@@ -15,8 +15,8 @@ admin = Blueprint("admin", __name__)
@admin_permission.require()
def index():
users = User.query.limit(10).all()
events = Event.query.limit(10).all()
return render_layout("admin_index.html", users=users, events=events)
topics = Topic.query.limit(10).all()
return render_layout("admin_index.html", users=users, topics=topics)
@admin.route("/user/")
@login_required
......@@ -69,53 +69,53 @@ def user_new():
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
@admin_permission.require()
def event_new():
form = NewEventForm()
def topic_new():
form = NewTopicForm()
if form.validate_on_submit():
if Event.query.filter_by(name=form.name.data).count() > 0:
flash("There already is an event with that name.", "alert-error")
return render_layout("admin_event_new.html", form=form)
event = Event(form.name.data, form.mode.data)
db.session.add(event)
if Topic.query.filter_by(name=form.name.data).count() > 0:
flash("There already is an topic with that name.", "alert-error")
return render_layout("admin_topic_new.html", form=form)
topic = Topic(form.name.data, form.mode.data)
db.session.add(topic)
db.session.commit()
return redirect(url_for(".event"))
return render_layout("admin_event_new.html", form=form)
return redirect(url_for(".topic"))
return render_layout("admin_topic_new.html", form=form)
@admin.route("/event/delete")
@admin.route("/topic/delete")
@login_required
@admin_permission.require()
def event_delete():
event_id = request.args.get("id", None)
if event_id is not None:
event = Event.query.filter_by(id=event_id).first()
db.session.delete(event)
def topc_delete():
topic_id = request.args.get("id", None)
if topic_id is not None:
topic = Topic.query.filter_by(id=topic_id).first()
db.session.delete(topic)
db.session.commit()
flash("Event deleted.", "alert-success")
return redirect(url_for(".event"))
flash("Topic deleted.", "alert-success")
return redirect(url_for(".topic"))
@admin.route("/event/edit", methods=["GET", "POST"])
@admin.route("/topic/edit", methods=["GET", "POST"])
@login_required
@admin_permission.require()
def event_edit():
event_id = request.args.get("id", None)
if event_id is not None:
event = db.session.query(Event).filter_by(id=event_id).first()
form = NewEventForm(obj=event)
def topic_edit():
topic_id = request.args.get("id", None)
if topic_id is not None:
topic = db.session.query(Topic).filter_by(id=topic_id).first()
form = NewTopicForm(obj=topic)
if form.validate_on_submit():
form.populate_obj(event)
form.populate_obj(topic)
db.session.commit()
return redirect(url_for(".index"))
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:
return redirect(url_for(".index"))
@admin.route("/event/")
@admin.route("/topic/")
@login_required
@admin_permission.require()
def event():
events = Event.query.all()
return render_layout("admin_event_index.html", events=events)
def topic():
topics = Topic.query.all()
return render_layout("admin_topic_index.html", topics=topics)
from flask import Blueprint, redirect, url_for, request, flash, abort, send_file, Response
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 shared import db, admin_permission, user_permission, render_layout
......@@ -13,9 +13,9 @@ import config
speech = Blueprint("speech", __name__)
def query_statements(mode, event_id):
statements = db.session.query(Statement).filter_by(event=event_id).all()
speakers = db.session.query(Speaker).filter_by(event=event_id).all()
def query_statements(mode, topic_id):
statements = db.session.query(Statement).filter_by(topic=topic_id).all()
speakers = db.session.query(Speaker).filter_by(topic=topic_id).all()
if mode == "balanced" or mode == "pending":
count = { speaker.id: 0 for speaker in speakers }
for statement in statements:
......@@ -40,46 +40,46 @@ def query_statements(mode, event_id):
@speech.route("/index")
def index():
event_id = request.args.get("event", None)
topic_id = request.args.get("topic", None)
mode = request.args.get("mode", None)
meta = []
if event_id is not None and event_id != "-1":
event = Event.query.filter_by(id=event_id).first()
if topic_id is not None and topic_id != "-1":
topic = Topic.query.filter_by(id=topic_id).first()
form = AddStatementForm()
form.event.data = event.id
meta.append((query_statements(mode if mode is not None else event.mode, event_id), form, event))
form.topic.data = topic.id
meta.append((query_statements(mode if mode is not None else topic.mode, topic_id), form, topic))
else:
for event in Event.query.all():
for topic in Topic.query.all():
form = AddStatementForm()
form.event.data = event.id
meta.append((query_statements(mode if mode is not None else event.mode, event.id), form, event))
event_id = -1
return render_layout("speech_index.html", meta=meta, event_id=event_id, mode=mode)
form.topic.data = topic.id
meta.append((query_statements(mode if mode is not None else topic.mode, topic.id), form, topic))
topic_id = -1
return render_layout("speech_index.html", meta=meta, topic_id=topic_id, mode=mode)
@speech.route("/show")
def show():
event_id = request.args.get("event", None)
topic_id = request.args.get("topic", None)
mode = request.args.get("mode", None)
meta = []
if event_id is not None and event_id is not "-1":
event = Event.query.filter_by(id=event_id).first()
meta.append((query_statements(mode if mode is not None else event.mode, event_id), event))
if topic_id is not None and topic_id is not "-1":
topic = Topic.query.filter_by(id=topic_id).first()
meta.append((query_statements(mode if mode is not None else topic.mode, topic_id), topic))
else:
for event in Event.query.all():
meta.append((query_statements(mode if mode is not None else event.mode, event.id), event))
return render_layout("speech_show.html", mode=mode, meta=meta, event_id=event_id)
for topic in Topic.query.all():
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, topic_id=topic_id)
@speech.route("/update")
def update():
event_id = request.args.get("event", None)
topic_id = request.args.get("topic", None)
mode = request.args.get("mode", None)
meta = []
if event_id is not None and event_id != "-1":
event = Event.query.filter_by(id=event_id).first()
meta.append((query_statements(mode if mode is not None else event.mode, event_id), event))
if topic_id is not None and topic_id != "-1":
topic = Topic.query.filter_by(id=topic_id).first()
meta.append((query_statements(mode if mode is not None else topic.mode, topic_id), topic))
else:
for event in Event.query.all():
meta.append((query_statements(mode if mode is not None else event.mode, event.id), event))
for topic in Topic.query.all():
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)
......@@ -90,31 +90,31 @@ def add():
add_form = AddStatementForm()
if add_form.validate_on_submit():
speaker_name = add_form["speaker_name"].data
event_id = add_form["event"].data
if speaker_name is None or event_id is None:
topic_id = add_form["topic"].data
if speaker_name is None or topic_id is None:
flash("Missing data", "alert-error")
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:
speaker = Speaker(speaker_name, event_id)
speaker = Speaker(speaker_name, topic_id)
db.session.add(speaker)
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")
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.commit()
mode = request.args.get("mode", None)
event_id = request.args.get("event", None)
return redirect(url_for(request.args.get("next") or ".index", mode=mode, event=event_id))
topic_id = request.args.get("topic", None)
return redirect(url_for(request.args.get("next") or ".index", mode=mode, topic=topic_id))
@speech.route("/cancel")
@user_permission.require()
def cancel():
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:
flash("Missing statement id", "alert-error")
return redirect(url_for(request.args.get("next") or ".index"))
......@@ -123,13 +123,13 @@ def cancel():
db.session.commit()
flash("Statement canceled", "alert-success")
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")
@user_permission.require()
def done():
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:
flash("Missing statement id", "alert-error")
return redirect(url_for(request.args.get("next") or ".index"))
......@@ -139,14 +139,14 @@ def done():
else:
flash("Statement already done", "alert-error")
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")
def update_show_js():
update_interval = config.UPDATE_SHOW_INTERVAL or 1
div = "rede-content-div"
mode = request.args.get("mode", None)
event_id = request.args.get("event", -1)
target_url = url_for(".update", mode=mode, event=event_id)
topic_id = request.args.get("topic", -1)
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_")
......@@ -10,7 +10,7 @@ from passlib.hash import pbkdf2_sha256
import config
from shared import db, login_manager, render_layout
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.config.from_object(config)
......@@ -38,24 +38,24 @@ def index():
user = User(fullname, username, password, ["admin", "user"])
db.session.add(user)
db.session.commit()
events = Event.query.all()
topics = Topic.query.all()
meta = []
for event in events:
ls = speech.query_statements(event.mode, event.id)
no_speaker = Speaker("No Speaker", event)
no_statement = Statement(no_speaker, event)
meta.append((ls[0] if len(ls) > 0 else (no_statement, no_speaker, ()), event))
for topic in topics:
ls = speech.query_statements(topic.mode, topic.id)
no_speaker = Speaker("No Speaker", topic)
no_statement = Statement(no_speaker, topic)
meta.append((ls[0] if len(ls) > 0 else (no_statement, no_speaker, ()), topic))
return render_layout("index.html", meta=meta)
@app.route("/update")
def update():
events = Event.query.all()
topics = Topic.query.all()
meta = []
for event in events:
ls = speech.query_statements(event.mode, event.id)
no_speaker = Speaker("No Speaker", event)
no_statement = Statement(no_speaker, event)
meta.append((ls[0] if len(ls) > 0 else (no_statement, no_speaker, ()), event))
for topic in topics:
ls = speech.query_statements(topic.mode, topic.id)
no_speaker = Speaker("No Speaker", topic)
no_statement = Statement(no_speaker, topic)
meta.append((ls[0] if len(ls) > 0 else (no_statement, no_speaker, ()), topic))
return render_layout("content_index.html", meta=meta)
@app.route("/update.js")
......
......@@ -36,17 +36,17 @@
</tr>
</thead>
<tbody>
{% for event in events %}
{% for topic in events %}
<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">{{ event.mode }}</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">{{ topic.mode }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<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") }}">
All events
<a class="mdl-button mdl-button--colored mdl-js-button" href="{{ url_for(".topic") }}">
All topics
</a>
</div>
</div>
......
{% extends "layout.html" %}
{% from "macros.html" import render_form %}
{% block title %}Edit Event - Administration{% endblock %}
{% block title %}Edit Topic - Administration{% endblock %}
{% 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 %}
{% extends "admin_index.html" %}
{% block admin_title %}Events{% endblock %}
{% block admin_title %}Topics{% endblock %}
{% block content %}
<div class="mdl-cell mdl-cell--3-col mdl-grid mdl-grid--no-spacing">
......@@ -12,12 +12,12 @@
</tr>
</thead>
<tbody>
{% for event in events %}
{% for topic in events %}
<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">{{ event.mode }}</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">{{ topic.mode }}</td>
<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>
</a>
</td>
......@@ -27,7 +27,7 @@
</table>
<div class="rede-separator">
<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>
</a>
</div>
......
{% extends "layout.html" %}
{% from "macros.html" import render_form %}
{% block title %}Add Event - Administration{% endblock %}
{% block title %}Add Topic - Administration{% endblock %}
{% 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 %}
{% 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-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 class="mdl-card__actions">
{% 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) }}">
<button type="button" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored">
<i class="material-icons" role="presentation">build</i>
</button>
</a>
{% endif %}
<a href="{{ url_for("speech.show", event=event.id) }}">
<a href="{{ url_for("speech.show", topic=event.id) }}">
<button type="button" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored">
<i class="material-icons" role="presentation">list</i>
</button>
......
{% from "macros.html" import render_form %}
{% for statements, event in meta %}
{% for statements, topic in meta %}
<table class="mdl-data-table mdl-js-table mdl-shadow--2dp mdl-cell mdl-cell--12-col mdl-cell--8-col-tablet mdl-cell--4-col-phone">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Speaker for {{ event.name }}</th>
<th class="mdl-data-table__cell--non-numeric">Speaker for {{ topic.name }}</th>
</tr>
</thead>
<tbody>
......
......@@ -11,12 +11,12 @@
{% endblock %}
{% block content %}
{% for statements, add_form, event in meta %}
{% for statements, add_form, topic in meta %}
<table id="next-speaker-table" class="mdl-data-table mdl-js-table mdl-shadow--2dp mdl-cell mdl-cell--6-col mdl-cell--4-col-tablet mdl-cell--4-col-phone sortable">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Speaker</th>
{% if (mode is not none and mode == "balanced") or (mode is none and event.mode == "balanced") %}
{% if (mode is not none and mode == "balanced") or (mode is none and topic.mode == "balanced") %}
<th>Count</th>
{% endif %}
{% if "user" in current_user.roles %}
......@@ -31,21 +31,21 @@
<td class="mdl-data-table__cell--non-numeric">
<h5>{{ speaker.name }}</h5>
</td>
{% if (mode is not none and mode == "balanced") or (mode is none and event.mode == "balanced") %}
{% if (mode is not none and mode == "balanced") or (mode is none and topic.mode == "balanced") %}
<td>
<h5>{{ count }}</h5>
</td>
{% endif %}
{% if "user" in current_user.roles %}
<td class="mdl-data-table__cell--non-numeric">
<a href="{{ url_for(".done", statement=statement.id, next=".index", event=event_id) }}">
<a href="{{ url_for(".done", statement=statement.id, next=".index", topic=event_id) }}">
<button class="mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-button--colored">
<i class="material-icons">done</i>
</button>
</a>
</td>
<td class="mdl-data-table__cell--non-numeric">
<a href="{{ url_for(".cancel", statement=statement.id, next=".index", event=event_id) }}">
<a href="{{ url_for(".cancel", statement=statement.id, next=".index", topic=event_id) }}">
<button class="mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab">
<i class="material-icons">delete</i>
</button>
......@@ -57,7 +57,7 @@
</tbody>
</table>
{% if current_user.is_authenticated() and "user" in current_user.roles %}
{{ render_form(add_form, action_url=url_for('.add', next=".index", event=event_id), action_text="Add", title="Add Speaker to {}".format(event.name)) }}
{{ render_form(add_form, action_url=url_for('.add', next=".index", topic=event_id), action_text="Add", title="Add Speaker to {}".format(event.name)) }}
{% endif %}
{% endfor %}
{% endblock %}
......@@ -2,7 +2,7 @@
{% from "macros.html" import render_form %}
{% block title %}Statements{% endblock %}
{% block additional_js %}
<script src="{{ url_for(".update_show_js", mode=mode, event=event_id) }}" async></script>
<script src="{{ url_for(".update_show_js", mode=mode, topic=event_id) }}" async></script>
{% endblock %}
{% block content %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment