Example #1
0
def cadmin_top(course_id):
    """ Present top level course admin page """
    course = Courses2.get_course(course_id)
    if not course:
        abort(404)

    user_id = session['user_id']
    is_sysadmin = check_perm(user_id, -1, 'sysadmin')

    topics = Courses2.get_topics_list(course_id)
    exams = [
        Exams.get_exam_struct(exam_id, course_id)
        for exam_id in Courses.get_exams(course_id, prev_years=False)
    ]

    exams.sort(key=lambda y: y['start_epoch'], reverse=True)
    groups = Courses.get_groups(course_id)
    choosegroups = [
        group for group in Groups.all_groups() if group.id not in groups
    ]
    return render_template("courseadmin_top.html",
                           course=course,
                           topics=topics,
                           exams=exams,
                           choosegroups=choosegroups,
                           groups=groups,
                           is_sysadmin=is_sysadmin)
Example #2
0
def practice_choose_topic(course_id):
    """ Present a list of topics for them to choose from the given course """
    user_id = session['user_id']
    try:
        course = Courses2.get_course(course_id)
    except KeyError:
        course = None
        abort(404)
    try:
        topics = Courses2.get_topics_list(course_id)
    except KeyError:
        topics = []
        abort(404)

    members = None
    for topic in topics:
        if topic['visibility'] == 2:  # course only
            if not members:
                members = Courses.get_users(course_id)
            if not user_id in members:
                topics.remove(topic)
    return render_template(
        "practicecourse.html",
        courses=Setup.get_sorted_courselist(),
        canpreview=check_perm(user_id, course_id, "questionpreview"),
        topics=topics,
        course=course
    )
Example #3
0
def practice_choose_topic(course_id):
    """ Present a list of topics for them to choose from the given course """
    user_id = session['user_id']
    try:
        course = Courses2.get_course(course_id)
    except KeyError:
        course = None
        abort(404)
    try:
        topics = Courses2.get_topics_list(course_id)
    except KeyError:
        topics = []
        abort(404)

    members = None
    for topic in topics:
        if topic['visibility'] == 2:  # course only
            if not members:
                members = Courses.get_users(course_id)
            if user_id not in members:
                topics.remove(topic)
    return render_template(
        "practicecourse.html",
        courses=Setup.get_sorted_courselist(),
        canpreview=check_perm(user_id, course_id, "questionpreview"),
        topics=topics,
        course=course
    )
Example #4
0
def cadmin_top(course_id):
    """ Present top level course admin page """
    course = Courses2.get_course(course_id)
    if not course:
        abort(404)

    user_id = session['user_id']
    is_sysadmin = check_perm(user_id, -1, 'sysadmin')

    topics = Courses2.get_topics_list(course_id)
    exams = [Exams.get_exam_struct(exam_id, course_id)
             for exam_id in Courses.get_exams(course_id, prev_years=False)]

    exams.sort(key=lambda y: y['start_epoch'], reverse=True)
    groups = Courses.get_groups(course_id)
    choosegroups = [group
                    for group in Groups.all_groups()
                    if group.id not in groups]
    return render_template(
        "courseadmin_top.html",
        course=course,
        topics=topics,
        exams=exams,
        choosegroups=choosegroups,
        groups=groups,
        is_sysadmin=is_sysadmin
    )
Example #5
0
def cadmin_edittopics(course_id):
    """ Present a page to view and edit all topics, including hidden. """
    course = None
    try:
        course = Courses2.get_course(course_id)
    except KeyError:
        abort(404)

    if not course:
        abort(404)

    topics = Courses2.get_topics_list(course_id)
    return render_template("courseadmin_edittopics.html", course=course, topics=topics)
Example #6
0
def cadmin_edittopics(course_id):
    """ Present a page to view and edit all topics, including hidden. """
    course = None
    try:
        course = Courses2.get_course(course_id)
    except KeyError:
        abort(404)

    if not course:
        abort(404)

    topics = Courses2.get_topics_list(course_id)
    return render_template("courseadmin_edittopics.html",
                           course=course,
                           topics=topics)
