Пример #1
0
def homework_download(courseid, homeworkid, studentuserid):
    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)
    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 check_homework_exist
    res = check_homework_exist(homeworkid)
    if res == False:
        return jsonify(res=PERMISSION_DENIED)

    if '.' in studentuserid:
        import os
        path = os.path.realpath(__file__).split('/')[:-2]
        path = '/'.join(path) + '/course/%s/homework/%s'%(courseid, homeworkid)
        filename = studentuserid
        return send_from_directory(path.encode('utf-8'), filename, as_attachment=True)
    else:
        import os
        path = os.path.realpath(__file__).split('/')[:-2]
        path = '/'.join(path) + '/course/%s/homework/%s'%(courseid, homeworkid)
        all_file = os.walk(path)
        for (a,b,c) in all_file:
            for item in c:
                if item.split('.')[0] == studentuserid:
                    filename = item
        return redirect('/homework/download/%s/%s/%s'%(courseid,homeworkid,filename))
Пример #2
0
def upload_namelist(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)

    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']
    import os
    path = os.path.realpath(__file__)
    path = '/'.join(path[:-2]) + '/tmp/%s.csv'%courseid
    f.save(path)

    from lib import add_userlist_from_csv
    add_userlist_from_csv(path)

    return jsonify(res=SUCCESS)
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
0
def login():
    cookies = request.cookies
    if 'session' in cookies:
        session = cookies['session']
        from lib import get_userid_by_session
        userid = get_userid_by_session(session)
        if userid != None:
            return redirect('/')
    else:
        from lib import generate_session
        session = generate_session()
    resp = make_response(render_template('login.html'))
    resp.set_cookie('session', session, max_age=1200)
    return resp
Пример #7
0
def info():
    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)

    from lib import get_info_by_id
    user_info = get_info_by_id(userid)

    return jsonify(res=SUCCESS, info=user_info)
Пример #8
0
def homework_list(courseid, homeworkid):
    cookies = request.cookies
    if 'session' in cookies:
        session = cookies['session']
        from lib import get_userid_by_session
        userid = get_userid_by_session(session)
        if userid == None:
            return redirect('/login')
        else:
            from lib import is_teacher
            if is_teacher(userid):
                resp = make_response(render_template('homework_admin.html', courseid=courseid, homeworkid=homeworkid))
            else:
                resp = make_response(render_template('course.html', courseid=courseid))
            return resp
    else:
        return redirect('/login')
Пример #9
0
def index():
    cookies = request.cookies
    if 'session' in cookies:
        session = cookies['session']
        from lib import get_userid_by_session
        userid = get_userid_by_session(session)
        if userid == None:
            return redirect('/login')
        else:
            from lib import is_teacher
            if is_teacher(userid):
                resp = make_response(render_template('index_admin.html'))
            else:
                resp = make_response(render_template('index.html'))
            return resp
    else:
        return redirect('/login')
Пример #10
0
def getcourse_list():
    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 check_user_is_teacher
    res = check_user_is_teacher(userid)
    from lib import get_course_by_userid
    course_list = get_course_by_userid(userid, res)

    return jsonify(res=SUCCESS, course=course_list)
Пример #11
0
def course_teacher_info(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)

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

    from lib import get_course_teacher_info_by_courseid
    teacher = get_course_teacher_info_by_courseid(courseid)
    return jsonify(res=SUCCESS, teacher=teacher)
Пример #12
0
def downloads(courseid):
    cookies = request.cookies
    if 'session' in cookies:
        session = cookies['session']
        from lib import get_userid_by_session
        userid = get_userid_by_session(session)
        if userid == None:
            return redirect('/login')
        else:
            from lib import check_user_is_teacher
            isteacher = check_user_is_teacher(userid)

            from lib import check_attend_course
            res = check_attend_course(userid, courseid, isteacher)
            if res == False:
                return jsonify(res=PERMISSION_DENIED)
            if isteacher:
                return render_template('downloads_teacher.html', courseid=courseid)
            else:
                return render_template('downloads.html', courseid=courseid)
    else:
        return redirect('/login')
Пример #13
0
def update():
    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
    require = ['email', 'phone', 'name', 'studentid']
    for item in require:
        if not item in form:
            return jsonify(res=PARAMETER_WRONG)

    email = form['email']
    phone = form['phone']
    name = form['name']
    studentid = form['studentid']

    from lib import update_user_info
    update_user_info(email, phone, name, studentid, userid)
    return jsonify(res=SUCCESS)
Пример #14
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)
Пример #15
0
def homework_submit(courseid, homeworkid):
    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)

    if request.method == 'POST':

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

        from lib import check_homework_exist
        res = check_homework_exist(homeworkid)
        if res == False:
            return jsonify(res=PERMISSION_DENIED)

        files = request.files
        f = files['file']
        filename = f.filename
        filetype = filename.split('.')[-1]
        filename = userid + '.' + filetype

        import os
        path = os.path.realpath(__file__).split('/')[:-2]
        dirpath = '/'.join(path) + '/course/%s/homework/%s'%(courseid, homeworkid)
        os.system("mkdir -p %s"%dirpath)
        path = '/'.join(path) + '/course/%s/homework/%s/%s'%(courseid, homeworkid, filename)
        f.save(path)

        from lib import homework_submit
        homework_submit(userid, homeworkid)

        return jsonify(res=SUCCESS)
    else:
        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 check_homework_exist
        res = check_homework_exist(homeworkid)
        if res == False:
            return jsonify(res=PERMISSION_DENIED)

        from lib import get_studentlist_by_courseid
        studentlist = get_studentlist_by_courseid(courseid)

        from lib import get_homeworksubmit_by_homeworkid
        homeworksubmit = get_homeworksubmit_by_homeworkid(homeworkid)

        res = []
        for item in studentlist:
            if item[0] in homeworksubmit:
                res.append({'userid':item[0],'name':item[1],'studentid':item[2],'issubmit':'1'})
            else:
                res.append({'userid':item[0],'name':item[1],'studentid':item[2],'issubmit':'0'})
        return jsonify(res=SUCCESS, homework=res)