Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
redl
redeleitsystem
Commits
c5901a6a
Commit
c5901a6a
authored
Nov 08, 2015
by
Hinrikus Wolf
Browse files
add current speaker to statements list
parent
a4b6c53f
Changes
3
Show whitespace changes
Inline
Side-by-side
migrations/versions/1b175b82cee_.py
0 → 100644
View file @
c5901a6a
"""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 ###
models/database.py
View file @
c5901a6a
...
@@ -94,9 +94,9 @@ class Topic(db.Model):
...
@@ -94,9 +94,9 @@ class Topic(db.Model):
def
sorted_statements
(
self
):
def
sorted_statements
(
self
):
statements
=
[
statement
for
statement
in
self
.
statements
if
not
statement
.
executed
]
statements
=
[
statement
for
statement
in
self
.
statements
if
not
statement
.
executed
]
if
self
.
mode
==
"fifo"
:
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"
:
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
:
else
:
return
statements
return
statements
...
@@ -169,34 +169,40 @@ class Statement(db.Model):
...
@@ -169,34 +169,40 @@ class Statement(db.Model):
executed
=
db
.
Column
(
db
.
Boolean
)
executed
=
db
.
Column
(
db
.
Boolean
)
execution_time
=
db
.
Column
(
db
.
DateTime
)
execution_time
=
db
.
Column
(
db
.
DateTime
)
is_meta
=
db
.
Column
(
db
.
Boolean
,
default
=
False
)
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
))
speaker
=
relationship
(
"Speaker"
,
backref
=
backref
(
"statements"
,
order_by
=
id
))
topic
=
relationship
(
"Topic"
,
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
.
speaker_id
=
speaker_id
self
.
topic_id
=
topic_id
self
.
topic_id
=
topic_id
self
.
insertion_time
=
insertion_time
or
datetime
.
now
()
self
.
insertion_time
=
insertion_time
or
datetime
.
now
()
self
.
executed
=
executed
self
.
executed
=
executed
self
.
execution_time
=
execution_time
or
datetime
.
now
()
self
.
execution_time
=
execution_time
or
datetime
.
now
()
self
.
is_meta
=
is_meta
self
.
is_meta
=
is_meta
self
.
is_current
=
is_current
def
__repr__
(
self
):
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
.
id
,
self
.
speaker
,
self
.
speaker
,
self
.
topic_id
,
self
.
topic_id
,
self
.
insertion_time
,
self
.
insertion_time
,
self
.
executed
,
self
.
executed
,
self
.
execution_time
,
self
.
execution_time
,
self
.
is_meta
self
.
is_meta
,
self
.
is_current
)
)
def
done
(
self
):
def
done
(
self
):
if
self
.
executed
:
if
self
.
executed
:
return
False
return
False
self
.
executed
=
True
self
.
executed
=
True
self
.
is_current
=
False
self
.
execution_time
=
datetime
.
now
()
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
return
True
def
undo
(
self
):
def
undo
(
self
):
...
...
modules/admin.py
View file @
c5901a6a
...
@@ -282,8 +282,11 @@ def statement_new():
...
@@ -282,8 +282,11 @@ def statement_new():
topic
=
Topic
.
query
.
filter_by
(
id
=
form
.
topic
.
data
).
first
()
topic
=
Topic
.
query
.
filter_by
(
id
=
form
.
topic
.
data
).
first
()
speaker
=
speaker_by_name_or_number
(
form
.
speaker_name
.
data
,
topic
.
event
.
id
)
speaker
=
speaker_by_name_or_number
(
form
.
speaker_name
.
data
,
topic
.
event
.
id
)
if
topic
is
not
None
and
speaker
is
not
None
:
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
)
:
if
speaker
.
count_active
(
topic
)
==
0
or
(
statement
==
"add_meta_statement"
statement
=
Statement
(
speaker
.
id
,
topic
.
id
,
is_meta
=
(
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
.
add
(
statement
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
redirect
(
url_for
(
".topic_show"
,
id
=
topic
.
id
))
return
redirect
(
url_for
(
".topic_show"
,
id
=
topic
.
id
))
...
@@ -309,12 +312,15 @@ def statement_done():
...
@@ -309,12 +312,15 @@ def statement_done():
@
admin_permission
.
require
()
@
admin_permission
.
require
()
def
statement_delete
():
def
statement_delete
():
statement_id
=
request
.
args
.
get
(
"id"
,
None
)
statement_id
=
request
.
args
.
get
(
"id"
,
None
)
topic_id
=
request
.
args
.
get
(
"topic_id"
,
None
)
if
statement_id
is
not
None
:
if
statement_id
is
not
None
:
statement
=
Statement
.
query
.
filter_by
(
id
=
statement_id
).
first
()
statement
=
Statement
.
query
.
filter_by
(
id
=
statement_id
).
first
()
if
statement
is
not
None
:
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
.
delete
(
statement
)
db
.
session
.
commit
()
db
.
session
.
commit
()
topic_id
=
request
.
args
.
get
(
"topic_id"
,
None
)
if
topic_id
is
not
None
:
if
topic_id
is
not
None
:
return
redirect
(
url_for
(
".topic_show"
,
id
=
topic_id
))
return
redirect
(
url_for
(
".topic_show"
,
id
=
topic_id
))
return
redirect
(
url_for
(
".index"
))
return
redirect
(
url_for
(
".index"
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment