Exemple #1
0
def __inject_flask_g(*args, **kwargs):
    if str(request.url_rule) == '/static/<path:filename>':
        return
    homeworks = HwSet(app.config['HOMEWORK_DIR'],[''])
    if current_user.is_authenticated():
        mongouser = app.config['USERS_COLLECTION'].find_one({"_id": current_user.name})
        if mongouser is None:
            session['course'] = None
            return
        if len(mongouser['course']) != 0:
            session['course'] = mongouser['course']
        if session.get('course') is not None:
            problem_dict = mongouser['problem_list']
            course_name = session['course']
            course = app.config['COURSE_COLLECTION'].find_one({"name": course_name})
            if course == None or not(os.path.isdir(os.path.join(app.config['HOMEWORK_DIR_FOR_CLASS'],course_name))):
                session['course'] = None
                return
            if not os.path.isdir(course["path"]):
                session['course'] = None
                if app.config['COURSE_COLLECTION'].count({"name":course}) > 0:
                    app.config['COURSE_COLLECTION'].remove({"name":course})
                return
            problem_list = problem_dict.get(course_name,'key_error')
            if current_user.is_admin:
                problem_list = course['problem_list']
            if (not current_user.is_admin) and (problem_list == 'key_error' or (len(problem_list) == 0) or (not_int_list(problem_list,course['problem_list'])) or (not_cover_list(problem_list,course['problem_list']))) and (len(course['problem_list']) != 0):
                problem_list = getproblemlist(course['problem_list'],app.config['HOMEWORK_NUM'])
                problem_dict.update({course_name:problem_list})
                app.config['USERS_COLLECTION'].remove({"_id":mongouser['_id']})
                app.config['USERS_COLLECTION'].insert({"_id":mongouser['_id'],"password":mongouser['password'],"problem_list":problem_dict,"course":mongouser['course']})
            string = str(problem_list)
            course_path = os.path.join(app.config['COURSE_HOMEWORK_DIR'],course_name)
            if string == "key_error":
                homeworks = HwSet(course_path,[''])
            else:
                tmplist = string.split('@')
                list = [item for item in tmplist]
                homeworks = HwSet(course_path,list)
    g.homeworks = HwSetProxy(homeworks)
    # g.utcnow will be used in templates/homework.html to determine some
    # visual styles
    g.utcnow = utc_now()
Exemple #2
0
def __inject_flask_g(*args, **kwargs):
    g.homeworks = HwSetProxy(homeworks)
    # g.utcnow will be used in templates/homework.html to determine some
    # visual styles
    g.utcnow = utc_now()
Exemple #3
0
def __inject_flask_g(*args, **kwargs):
    g.homeworks = HwSetProxy(homeworks)
    g.allhws = HwSetProxy(homeworks, select_all=True)
    # g.utcnow will be used in templates/homework.html to determine some
    # visual styles
    g.utcnow = utc_now()