-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #40
- Loading branch information
Showing
15 changed files
with
557 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from flask import Blueprint | ||
from flask import jsonify | ||
from flask import request | ||
from flask.ext.login import current_user | ||
|
||
from models import AudioAnnotation | ||
from models import db | ||
|
||
audioann = Blueprint('audioann', __name__) | ||
|
||
@audioann.route('/audioannotation/new', methods=['POST']) | ||
def audioann_new(): | ||
""" | ||
Create a new audio annotation. | ||
:<json int doc: Document ID. | ||
:<json start: Start of annotation, in seconds | ||
:<json length: Length of annotation, in seconds | ||
:<json string text: The text content of the annotation. | ||
:>json int id: The new ID. | ||
""" | ||
user = current_user.id | ||
doc = request.form['doc'] | ||
start = request.form['start'] | ||
length = request.form['length'] | ||
text = request.form['text'] | ||
aa = AudioAnnotation(user, doc, start, length, text) | ||
db.session.add(aa) | ||
db.session.commit() | ||
return jsonify(id=aa.id) | ||
|
||
|
||
@audioann.route('/view/<id>/audioannotations') | ||
def audio_annotations_for_doc(id): | ||
""" | ||
Get the audio annotations associated to a Document. | ||
:param id: Integer ID | ||
:>json array data: Results | ||
""" | ||
data = [] | ||
for ann in AudioAnnotation.query.filter_by(doc_id=id): | ||
data.append(ann.to_json()) | ||
return jsonify(data=data) | ||
|
||
|
||
@audioann.route('/audioannotation/<id>', methods=['DELETE']) | ||
def annotation_delete(id): | ||
""" | ||
Delete an audio annotation. | ||
:param id: Integer ID | ||
:>json string status: The string 'ok' | ||
""" | ||
ann = AudioAnnotation.query.get(id) | ||
if not ann.editable_by(current_user): | ||
return lm.unauthorized() | ||
db.session.delete(ann) | ||
db.session.commit() | ||
return jsonify(status='ok') | ||
|
||
|
||
@audioann.route('/audioannotation/<id>', methods=['PUT']) | ||
def audio_annotation_edit(id): | ||
""" | ||
Edit an AudioAnnotation. | ||
For JSON parameters, see :py:func:`audioann_new`. | ||
:>json string status: The string 'ok' | ||
""" | ||
ann = AudioAnnotation.query.get(id) | ||
if not ann.editable_by(current_user): | ||
return lm.unauthorized() | ||
ann.load_json(request.form) | ||
db.session.commit() | ||
return jsonify(status='ok') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Add AudioAnnotation | ||
Revision ID: 51a83463dbb6 | ||
Revises: 22608a4a8a06 | ||
Create Date: 2014-11-07 13:51:43.097465 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '51a83463dbb6' | ||
down_revision = '22608a4a8a06' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('audio_annotation', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('user_id', sa.Integer(), nullable=True), | ||
sa.Column('doc_id', sa.Integer(), nullable=False), | ||
sa.Column('start', sa.Integer(), nullable=False), | ||
sa.Column('length', sa.Integer(), nullable=False), | ||
sa.Column('text', sa.String(), nullable=False), | ||
sa.Column('state', sa.SmallInteger(), nullable=False), | ||
sa.ForeignKeyConstraint(['doc_id'], ['document.id'], ), | ||
sa.ForeignKeyConstraint(['user_id'], [u'user.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('audio_annotation') | ||
### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.