aboutsummaryrefslogtreecommitdiff
path: root/app/auth
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/auth
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/auth')
-rw-r--r--app/auth/routes.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/app/auth/routes.py b/app/auth/routes.py
index fa792c2..0556233 100644
--- a/app/auth/routes.py
+++ b/app/auth/routes.py
@@ -30,8 +30,7 @@ from app.auth.email import (
send_password_reset_email,
send_email_confirmation_email,
)
-from app.models import User, Task
-from app.utils.tasks import generate_user_task
+from app.models import User, Task, Annotation
LEGAL = markdown.markdown(
@@ -92,6 +91,21 @@ def login():
current_user.last_active = datetime.datetime.utcnow()
db.session.commit()
+ # remove any assigned unfinished datasets, as these may no longer be
+ # needed
+ user_tasks = Task.query.filter_by(
+ annotator_id=current_user.id, done=False
+ ).all()
+ for task in user_tasks:
+ anns = Annotation.query.filter_by(task_id=task.id).all()
+ if len(anns) > 0:
+ flash(
+ "Internal error, unfinished tasks has annotations!",
+ "error",
+ )
+ db.session.delete(task)
+ db.session.commit()
+
# redirect if not confirmed yet
if not user.is_confirmed:
return redirect(url_for("auth.not_confirmed"))
@@ -105,19 +119,6 @@ def login():
if not user.is_introduced:
return redirect(url_for("main.index"))
- # assign task if no remaining and not at maximum.
- remaining = Task.query.filter_by(
- annotator_id=user.id, done=False
- ).all()
- if remaining:
- return redirect(next_page)
-
- task = generate_user_task(user)
- if task is None:
- return redirect(next_page)
-
- db.session.add(task)
- db.session.commit()
return redirect(next_page)
return render_template("auth/login.html", title="Sign In", form=form)