예제 #1
0
def api_exam_qtemplates(course_id, exam_id):
    """ Return a JSON list of all the qtemplates used for the given exam.
    """
    user_id = session['user_id']
    if not satisfy_perms(user_id, course_id, ("examcreate", )):
        abort(401)

    if exam_id == 0:  # New assessment may be being created
        return jsonify(result=[
            [
                {
                    'qtid': 0
                },
            ],
        ])

    exam = Exams.get_exam_struct(exam_id)
    ecid = exam['cid']
    if not ecid == course_id:  # They may be trying to bypass permission check
        abort(401)

    qtemplates = []
    try:
        qtemplates = Exams.get_qts_list(exam_id)
    except KeyError:
        abort(401)

    return jsonify(result=qtemplates)
예제 #2
0
def setup_usersummary(view_id):
    """ Show an account summary for the given user account. """
    user_id = session['user_id']

    if not check_perm(user_id, -1, "useradmin"):
        flash("You do not have User Administration access.")
        return redirect(url_for('setup_top'))

    is_sysadmin = check_perm(user_id, -1, 'sysadmin')

    user = Users2.get_user(view_id)
    examids = Exams.get_exams_done(view_id)
    exams = []
    for examid in examids:
        exam = Exams.get_exam_struct(examid)
        started = General.human_date(exam['start'])
        exam['started'] = started

        exam['viewable'] = satisfy_perms(user_id, exam['cid'], ("viewmarks", ))

        exams.append(exam)
    exams.sort(key=lambda x: x['start_epoch'], reverse=True)

    course_ids = Users2.get_courses(view_id)
    courses = []
    for course_id in course_ids:
        courses.append(Courses2.get_course(course_id))

    user_is_admin = check_perm(view_id, 0, 'sysadmin')
    return render_template('setup_usersummary.html',
                           user=user,
                           exams=exams,
                           courses=courses,
                           is_sysadmin=is_sysadmin,
                           user_is_admin=user_is_admin)
예제 #3
0
def api_qedit2_get_qtemplate_json(qt_id):
    """ Present a list of qtemplates that are available for use in the exam."""
    if 'user_id' not in session:
        abort(401)
    user_id = session['user_id']
    topic_id = DB.get_topic_for_qtemplate(qt_id)
    course_id = Topics.get_course_id(topic_id)
    if not satisfy_perms(user_id, course_id, ("questionedit",)):
        abort(401)

    # test data while we're building the frontend
    return jsonify(result={
        'type': "qtemplate data",
        'title': "Test QE2 Question",
        'embed_id': "aaaaaaaaa3",
        'maxscore': 3,
        'pre_vars': [
            {'id': 1, 'name': "a", 'type': 'List', 'value': "2,3,4,5,6,7"},
            {'id': 2, 'name': "b", 'type': 'Range', 'value': "1-10"},
            {'id': 3, 'name': "a1", 'type': 'Calculation', 'value': "$a+$b"},
            {'id': 4, 'name': "a2", 'type': 'Calculation', 'value': "$a*$b"},
        ],
        'qtext': "What is $a + $b ? <answer1>\nWhat is $a * $b?  <answer2> ",
        'answers': [
            {'id': 1, 'source': 'Variable', 'value': '$a1', 'tolerance': 0, 'score': 1},
            {'id': 2, 'source': 'Variable', 'value': '$a2', 'tolerance': 0, 'score': 1}
        ]
    })
예제 #4
0
def api_exam_available_qtemplates(course_id, exam_id):
    """ Present a list of qtemplates that are available for use in the exam."""
    if 'user_id' not in session:
        abort(401)
    user_id = session['user_id']
    if not satisfy_perms(user_id, course_id, ("examcreate",)):
        abort(401)

    return jsonify(result=API.exam_available_q_list(course_id))
