コード例 #1
0
ファイル: admin.py プロジェクト: pablooliveira/tigergrader
def admin():
    conf = GraderConfiguration()
    modules = app.config["MODULES"]

    if request.method == 'POST':
        if "_registration" in request.form:
            conf["registration"] = "open"
        else:
            conf["registration"] = "closed"
        active_modules = []
        for m in modules:
            if m in request.form:
                active_modules.append(m)
        conf["active_modules"] = ",".join(active_modules)
        flash("Active modules updated")
        return redirect(url_for('admin'))
    else:
        registration_active = conf["registration"] == "open"
        active_modules = get_active_modules()
        module_active = dict([(m, m in active_modules) for m in modules])

        all_grades_raw = query_db('select * from (select test, user, \
                timestamp, grade, upload from grades \
                order by grade ASC, timestamp DESC) \
                as tmp group by test, user')

        groups = []
        emails = []
        for u in query_db('select user, emails from users order by user'):
            if u != app.config["ADMIN_USERNAME"]:
                groups.append(u["user"])
                emails.append(u["emails"])

        all_grades = dict([(g, {}) for g in groups])
        for g in all_grades_raw:
            if g["user"] not in groups:
                continue
            all_grades[g["user"]][g["test"]] = dict(grade=g["grade"],
                                                    timestamp=g["timestamp"],
                                                    upload=g["upload"])

        return render_template('admin.html',
                               all_grades=all_grades,
                               groups_emails=zip(groups, emails),
                               modules=modules,
                               module_active=module_active,
                               registration_active=registration_active,
                               user=session["username"])
コード例 #2
0
ファイル: student.py プロジェクト: pablooliveira/tigergrader
def submit(test):

    if test not in get_active_modules():
        flash("Module does not seem to exist or is inactive.")
        return redirect(url_for('index'))

    f = request.files['file']
    if f and request.method == 'POST':
        filename = str(uuid.uuid1())

        # Create upload folder if it does not exists
        if not os.path.exists(app.config['UPLOAD_FOLDER']):
            os.makedirs(app.config['UPLOAD_FOLDER'])

        dest = os.path.join(app.config['UPLOAD_FOLDER'], filename)
        f.save(dest)
        task = grade.delay(os.path.abspath(dest), test, session["username"])

        return render_template('waiting.html', test=test, task=task,
                               timeout=app.config['SUBMISSION_TIMEOUT'])
    else:
        return render_template('upload.html', test=test)