def assign()

in data_annotation_platform/app/main/routes.py [0:0]


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. This can happen if the admin has assigned this task.
    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))