Commit 535aa66e authored by Robin Sonnabend's avatar Robin Sonnabend

Merge branch 'master' of git.fsmpi.rwth-aachen.de:redl/redeleitsystem

parents 6e69afe3 559389cc
"""empty message
Revision ID: 1b175b82cee
Revises: 3c75c74bb94
Create Date: 2015-11-08 14:06:28.235808
"""
# revision identifiers, used by Alembic.
revision = '1b175b82cee'
down_revision = '3c75c74bb94'
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('statements', sa.Column('is_current', sa.Boolean(), nullable=True))
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('statements', 'is_current')
### end Alembic commands ###
......@@ -94,9 +94,9 @@ class Topic(db.Model):
def sorted_statements(self):
statements = [statement for statement in self.statements if not statement.executed]
if self.mode == "fifo":
return sorted(statements, key=lambda st: -1 if st.is_meta else st.id)
return sorted(statements, key=lambda st:-2 if st.is_current else -1 if st.is_meta else st.id)
elif self.mode == "balanced":
return sorted(statements, key=lambda st: -1 if st.is_meta else st.speaker.count(self))
return sorted(statements, key=lambda st:-2 if st.is_current else -1 if st.is_meta else st.speaker.count(self))
else:
return statements
......@@ -169,34 +169,40 @@ class Statement(db.Model):
executed = db.Column(db.Boolean)
execution_time = db.Column(db.DateTime)
is_meta = db.Column(db.Boolean, default=False)
is_current = db.Column(db.Boolean, default=False)
speaker = relationship("Speaker", backref=backref("statements",order_by=id))
topic = relationship("Topic", backref=backref("statements",order_by=id))
def __init__(self, speaker_id, topic_id, insertion_time=None, executed=False, execution_time=None, is_meta=False):
def __init__(self, speaker_id, topic_id, insertion_time=None, executed=False, execution_time=None, is_meta=False, is_current=False):
self.speaker_id = speaker_id
self.topic_id = topic_id
self.insertion_time = insertion_time or datetime.now()
self.executed = executed
self.execution_time = execution_time or datetime.now()
self.is_meta = is_meta
self.is_current = is_current
def __repr__(self):
return "<Statement(id={}, speaker={}, topic_id={}, insertion_time={}, executed={}, execution_time={}, is_meta={})>".format(
return "<Statement(id={}, speaker={}, topic_id={}, insertion_time={}, executed={}, execution_time={}, is_meta={}, is_current={})>".format(
self.id,
self.speaker,
self.topic_id,
self.insertion_time,
self.executed,
self.execution_time,
self.is_meta
self.is_meta,
self.is_current
)
def done(self):
if self.executed:
return False
self.executed = True
self.is_current = False
self.execution_time = datetime.now()
if self.topic.sorted_statements() is not None and self.topic.sorted_statements():
self.topic.sorted_statements()[0].is_current = True
return True
def undo(self):
......
......@@ -283,8 +283,11 @@ def statement_new():
topic = Topic.query.filter_by(id=form.topic.data).first()
speaker = speaker_by_name_or_number(form.speaker_name.data, topic.event.id)
if topic is not None and speaker is not None:
if speaker.count_active(topic) == 0 or (statement == "add_meta_statement" and speaker.count_active_meta(topic) == 0) :
statement = Statement(speaker.id, topic.id, is_meta=(statement == "add_meta_statement"))
if speaker.count_active(topic) == 0 or (statement == "add_meta_statement"
and speaker.count_active_meta(topic) == 0) :
statement = Statement(speaker.id, topic.id,
is_meta=(statement == "add_meta_statement"),
is_current=(not topic.sorted_statements()))
db.session.add(statement)
db.session.commit()
return redirect(url_for(".topic_show", id=topic.id))
......@@ -310,12 +313,15 @@ def statement_done():
@admin_permission.require()
def statement_delete():
statement_id = request.args.get("id", None)
topic_id = request.args.get("topic_id", None)
if statement_id is not None:
statement = Statement.query.filter_by(id=statement_id).first()
if statement is not None:
topic = Topic.query.filter_by(id=topic_id).first()
if len(topic.sorted_statements()) > 1:
topic.sorted_statements()[1].is_current = True
db.session.delete(statement)
db.session.commit()
topic_id = request.args.get("topic_id", None)
if topic_id is not None:
return redirect(url_for(".topic_show", id=topic_id))
return redirect(url_for(".index"))
......
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