Beispiel #1
0
def resource_upload(courseid):
    cookies = request.cookies
    if not 'session' in cookies:
        return jsonify(res=PARAMETER_WRONG)
    session = cookies['session']
    # session = '111111'
    from lib import get_userid_by_session
    userid = get_userid_by_session(session)
    if userid == None:
        return jsonify(res=USER_NOT_LOGIN_IN)

    from lib import get_name_by_userid
    name = get_name_by_userid(userid)
    name = name.decode('utf-8')

    from lib import check_is_course_teacher
    res = check_is_course_teacher(userid, courseid)
    if res == False:
        return jsonify(res=PERMISSION_DENIED)

    files = request.files
    f = files['file']
    filename = f.filename
    import os
    path = os.path.realpath(__file__).split('/')[:-2]
    path = '/'.join(path) + '/course/%s/resource/%s'%(courseid, filename)
    f.save(path)

    from lib import add_resource_by_courseid
    add_resource_by_courseid(courseid, filename)
    from lib import add_news_by_courseid
    add_news_by_courseid(courseid, filename, name, 1)

    return jsonify(res=SUCCESS)
Beispiel #2
0
def course_add_news(courseid):
    cookies = request.cookies
    if not 'session' in cookies:
        return jsonify(res=PARAMETER_WRONG)
    session = cookies['session']
    from lib import get_userid_by_session
    userid = get_userid_by_session(session)
    if userid == None:
        return jsonify(res=USER_NOT_LOGIN_IN)

    form = request.form
    if not 'notice' in form:
        return jsonify(res=PARAMETER_WRONG)
    notice = form['notice']

    from lib import get_name_by_userid
    name = get_name_by_userid(userid)
    name = name.decode('utf-8')

    from lib import check_is_course_teacher
    res = check_is_course_teacher(userid, courseid)

    if res == False:
        return jsonify(res=PERMISSION_DENIED)

    from lib import add_news_by_courseid
    add_news_by_courseid(courseid, notice, name, 3)
    return jsonify(res=SUCCESS)
Beispiel #3
0
def add_homework(courseid):
    cookies = request.cookies
    if not 'session' in cookies:
        return jsonify(res=PARAMETER_WRONG)
    session = cookies['session']
    # session = '111111'
    from lib import get_userid_by_session
    userid = get_userid_by_session(session)
    if userid == None:
        return jsonify(res=USER_NOT_LOGIN_IN)

    from lib import get_name_by_userid
    name = get_name_by_userid(userid)
    name = name.decode('utf-8')

    from lib import check_is_course_teacher
    res = check_is_course_teacher(userid, courseid)
    if res == False:
        return jsonify(res=PERMISSION_DENIED)

    form = request.form
    if not 'description' in form or not 'deadline' in form:
        return jsonify(res=PARAMETER_WRONG)
    description = form['description']
    deadline = form['deadline']

    from lib import add_homework_by_courseid
    add_homework_by_courseid(courseid, description, deadline)

    from lib import add_news_by_courseid
    add_news_by_courseid(courseid, description, name, 2)

    return jsonify(res=SUCCESS)
Beispiel #4
0
def course_add():
    cookies = request.cookies
    if not 'session' in cookies:
        return jsonify(res=PARAMETER_WRONG)
    session = cookies['session']
    from lib import get_userid_by_session
    userid = get_userid_by_session(session)
    if userid == None:
        return jsonify(USER_NOT_LOGIN_IN)
    from lib import check_user_is_teacher
    res = check_user_is_teacher(userid)
    if res == False:
        return jsonify(res=PERMISSION_DENIED)
    form = request.form
    require = ['name', 'description', 'time', 'classroom']
    for item in require:
        if not item in form:
            return jsonify(res=PARAMETER_WRONG)

    name = form['name']
    description = form['description']
    time = form['time']
    classroom = form['classroom']

    from lib import get_name_by_userid
    teacher = get_name_by_userid(userid)
    teacher = teacher.decode('utf-8')

    files = request.files
    f = files['file']
    filename = f.filename
    f.save('tmp/' + filename)

    from lib import add_course
    add_course(teacher, name, description, time, classroom, filename)
    return jsonify(res=SUCCESS)