Ejemplo n.º 1
0
def get_offer_by_id(offer_id):
    wants_json = request_wants_json()
    try:
        offer = api.get_offer_by_id(offer_id, json=wants_json)
        return jsonify({'offer': offer})
    except api.DbNotFoundError:
        abort(404)
Ejemplo n.º 2
0
def get_lab_by_id(lab_id):
    wants_json = request_wants_json()
    try:
        lab = api.get_course_by_id("lab", lab_id, json=wants_json)
    except api.DbNotFoundError:
        abort(404)

    return jsonify({"lab": lab}) if wants_json else render_template("couse_page.html", course=lab)
Ejemplo n.º 3
0
def get_lecture_by_id(lecture_id):
    wants_json = request_wants_json()

    try:
        lecture = api.get_course_by_id('lecture', lecture_id, json=wants_json)
    except api.DbNotFoundError:
        abort(404)

    return jsonify({'lecture': lecture}) if wants_json else render_template('course_page.html', course=lecture)
Ejemplo n.º 4
0
def get_sections_for_lecture(lecture_id):
    wants_json = request_wants_json()

    try:
        sections = api.get_sections_for_lecture(lecture_id, json=wants_json)
    except api.DbNotFoundError:
        abort(404)

    return jsonify({'section': sections}) if wants_json else render_template('section.html', sections=sections)
Ejemplo n.º 5
0
def get_section_by_id(section_id):
    wants_json = request_wants_json()

    try:
        section = api.get_course_by_id('section', section_id, json=wants_json)
    except api.DbNotFoundError:
        abort(404)

    return jsonify({'section': section}) if wants_json else render_template('course_page.html', course=section)
Ejemplo n.º 6
0
def student_swapblock(student_id):
    wants_json = request_wants_json()

    try:
        swapblock = api.get_student_swapblock(student_id, json=wants_json)
    except api.DbNotFoundError:
        abort(404)

    return jsonify({'swapblock': swapblock})
Ejemplo n.º 7
0
def all_swapblocks():
    wants_json = request_wants_json()

    try:
        blocks = api.get_all_swapblocks(json=wants_json)
    except api.DbNotFoundError:
        abort(404, message='There are no swablocks')

    return jsonify({'swapblocks': blocks})
Ejemplo n.º 8
0
def get_all_lectures():
    page_number = request.args.get('page')
    wants_json = request_wants_json()

    try:
        lectures = api.get_courses(class_type='lecture', pagination=page_number is not None,
                                   page=page_number, json=wants_json)
    except api.DbNotFoundError:
        abort(404)

    return jsonify({'lectures': lectures}) if wants_json else render_template('lecture.html', lectures=lectures)
Ejemplo n.º 9
0
def get_lecture_by_department(department):
    page_number = request.args.get('page')
    wants_json = request_wants_json()

    try:
        lectures = api.get_courses(class_type='lecture', pagination=page_number is not None,
                                   page=page_number, json=wants_json, department=department)
    except api.DbNotFoundError:
        abort(404)

    return jsonify({'lectures': lectures})
Ejemplo n.º 10
0
def get_lab_by_department(department):
    wants_json = request_wants_json()
    page_number = request.args.get("page")
    try:
        labs = api.get_courses(
            "lab", pagination=page_number is not None, page=page_number, json=wants_json, department=department
        )
    except api.DbNotFoundError:
        abort(404)

    return jsonify({"labs": labs})
Ejemplo n.º 11
0
def get_all_sections():
    page_number = request.args.get('page')
    wants_json = request_wants_json()

    try:
        sections = api.get_courses('section', pagination=page_number is not None, page=page_number,
                                   json=wants_json)
    except api.DbNotFoundError:
        abort(404)

    return jsonify({'sections': sections})
Ejemplo n.º 12
0
def add_or_get_offers():
    wants_json = request_wants_json()
    params = json.loads(request.form['params'])
    try:
        if request.method == 'GET':
            offers = api.get_all_offers(json=wants_json)
            return jsonify({'offer': offers})
        elif request.method == 'POST':
            api.create_offer(**params)
            resp = jsonify(message='success!')
            resp.status_code = 201
            return resp
    except api.DbNotFoundError:
        abort(404)