예제 #5
0
def api_exam_available_qtemplates(course_id, exam_id):
    """ Present a list of qtemplates that are available for use in the exam."""
    if 'user_id' not in session:
        abort(401)
    user_id = session['user_id']
    if not satisfy_perms(user_id, course_id, ("examcreate", )):
        abort(401)

    return jsonify(result=API.exam_available_q_list(course_id))
예제 #6
0
def cadmin_edit_topic(course_id, topic_id):
    """ Present a page to view and edit a topic, including adding/editing
        questions and setting some parameters.
    """
    user_id = session['user_id']

    if not course_id:
        abort(404)

    course = Courses2.get_course(course_id)
    topic = {
        'id': topic_id,
        'position': Topics.get_pos(topic_id),
        'name': Topics.get_name(topic_id)
    }
    questions = [question
                 for question in Topics.get_qts(topic_id).values()]
    for question in questions:
        question['embed_id'] = DB.get_qt_embedid(question['id'])
        if question['embed_id']:
            question['embed_url'] = "%s/embed/question/%s/question.html" % \
                                    (OaConfig.parentURL, question['embed_id'])
        else:
            question['embed_url'] = None
        question['editor'] = DB.get_qt_editor(question['id'])

    all_courses = Courses2.get_course_list()
    all_courses = [crse
                   for crse in all_courses
                   if satisfy_perms(user_id, int(crse['id']),
                                    ("questionedit", "courseadmin",
                                    "sysadmin"))]
    all_courses.sort(lambda f, s: cmp(f['name'], s['name']))

    all_course_topics = []
    for crse in all_courses:
        topics = Courses.get_topics_all(crse['id'], numq=False)
        if topics:
            all_course_topics.append({'course': crse['name'], 'topics': topics})

    questions.sort(key=lambda k: k['position'])
    return render_template(
        "courseadmin_edittopic.html",
        course=course,
        topic=topic,
        questions=questions,
        all_course_topics=all_course_topics
    )
예제 #7
0
def cadmin_view_topic(course_id, topic_id):
    """ Present a page to view a topic, including basic stats """
    user_id = session['user_id']

    if not course_id:
        abort(404)

    course = Courses2.get_course(course_id)
    topic = {
        'id': topic_id,
        'position': Topics.get_pos(topic_id),
        'name': Topics.get_name(topic_id)
    }
    questions = [question for question in Topics.get_qts(topic_id).values()]
    for question in questions:
        question['embed_id'] = DB.get_qt_embedid(question['id'])
        if question['embed_id']:
            question['embed_url'] = "%s/embed/question/%s/question.html" % \
                                    (OaConfig.parentURL, question['embed_id'])
        else:
            question['embed_url'] = None
        question['editor'] = DB.get_qt_editor(question['id'])

    all_courses = [
        crse for crse in Courses2.get_course_list()
        if satisfy_perms(user_id, int(crse['id']), ("questionedit",
                                                    "courseadmin", "sysadmin"))
    ]
    all_courses.sort(lambda f, s: cmp(f['name'], s['name']))

    all_course_topics = []
    for crse in all_courses:
        topics = Courses.get_topics_all(crse['id'], numq=False)
        if topics:
            all_course_topics.append({
                'course': crse['name'],
                'topics': topics
            })

    questions.sort(key=lambda k: k['position'])
    return render_template(
        "courseadmin_viewtopic.html",
        course=course,
        topic=topic,
        questions=questions,
        all_course_topics=all_course_topics,
    )
예제 #8
0
파일: __init__.py 프로젝트: ehchua/oasisqe
        def call_fn(*args, **kwargs):
            """ check auth first, can't have perms if we're not.
            """
            if 'user_id' not in session:
                session['redirect'] = request.path
                return redirect(url_for('index'))

            user_id = session['user_id']

            if isinstance(perms, str):
                permlist = (perms, )
            else:
                permlist = perms

            if satisfy_perms(user_id, 0, permlist):
                return func(*args, **kwargs)
            flash("You do not have permission to do that.")
            return redirect(url_for(redir))
