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)
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)
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} ] })
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))
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))
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 )
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, )
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))
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))
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, )
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)
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 )