Example #7
0
def practice_choose_question(topic_id):
    """ Present a list of questions for them to choose from the given topic """
    user_id = session['user_id']
    try:
        course_id = Topics.get_course_id(topic_id)
    except KeyError:
        course_id = None
        abort(404)
    topics = []
    try:
        topics = Courses2.get_topics_list(course_id)
    except KeyError:
        abort(404)
    try:
        course = Courses2.get_course(course_id)
    except KeyError:
        course = None
        abort(404)
    topictitle = Topics.get_name(topic_id)
    questions = Practice.get_sorted_questions(course_id, topic_id, user_id)

    thistopic = Topics.get_topic(topic_id)
    members = []
    if thistopic['visibility'] == 2:  # course only
        if not members:
            members = Courses.get_users(course_id)
            if not user_id in members:
                abort(404)

    for topic in topics:
        if topic['visibility'] == 2:  # course only
            if not members:
                members = Courses.get_users(course_id)
            if not user_id in members:
                topics.remove(topic)

    return render_template(
        "practicetopic.html",
        canpreview=check_perm(user_id, course_id, "questionpreview"),
        topics=topics,
        topic_id=topic_id,
        course=course,
        topictitle=topictitle,
        questions=questions
    )
Example #8
0
def practice_choose_question(topic_id):
    """ Present a list of questions for them to choose from the given topic """
    user_id = session['user_id']
    try:
        course_id = Topics.get_course_id(topic_id)
    except KeyError:
        course_id = None
        abort(404)
    topics = []
    try:
        topics = Courses2.get_topics_list(course_id)
    except KeyError:
        abort(404)
    try:
        course = Courses2.get_course(course_id)
    except KeyError:
        course = None
        abort(404)
    topictitle = Topics.get_name(topic_id)
    questions = Practice.get_sorted_questions(course_id, topic_id, user_id)

    thistopic = Topics.get_topic(topic_id)
    members = []
    if thistopic['visibility'] == 2:  # course only
        if not members:
            members = Courses.get_users(course_id)
            if user_id not in members:
                abort(404)

    for topic in topics:
        if topic['visibility'] == 2:  # course only
            if not members:
                members = Courses.get_users(course_id)
            if user_id not in members:
                topics.remove(topic)

    return render_template(
        "practicetopic.html",
        canpreview=check_perm(user_id, course_id, "questionpreview"),
        topics=topics,
        topic_id=topic_id,
        course=course,
        topictitle=topictitle,
        questions=questions
    )
Example #9
0
def practice_choose_question_stats(topic_id):
    """ Present a list of questions for them to choose from the given topic,
        and show some statistics on how they're doing.
    """
    user_id = session['user_id']

    course_id = Topics.get_course_id(topic_id)
    if not course_id:
        abort(404)

    topics = Courses2.get_topics_list(course_id)
    course = Courses2.get_course(course_id)
    topictitle = Topics.get_name(topic_id)
    questions = Practice.get_sorted_qlist_wstats(course_id, topic_id, user_id)

    return render_template(
        "practicetopicstats.html",
        canpreview=check_perm(user_id, course_id, "questionpreview"),
        topics=topics,
        topic_id=topic_id,
        course=course,
        topictitle=topictitle,
        questions=questions
    )
Example #10
0
def practice_choose_question_stats(topic_id):
    """ Present a list of questions for them to choose from the given topic,
        and show some statistics on how they're doing.
    """
    user_id = session['user_id']

    course_id = Topics.get_course_id(topic_id)
    if not course_id:
        abort(404)

    topics = Courses2.get_topics_list(course_id)
    course = Courses2.get_course(course_id)
    topictitle = Topics.get_name(topic_id)
    questions = Practice.get_sorted_qlist_wstats(course_id, topic_id, user_id)

    return render_template(
        "practicetopicstats.html",
        canpreview=check_perm(user_id, course_id, "questionpreview"),
        topics=topics,
        topic_id=topic_id,
        course=course,
        topictitle=topictitle,
        questions=questions
    )