예제 #1
0
def welcome():
    github = github_username()
    with DbCursor() as c:
        user = get_user_by_id(c, user_id())
    return render_template("onboarding/welcome.html",
                           github=github,
                           user=user,
                           inst_account_enabled=config.inst_account_enabled)
예제 #2
0
파일: __init__.py 프로젝트: aykamko/ob2
def welcome():
    github = github_username()
    with DbCursor() as c:
        user = get_user_by_id(c, user_id())
    return render_template("onboarding/welcome.html",
                           github=github,
                           user=user,
                           inst_account_enabled=config.inst_account_enabled)
예제 #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
파일: __init__.py 프로젝트: octobear2/ob2
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()
    )
예제 #5
0
 def try_add(f_student, f_score, f_slipunits):
     if not any((f_student, f_score, f_slipunits)):
         return
     elif not f_student and (f_score or f_slipunits):
         fail_validation(
             "Expected student SID, login, or name, but none provided"
         )
     elif f_student in ambiguous_identifiers:
         fail_validation(
             "The identifier '%s' is ambiguous. Please use another."
             % f_student)
     else:
         if step == 1:
             students = get_users_by_identifier(c, f_student)
         elif step == 2:
             student = get_user_by_id(c, f_student)
             # Let the usual error handling take care of this case
             students = [student] if student else []
         if not students:
             fail_validation("Student or group not found: %s" %
                             f_student)
         for student in students:
             user_id, student_name, _, _, _, _ = student
             if user_id in user_id_set:
                 fail_validation(
                     "Student was listed more than once: %s" %
                     student_name)
             try:
                 score = float_or_none(f_score)
             except ValueError:
                 fail_validation("Not a valid score: %s" % f_score)
             try:
                 slipunits = int_or_none(f_slipunits)
             except ValueError:
                 fail_validation(
                     "Slip %s amount not valid: %s" %
                     (slip_unit_name_plural, f_slipunits))
             if slipunits is not None and slipunits < 0:
                 fail_validation("Slip %s cannot be negative" %
                                 slip_unit_name_plural)
             if score is not None and not min_score <= score <= max_score:
                 fail_validation(
                     "Score is out of allowed range: %s (Range: %s to %s)"
                     % (f_score, str(min_score), str(max_score)))
             entries.append([user_id, score, slipunits])
             user_id_set.add(user_id)
예제 #6
0
파일: __init__.py 프로젝트: octobear2/ob2
def modify_grouplimit_now():
    user_id = request.form.get("f_user_id")
    action = request.form.get("f_action")
    if not user_id:
        abort(400)
    if action not in ("add", "subtract"):
        abort(400)
    with DbCursor() as c:
        student = get_user_by_id(c, user_id)
        if not student:
            abort(400)
        _, _, _, _, github, _ = student
        modification = {"add": +1, "subtract": -1}
        modify_grouplimit(c, user_id, modification[action])
        grouplimit = get_grouplimit(c, user_id)
        flash("grouplimit has been set to %d" % grouplimit, "success")
    if github:
        return redirect(url_for("ta.students_one", identifier=github, type_="github"))
    else:
        return redirect(url_for("ta.students_one", identifier=user_id, type_="user_id"))
예제 #7
0
def modify_grouplimit_now():
    user_id = request.form.get("f_user_id")
    action = request.form.get("f_action")
    if not user_id:
        abort(400)
    if action not in ("add", "subtract"):
        abort(400)
    with DbCursor() as c:
        student = get_user_by_id(c, user_id)
        if not student:
            abort(400)
        _, _, _, _, github, _ = student
        modification = {"add": +1, "subtract": -1}
        modify_grouplimit(c, user_id, modification[action])
        grouplimit = get_grouplimit(c, user_id)
        flash("grouplimit has been set to %d" % grouplimit, "success")
    if github:
        return redirect(
            url_for("ta.students_one", identifier=github, type_="github"))
    else:
        return redirect(
            url_for("ta.students_one", identifier=user_id, type_="user_id"))
예제 #8
0
파일: __init__.py 프로젝트: cycomachead/ob2
 def try_add(f_student, f_score, f_slipunits):
     if not any((f_student, f_score, f_slipunits)):
         return
     elif not f_student and (f_score or f_slipunits):
         fail_validation("Expected student SID, login, or name, but none provided")
     elif f_student in ambiguous_identifiers:
         fail_validation("The identifier '%s' is ambiguous. Please use another." %
                         f_student)
     else:
         if step == 1:
             students = get_users_by_identifier(c, f_student)
         elif step == 2:
             student = get_user_by_id(c, f_student)
             # Let the usual error handling take care of this case
             students = [student] if student else []
         if not students:
             fail_validation("Student or group not found: %s" % f_student)
         for student in students:
             user_id, student_name, _, _, _, _ = student
             if user_id in user_id_set:
                 fail_validation("Student was listed more than once: %s" % student_name)
             try:
                 score = float_or_none(f_score)
             except ValueError:
                 fail_validation("Not a valid score: %s" % f_score)
             try:
                 slipunits = int_or_none(f_slipunits)
             except ValueError:
                 fail_validation("Slip %s amount not valid: %s" % (slip_unit_name_plural,
                                                                   f_slipunits))
             if slipunits is not None and slipunits < 0:
                 fail_validation("Slip %s cannot be negative" % slip_unit_name_plural)
             if score is not None and not min_score <= score <= max_score:
                 fail_validation("Score is out of allowed range: %s (Range: %s to %s)" %
                                 (f_score, str(min_score), str(max_score)))
             entries.append([user_id, score, slipunits])
             user_id_set.add(user_id)
예제 #9
0
파일: __init__.py 프로젝트: octobear2/ob2
def _get_student(c):
    if not hasattr(g, "student"):
        g.student = get_user_by_id(c, user_id())
    return g.student
예제 #10
0
파일: __init__.py 프로젝트: samkumar/ob2
def _get_student(c):
    if not hasattr(g, "student"):
        g.student = get_user_by_id(c, user_id())
    return g.student