Skip to content
Snippets Groups Projects
Commit 58056af3 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Added topic overview

parent de956911
No related branches found
No related tags found
No related merge requests found
"""empty message
Revision ID: 497c76393f9
Revises: c14363cf9b
Create Date: 2015-11-07 21:39:34.419696
"""
# revision identifiers, used by Alembic.
revision = '497c76393f9'
down_revision = 'c14363cf9b'
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('topics_index_key', 'topics', type_='unique')
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint('topics_index_key', 'topics', ['index'])
### end Alembic commands ###
"""empty message
Revision ID: c14363cf9b
Revises: 201dda3f23e
Create Date: 2015-11-07 20:59:17.755968
"""
# revision identifiers, used by Alembic.
revision = 'c14363cf9b'
down_revision = '201dda3f23e'
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('topics', sa.Column('index', sa.Integer(), nullable=True))
op.create_unique_constraint(None, 'topics', ['index'])
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'topics', type_='unique')
op.drop_column('topics', 'index')
### end Alembic commands ###
...@@ -46,25 +46,32 @@ class Event(db.Model): ...@@ -46,25 +46,32 @@ class Event(db.Model):
def __repr__(self): def __repr__(self):
return "<Event(id={}, name={})>".format(self.id, self.name) return "<Event(id={}, name={})>".format(self.id, self.name)
def sorted_topics(self):
return sorted(self.topics, key=lambda tp: tp.get_index())
class Topic(db.Model): class Topic(db.Model):
__tablename__ = "topics" __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)
event_id = db.Column(db.Integer, db.ForeignKey("events.id"), nullable=False) event_id = db.Column(db.Integer, db.ForeignKey("events.id"), nullable=False)
index = db.Column(db.Integer)
event = relationship("Event", backref=backref("topics",order_by=id)) event = relationship("Event", backref=backref("topics",order_by=id))
def __init__(self, name, mode, event_id): def __init__(self, name, mode, event_id):
self.name = name self.name = name
self.mode = mode self.mode = mode
self.event_id = event_id self.event_id = event_id
self.index = None
def __repr__(self): def __repr__(self):
return "<Topic(id={}, name='{}', mode='{}', event_id={})>".format( return "<Topic(id={}, name='{}', mode='{}', event_id={}, index={})>".format(
self.id, self.id,
self.name, self.name,
self.mode, self.mode,
self.event_id self.event_id,
self.index
) )
def sorted_statements(self): def sorted_statements(self):
...@@ -76,6 +83,20 @@ class Topic(db.Model): ...@@ -76,6 +83,20 @@ class Topic(db.Model):
else: else:
return statements return statements
def swap_topics(self, other):
other.index, self.index = self.get_index(), other.get_index()
def get_index(self):
if self.index == None:
return self.id
return self.index
def get_next_index(self):
topics = self.event.sorted_topics()
i = topics.index(self) + 1
if i >= len(topics):
i = -1
return topics[i].id
class Speaker(db.Model): class Speaker(db.Model):
__tablename__ = "speakers" __tablename__ = "speakers"
......
...@@ -144,7 +144,8 @@ def topic_show(): ...@@ -144,7 +144,8 @@ def topic_show():
form = AddStatementForm() form = AddStatementForm()
form.topic.data = topic.id form.topic.data = topic.id
statements = topic.sorted_statements() statements = topic.sorted_statements()
return render_layout("admin_topic_show.html", topic=topic, form=form, statements=statements) topics = topic.event.sorted_topics()
return render_layout("admin_topic_show.html", topic=topic, form=form, statements=statements, topics=topics)
return redirect(url_for(".index")) return redirect(url_for(".index"))
...@@ -160,7 +161,7 @@ def topic_new(): ...@@ -160,7 +161,7 @@ def topic_new():
topic = Topic(form.name.data, form.mode.data, form.event_id.data) topic = Topic(form.name.data, form.mode.data, form.event_id.data)
db.session.add(topic) db.session.add(topic)
db.session.commit() db.session.commit()
return redirect(url_for(".topic")) return redirect(url_for(".event", id=topic.event.id))
event_id = request.args.get("event_id", None) event_id = request.args.get("event_id", None)
if event_id is None: if event_id is None:
return redirect(url_for(".index")) return redirect(url_for(".index"))
...@@ -203,6 +204,37 @@ def topic(): ...@@ -203,6 +204,37 @@ def topic():
topics = Topic.query.all() topics = Topic.query.all()
return render_layout("admin_topic_index.html", topics=topics) return render_layout("admin_topic_index.html", topics=topics)
@admin.route("/topic/swap/up")
@login_required
@admin_permission.require()
def topic_swap_up():
topic_id = request.args.get("id", None)
original_id = request.args.get("original", None)
if topic_id is not None:
topic = Topic.query.filter_by(id=topic_id).first()
topics = topic.event.sorted_topics()
index = topics.index(topic)
if index != 0:
topic.swap_topics(topics[index-1])
db.session.commit()
return redirect(url_for(".topic_show", id=original_id))
return redirect(url_for(".index"))
@admin.route("/topic/swap/down")
@login_required
@admin_permission.require()
def topic_swap_down():
topic_id = request.args.get("id", None)
original_id = request.args.get("original", None)
if topic_id is not None:
topic = Topic.query.filter_by(id=topic_id).first()
topics = topic.event.sorted_topics()
index = topics.index(topic)
if index != len(topics) - 1:
topic.swap_topics(topics[index+1])
db.session.commit()
return redirect(url_for(".topic_show", id=original_id))
return redirect(url_for(".index"))
@admin.route("/speaker/rename", methods=["GET", "POST"]) @admin.route("/speaker/rename", methods=["GET", "POST"])
@login_required @login_required
...@@ -292,3 +324,4 @@ def statement_undo(): ...@@ -292,3 +324,4 @@ def statement_undo():
statement.undo() statement.undo()
db.session.commit() db.session.commit()
return redirect(url_for(".topic_show", id=topic_id)) return redirect(url_for(".topic_show", id=topic_id))
...@@ -123,3 +123,11 @@ th.rede-medium-text { ...@@ -123,3 +123,11 @@ th.rede-medium-text {
list-style-type: none; list-style-type: none;
padding-left: 1pc; padding-left: 1pc;
} }
.rede-list-point-big {
font-weight: bold;
}
.rede-list-point-normal {
font-weight: normal;
}
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
<thead> <thead>
<tr> <tr>
<th class="mdl-data-table__cell--non-numeric">Name</th> <th class="mdl-data-table__cell--non-numeric">Name</th>
<th class="mdl-data-table__cell--non-numeric">Mode</th>
<th class="mdl-data-table__cell--non-numeric">Edit</th> <th class="mdl-data-table__cell--non-numeric">Edit</th>
<th class="mdl-data-table__cell--non-numeric">Delete</th> <th class="mdl-data-table__cell--non-numeric">Delete</th>
</tr> </tr>
......
...@@ -56,7 +56,32 @@ ...@@ -56,7 +56,32 @@
</li> </li>
{% endif %} {% endif %}
<li><a href="{{ url_for(".statement_undo") }}" class="rede-href"><i class="material-icons" role="presentation">undo</i> Previous</a></li> <li><a href="{{ url_for(".statement_undo") }}" class="rede-href"><i class="material-icons" role="presentation">undo</i> Previous</a></li>
<li><a href="{{ url_for(".topic_show", id=topic.get_next_index()) }}"><i class="material-icons">arrow_forward</i> Next Topic</a></li>
</ul> </ul>
</div> </div>
</div> </div>
<div class="mdl-cell mdl-cell--3-col mdl-cell--3-col-tablet mdl-cell--4-col-phone mdl-card mdl-shadow--2dp">
<div class="mdl-card__title">
<h4 class="mdl-card__title-text">Topics</h4>
</div>
<table>
{% for t in topics %}
<tr class="{% if t == topic %}rede-list-point-big{% else %}rede-list-point-normal{% endif %}">
<td>
{% if t != topics[0] %}
<a href="{{ url_for(".topic_swap_up", id=t.id, original=topic.id) }}"><i class="material-icons">keyboard_arrow_up</i></a>
{% endif %}
</td>
<td>
{{ t.name }}
</td>
<td>
{% if t != topics[-1] %}
<a href="{{ url_for(".topic_swap_down", id=t.id, original=topic.id) }}"><i class="material-icons">keyboard_arrow_down</i></a>
{% endif %}
</td>
<tr>
{% endfor %}
</table>
</div>
{% endblock %} {% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment