Пример #1
0
def student_id():
    github = github_username()
    if request.method == "GET":
        return render_template("onboarding/student_id.html", github=github)
    try:
        mailer_job = None
        github_job = None
        with DbCursor() as c:
            user = get_user_by_github(c, github)
            if user:
                return redirect(url_for("dashboard.index"))
            student_id = request.form.get("f_student_id")
            if not student_id:
                fail_validation("Student ID is required")
            user = get_user_by_student_id(c, student_id)
            if not user:
                fail_validation("Student not found with that student ID")
            user_id, name, _, login, old_github, email = user
            if old_github:
                fail_validation(
                    "Another GitHub account has been associated with that student "
                    "ID already.")
            if not name:
                fail_validation(
                    "There is no name associated with this account. (Contact your TA?)"
                )
            if not login:
                fail_validation(
                    "There is no login associated with this account. (Contact your "
                    "TA?)")
            if not email:
                fail_validation(
                    "There is no email associated with this account. (Contact your "
                    "TA?)")
            c.execute('''UPDATE users SET github = ? WHERE sid = ?''',
                      [github, student_id])
            if not config.github_read_only_mode:
                github_job = repomanager_queue.create(c, "assign_repo",
                                                      (login, [github]))
            if config.mailer_enabled:
                if config.inst_account_enabled:
                    attachments = [("pdf", get_inst_account_form_path(login))]
                else:
                    attachments = []
                email_payload = create_email(
                    "onboarding_confirm",
                    email,
                    "%s Autograder Registration" % config.course_number,
                    _attachments=attachments,
                    name=name,
                    login=login,
                    inst_account_enabled=config.inst_account_enabled)
                mailer_job = mailer_queue.create(c, "send", email_payload)
        if config.mailer_enabled and mailer_job:
            mailer_queue.enqueue(mailer_job)
        if not config.github_read_only_mode and github_job:
            repomanager_queue.enqueue(github_job)
        return redirect(url_for(_get_next_step("onboarding.student_id")))
    except ValidationError as e:
        return redirect_with_error(url_for("onboarding.student_id"), e)
Пример #2
0
def students_one(identifier, type_):
    with DbCursor() as c:
        student = None
        if type_ in ("id", "user_id"):
            student = get_user_by_id(c, identifier)
        elif type_ in ("github", "_github_explicit"):
            student = get_user_by_github(c, identifier)
        elif type_ == "login":
            student = get_user_by_login(c, identifier)
        elif type_ in ("sid", "student_id"):
            student = get_user_by_student_id(c, identifier)
        if student is None:
            abort(404)
        user_id, _, _, _, _, _ = student
        super_ = get_super(c, user_id)
        photo = None
        if student_photos_enabled:
            photo = get_photo(c, user_id)
        c.execute(
            '''SELECT users.id, users.name, users.github, groupsusers.`group`
                     FROM groupsusers LEFT JOIN users ON groupsusers.user = users.id
                     WHERE groupsusers.`group` IN
                         (SELECT `group` FROM groupsusers WHERE user = ?)''',
            [user_id])
        groups = OrderedDict()
        for g_user_id, g_name, g_github, g_group in c.fetchall():
            groups.setdefault(g_group, []).append(
                (g_user_id, g_name, g_github))
        grouplimit = get_grouplimit(c, user_id)
        c.execute(
            '''SELECT transaction_name, source, assignment, score, slipunits, updated,
                     description FROM gradeslog WHERE user = ? ORDER BY updated DESC''',
            [user_id])
        entries = c.fetchall()
        full_scores = {
            assignment.name: assignment.full_score
            for assignment in config.assignments
        }
        events = [entry + (full_scores.get(entry[2]), ) for entry in entries]
        c.execute(
            "SELECT assignment, score, slipunits, updated FROM grades WHERE user = ?",
            [user_id])
        grade_info = {
            assignment: (score, slipunits, updated)
            for assignment, score, slipunits, updated in c.fetchall()
        }
        assignments_info = [(a.name, a.full_score, a.weight, a.due_date) +
                            grade_info.get(a.name, (None, None, None))
                            for a in config.assignments]
    return render_template("ta/students_one.html",
                           student=student,
                           super_=super_,
                           photo=photo,
                           groups=groups.items(),
                           grouplimit=grouplimit,
                           events=events,
                           assignments_info=assignments_info,
                           **_template_common())