예제 #9
0
파일: __init__.py 프로젝트: tkanesh/oasisqe
        def call_fn(*args, **kwargs):
            """ check auth first, can't have perms if we're not.
            """
            if 'user_id' not in session:
                session['redirect'] = request.path
                return redirect(url_for('index'))

            user_id = session['user_id']

            if isinstance(perms, str):
                permlist = (perms,)
            else:
                permlist = perms

            if satisfy_perms(user_id, 0, permlist):
                return func(*args, **kwargs)
            flash("You do not have permission to do that.")
            return redirect(url_for(redir))
예제 #10
0
def cadmin_view_topic(course_id, topic_id):
    """ Present a page to view a topic, including basic stats """
    user_id = session["user_id"]

    if not course_id:
        abort(404)

    course = Courses2.get_course(course_id)
    topic = {"id": topic_id, "position": Topics.get_pos(topic_id), "name": Topics.get_name(topic_id)}
    questions = [question for question in Topics.get_qts(topic_id).values()]
    for question in questions:
        question["embed_id"] = DB.get_qt_embedid(question["id"])
        if question["embed_id"]:
            question["embed_url"] = "%s/embed/question/%s/question.html" % (OaConfig.parentURL, question["embed_id"])
        else:
            question["embed_url"] = None
        question["editor"] = DB.get_qt_editor(question["id"])

    all_courses = Courses2.get_course_list()
    all_courses = [
        crse
        for crse in all_courses
        if satisfy_perms(user_id, int(crse["id"]), ("questionedit", "courseadmin", "sysadmin"))
    ]
    all_courses.sort(lambda f, s: cmp(f["name"], s["name"]))

    all_course_topics = []
    for crse in all_courses:
        topics = Courses.get_topics_all(crse["id"], numq=False)
        if topics:
            all_course_topics.append({"course": crse["name"], "topics": topics})

    questions.sort(key=lambda k: k["position"])
    return render_template(
        "courseadmin_viewtopic.html",
        course=course,
        topic=topic,
        questions=questions,
        all_course_topics=all_course_topics,
    )
예제 #11
0
def api_exam_qtemplates(course_id, exam_id):
    """ Return a JSON list of all the qtemplates used for the given exam.
    """
    user_id = session['user_id']
    if not satisfy_perms(user_id, course_id, ("examcreate",)):
        abort(401)

    if exam_id == 0:   # New assessment may be being created
        return jsonify(result=[[{'qtid': 0}, ], ])

    exam = Exams.get_exam_struct(exam_id)
    ecid = exam['cid']
    if not ecid == course_id:   # They may be trying to bypass permission check
        abort(401)

    qtemplates = []
    try:
        qtemplates = Exams.get_qts_list(exam_id)
    except KeyError:
        abort(401)

    return jsonify(result=qtemplates)
예제 #12
0
def setup_usersummary(view_id):
    """ Show an account summary for the given user account. """
    user_id = session['user_id']

    if not check_perm(user_id, -1, "useradmin"):
        flash("You do not have User Administration access.")
        return redirect(url_for('setup_top'))

    is_sysadmin = check_perm(user_id, -1, 'sysadmin')

    user = Users2.get_user(view_id)
    examids = Exams.get_exams_done(view_id)
    exams = []
    for examid in examids:
        exam = Exams.get_exam_struct(examid)
        started = General.human_date(exam['start'])
        exam['started'] = started

        exam['viewable'] = satisfy_perms(user_id, exam['cid'], ("viewmarks", ))

        exams.append(exam)
    exams.sort(key=lambda x: x['start_epoch'], reverse=True)

    course_ids = Users2.get_courses(view_id)
    courses = []
    for course_id in course_ids:
        courses.append(Courses.get_course(course_id))

    user_is_admin = check_perm(view_id, 0, 'sysadmin')
    return render_template(
        'setup_usersummary.html',
        user=user,
        exams=exams,
        courses=courses,
        is_sysadmin=is_sysadmin,
        user_is_admin=user_is_admin
    )