aboutsummaryrefslogtreecommitdiff
path: root/app/auth
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2019-06-03 15:19:28 +0100
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2019-06-03 15:19:28 +0100
commit94c3656bea0ff16b826f1adf34a3ada9084c7f8f (patch)
treeb9e64849ea5dd15ab94fb3b8f79a2080fa050d1e /app/auth
parentInitial version of demo (diff)
downloadAnnotateChange-94c3656bea0ff16b826f1adf34a3ada9084c7f8f.tar.gz
AnnotateChange-94c3656bea0ff16b826f1adf34a3ada9084c7f8f.zip
Rewrite the task assignment flow
With the demo in place, we're rewriting the task assignment flow such that users only get a task assigned when: 1. They finish the demo 2. They finish a task 3. They login again. This way we can better balance the datasets and we won't have datasets that don't get enough annotations because some users didn't finish tasks they were assigned.
Diffstat (limited to 'app/auth')
-rw-r--r--app/auth/routes.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/app/auth/routes.py b/app/auth/routes.py
index 27b0de0..bc5e9b3 100644
--- a/app/auth/routes.py
+++ b/app/auth/routes.py
@@ -20,7 +20,8 @@ from app.auth.email import (
send_password_reset_email,
send_email_confirmation_email,
)
-from app.models import User
+from app.models import User, Task
+from app.utils.tasks import generate_user_task
@bp.route("/login", methods=("GET", "POST"))
@@ -32,13 +33,36 @@ def login():
flash("Invalid username or password", "error")
return redirect(url_for("auth.login"))
login_user(user, remember=form.remember_me.data)
+ # record last_active time
current_user.last_active = datetime.datetime.utcnow()
db.session.commit()
+
+ # redirect if not confirmed yet
if not user.is_confirmed:
return redirect(url_for("auth.not_confirmed"))
+
+ # Get the next page from the request (default to index)
next_page = request.args.get("next")
if not next_page or url_parse(next_page).netloc != "":
next_page = url_for("main.index")
+
+ # redirect if not introduced yet
+ 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)