aboutsummaryrefslogtreecommitdiff
path: root/app/main/routes.py
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2019-09-13 15:27:37 +0100
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2019-09-13 15:27:37 +0100
commit85e36328f7bd5033efaa92c3b040769eb2eee181 (patch)
tree172706ab0dec53f468ec7962d5bc172788e42c35 /app/main/routes.py
parentRemove y-axis value from table (diff)
downloadAnnotateChange-85e36328f7bd5033efaa92c3b040769eb2eee181.tar.gz
AnnotateChange-85e36328f7bd5033efaa92c3b040769eb2eee181.zip
Assign new tasks on the fly
The old logic assigned a task when the user finished the demo, logged in, or finished an annotation. This was not optimal as it could lead to race conditions where some datasets were annotated unnecessarily. With this change we select the dataset to annotate at the exact moment the user wants to do another one.
Diffstat (limited to 'app/main/routes.py')
-rw-r--r--app/main/routes.py37
1 files changed, 26 insertions, 11 deletions
diff --git a/app/main/routes.py b/app/main/routes.py
index 13fe3f8..8a0e83e 100644
--- a/app/main/routes.py
+++ b/app/main/routes.py
@@ -46,6 +46,32 @@ def index():
return render_template("index.html", title="Home")
+@bp.route("/assign")
+@login_required
+def assign():
+ # Intermediate page that assigns a task to a user if needed and then
+ # redirects to /annotate/task.id
+ user_tasks = Task.query.filter_by(annotator_id=current_user.id).all()
+ user_tasks = [t for t in user_tasks if not t.dataset.is_demo]
+ user_tasks = [t for t in user_tasks if not t.done]
+
+ # if the user has, for some reason, a unfinished assigned task, redirect to
+ # that
+ if len(user_tasks) > 0:
+ task = user_tasks[0]
+ return redirect(url_for("main.annotate", task_id=task.id))
+
+ task = generate_user_task(current_user)
+ if task is None:
+ flash(
+ "There are no more datasets to annotate at the moment, thanks for all your help!",
+ "info",
+ )
+ return redirect(url_for("main.index"))
+ db.session.add(task)
+ db.session.commit()
+ return redirect(url_for("main.annotate", task_id=task.id))
+
@bp.route("/annotate/<int:task_id>", methods=("GET", "POST"))
@login_required
def annotate(task_id):
@@ -94,17 +120,6 @@ def annotate(task_id):
"annotations_raw": annotation,
}
send_annotation_backup(record)
-
- # assign a new task if necessary
- task = generate_user_task(current_user)
- if task is None:
- return url_for("main.index")
- db.session.add(task)
- db.session.commit()
- flash(
- "A new dataset has been assigned for you to annotate. Thanks for your help!",
- "info",
- )
return url_for("main.index")
task = Task.query.filter_by(id=task_id).first()