Exemplo n.º 1
0
def class_teachers(class_url):
    """ covered by test 0_classes / `Can get the teachers of a class`"""
    dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT)
    try:
        class_obj = dbw.get_class_or_error(class_url)
        return jsonify(teachers=class_obj["teachers"])
    except ClassDoesNotExistError as e:
        return jsonify({"error": "class not found!", "exception": str(e)}), 404
Exemplo n.º 2
0
def class_students(class_url):
    """ civered by test 0_classes / `Can list students in a class` """
    dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT)
    try:
        class_obj = dbw.get_class_or_error(class_url)
        return jsonify(students=class_obj["students"])
    except ClassDoesNotExistError as e:
        return jsonify({"error": "class not found!", "exception": str(e)}), 404
Exemplo n.º 3
0
def add_student(class_url):
    """ covered by test 0_classes / `Student can enroll in a class` """
    json_data = get_json_data()
    student = json_data.get("username")
    dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT)
    try:
        dbw.add_student_to_class(class_url, student)
    except ClassDoesNotExistError as e:
        return jsonify({"error": "class not found!", "exception": str(e)}), 404
    except UserDoesNotExistError as e:
        return jsonify({"error": "username not found!", "exception": str(e)}), 404

    return jsonify(class_updated=dbw.get_class_or_error(class_url))
Exemplo n.º 4
0
def add_teacher(class_url):
    """ covered by test 0_classes / `Teacher can add other teachers to class they own` """
    json_data = get_json_data()
    teacher = json_data.get("username")
    dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT)

    try:
        dbw.add_teacher_to_class(class_url, teacher)
    except ClassDoesNotExistError as e:
        return jsonify({"error": "class not found!", "exception": str(e)}), 404
    except UserDoesNotExistError as e:
        return jsonify({"error": "username not found!", "exception": str(e)}), 404

    return jsonify(class_updated=dbw.get_class_or_error(class_url))
Exemplo n.º 5
0
def get_class(class_url):
    dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT)
    return jsonify({"class": dbw.get_class_or_error(class_url)})