Пример #3
0
def students_one(identifier, type_):
    with DbCursor() as c:
        student = None
        if type_ in ("id", "user_id"):
            student = get_user_by_id(c, identifier)
        elif type_ in ("github", "_github_explicit"):
            student = get_user_by_github(c, identifier)
        elif type_ == "login":
            student = get_user_by_login(c, identifier)
        elif type_ in ("sid", "student_id"):
            student = get_user_by_student_id(c, identifier)
        if student is None:
            abort(404)
        user_id, _, _, _, _, _ = student
        super_ = get_super(c, user_id)
        photo = None
        if student_photos_enabled:
            photo = get_photo(c, user_id)
        c.execute(
            """SELECT users.id, users.name, users.github, groupsusers.`group`
                     FROM groupsusers LEFT JOIN users ON groupsusers.user = users.id
                     WHERE groupsusers.`group` IN
                         (SELECT `group` FROM groupsusers WHERE user = ?)""",
            [user_id],
        )
        groups = OrderedDict()
        for g_user_id, g_name, g_github, g_group in c.fetchall():
            groups.setdefault(g_group, []).append((g_user_id, g_name, g_github))
        grouplimit = get_grouplimit(c, user_id)
        c.execute(
            """SELECT transaction_name, source, assignment, score, slipunits, updated,
                     description FROM gradeslog WHERE user = ? ORDER BY updated DESC""",
            [user_id],
        )
        entries = c.fetchall()
        full_scores = {assignment.name: assignment.full_score for assignment in config.assignments}
        events = [entry + (full_scores.get(entry[2]),) for entry in entries]
        c.execute("SELECT assignment, score, slipunits, updated FROM grades WHERE user = ?", [user_id])
        grade_info = {assignment: (score, slipunits, updated) for assignment, score, slipunits, updated in c.fetchall()}
        assignments_info = [
            (a.name, a.full_score, a.weight, a.due_date) + grade_info.get(a.name, (None, None, None))
            for a in config.assignments
        ]
    return render_template(
        "ta/students_one.html",
        student=student,
        super_=super_,
        photo=photo,
        groups=groups.items(),
        grouplimit=grouplimit,
        events=events,
        assignments_info=assignments_info,
        **_template_common()
    )
Пример #4
0
def student_id():
    github = github_username()
    if request.method == "GET":
        return render_template("onboarding/student_id.html",
                               github=github)
    try:
        mailer_job = None
        github_job = None
        with DbCursor() as c:
            user = get_user_by_github(c, github)
            if user:
                return redirect(url_for("dashboard.index"))
            student_id = request.form.get("f_student_id")
            if not student_id:
                fail_validation("Student ID is required")
            user = get_user_by_student_id(c, student_id)
            if not user:
                fail_validation("Student not found with that student ID")
            user_id, name, _, login, old_github, email = user
            if old_github:
                fail_validation("Another GitHub account has been associated with that student "
                                "ID already.")
            if not name:
                fail_validation("There is no name associated with this account. (Contact your TA?)")
            if not login:
                fail_validation("There is no login associated with this account. (Contact your "
                                "TA?)")
            if not email:
                fail_validation("There is no email associated with this account. (Contact your "
                                "TA?)")
            c.execute('''UPDATE users SET github = ? WHERE sid = ?''',
                      [github, student_id])
            if not config.github_read_only_mode:
                github_job = repomanager_queue.create(c, "assign_repo", (login, [github]))
            if config.mailer_enabled:
                if config.inst_account_enabled:
                    attachments = [("pdf", get_inst_account_form_path(login))]
                else:
                    attachments = []
                email_payload = create_email("onboarding_confirm", email,
                                             "%s Autograder Registration" % config.course_number,
                                             _attachments=attachments, name=name, login=login,
                                             inst_account_enabled=config.inst_account_enabled)
                mailer_job = mailer_queue.create(c, "send", email_payload)
        if config.mailer_enabled and mailer_job:
            mailer_queue.enqueue(mailer_job)
        if not config.github_read_only_mode and github_job:
            repomanager_queue.enqueue(github_job)
        return redirect(url_for(_get_next_step("onboarding.student_id")))
    except ValidationError as e:
        return redirect_with_error(url_for("onboarding.student_id"), e)