コード例 #1
0
def move_membership(lti=None):
    # Get the attributes
    assignment_id = request.values.get('assignment_id', None)
    old_group_id = request.values.get('old_group_id', None)
    new_group_id = request.values.get('new_group_id', None)
    if None in (assignment_id, new_group_id, old_group_id):
        return jsonify(success=False, message="Need assignment_id, old_group_id, and new_group_id.")
    
    # Ensure that the assignment exists and that the user can modify it
    assignment = Assignment.by_id(int(assignment_id))
    if not g.user.is_instructor(assignment.course_id):
        return jsonify(success=False, message="You are not an instructor in this assignment's course.")
        
    # Verify permissions
    if int(new_group_id) != -1:
        new_assignment_group = AssignmentGroup.by_id(int(new_group_id))
        if not g.user.is_instructor(new_assignment_group.course_id):
            return jsonify(success=False, message="You are not an instructor in this assignment's course.")
    if int(old_group_id) != -1:
        old_assignment_group = AssignmentGroup.by_id(int(old_group_id))
        if not g.user.is_instructor(old_assignment_group.course_id):
            return jsonify(success=False, message="You are not an instructor in this assignment's course.")
    # Perform action
    AssignmentGroupMembership.move_assignment(int(assignment_id), int(new_group_id))
    # Result
    return jsonify(success=True)
コード例 #2
0
ファイル: assignment_groups.py プロジェクト: briandk/blockpy
def remove_group(lti=lti):
    assignment_group_id = request.values.get('assignment_group_id', None)
    if assignment_group_id is None:
        return jsonify(success=False, message="No assignment group id")
    user, roles, course = ensure_canvas_arguments()
    if not User.is_lti_instructor(roles):
        return jsonify(success=False, message="You are not an instructor in this course.")
    AssignmentGroup.remove(assignment_group_id)
    return jsonify(success=True)
コード例 #3
0
def remove_group(lti=lti):
    assignment_group_id = request.values.get('assignment_group_id', None)
    if assignment_group_id is None:
        return jsonify(success=False, message="No assignment group id")
    user, roles, course = ensure_canvas_arguments()
    if not User.is_lti_instructor(roles):
        return jsonify(success=False,
                       message="You are not an instructor in this course.")
    AssignmentGroup.remove(assignment_group_id)
    return jsonify(success=True)
コード例 #4
0
ファイル: assignment_groups.py プロジェクト: briandk/blockpy
def edit_group(lti=lti):
    assignment_group_id = request.values.get('assignment_group_id', None)
    new_name = request.values.get('new_name', None)
    if None in (assignment_group_id, new_name):
        return jsonify(success=False, message="No assignment group id, or no new_name given.")
    user, roles, course = ensure_canvas_arguments()
    print user, roles, course
    if not User.is_lti_instructor(roles):
        return jsonify(success=False, message="You are not an instructor in this course.")
    AssignmentGroup.edit(assignment_group_id, name=new_name)
    return jsonify(success=True)
コード例 #5
0
ファイル: lti.py プロジェクト: scareface972/blockpy
def select(lti=lti):
    """ Let's the user select from a list of assignments.
    """
    # Store current user_id and context_id
    user, roles, course = ensure_canvas_arguments()
    assignments = Assignment.by_course(course.id, exclude_builtins=True)
    groups = [(group, group.get_assignments())
              for group in AssignmentGroup.by_course(course.id)]
    strays = AssignmentGroup.get_ungrouped_assignments(course.id)
    return_url = session['launch_presentation_return_url']
    
    return render_template('lti/select.html', assignments=assignments, strays=strays, groups=groups, return_url=return_url, menu='select')
コード例 #6
0
def edit_group(lti=lti):
    assignment_group_id = request.values.get('assignment_group_id', None)
    new_name = request.values.get('new_name', None)
    if None in (assignment_group_id, new_name):
        return jsonify(success=False,
                       message="No assignment group id, or no new_name given.")
    user, roles, course = ensure_canvas_arguments()
    print user, roles, course
    if not User.is_lti_instructor(roles):
        return jsonify(success=False,
                       message="You are not an instructor in this course.")
    AssignmentGroup.edit(assignment_group_id, name=new_name)
    return jsonify(success=True)
コード例 #7
0
def remove_group(lti=lti):
    ''' Removes a group from a course'''
    assignment_group_id = request.values.get('assignment_group_id', None)
    if assignment_group_id is None:
        return jsonify(success=False, message="No assignment group id")
    assignment_group = AssignmentGroup.by_id(int(assignment_group_id))
    # Verify permissions
    if not g.user.is_instructor(assignment_group.course_id):
        return jsonify(success=False, message="You are not an instructor in this course.")
    # Perform action
    AssignmentGroup.remove(assignment_group.id)
    # Result
    return jsonify(success=True)
コード例 #8
0
def remove_group(lti=lti):
    ''' Removes a group from a course'''
    assignment_group_id = request.values.get('assignment_group_id', None)
    if assignment_group_id is None:
        return jsonify(success=False, message="No assignment group id")
    assignment_group = AssignmentGroup.by_id(int(assignment_group_id))
    # Verify permissions
    if not g.user.is_instructor(assignment_group.course_id):
        return jsonify(success=False,
                       message="You are not an instructor in this course.")
    # Perform action
    AssignmentGroup.remove(assignment_group.id)
    # Result
    return jsonify(success=True)
コード例 #9
0
ファイル: lti.py プロジェクト: scareface972/blockpy
def share(lti=lti):
    """ render the contents of the staff.html template

    :param lti: the `lti` object from `pylti`
    :return: the staff.html template rendered
    """
    user, roles, course = ensure_canvas_arguments()
    assignments = Assignment.by_course(course.id, exclude_builtins=True)
    groups = [(group, group.get_assignments())
              for group in AssignmentGroup.by_course(course.id)]
    strays = AssignmentGroup.get_ungrouped_assignments(course.id)
    return_url = session['launch_presentation_return_url']
    
    return render_template('lti/select.html', assignments=assignments, strays=strays, groups=groups, return_url=return_url, menu='share')
コード例 #10
0
def edit_group(lti=lti):
    # Get arguments
    assignment_group_id = request.values.get('assignment_group_id', None)
    if assignment_group_id is None:
        return jsonify(success=False, message="No assignment group id.")
    assignment_group = AssignmentGroup.by_id(int(assignment_group_id))
    new_name = request.values.get('new_name', None)
    if new_name is None:
        return jsonify(success=False, message="No new_name given.")
    # Verify permissions
    if not g.user.is_instructor(assignment_group.course_id):
        return jsonify(success=False, message="You are not an instructor in this group's course.")
    # Perform action
    group = AssignmentGroup.edit(int(assignment_group_id), name=new_name)
    # Result
    return jsonify(success=True, name = group.name)
コード例 #11
0
ファイル: helpers.py プロジェクト: awfssv/Blockpy-Server
def get_assignments_from_request():
    assignment_id = request.args.get('assignment_id', None)
    assignment_group_id = request.args.get('assignment_group_id', None)
    if 'course_id' in request.args:
        course_id = int(request.args.get('course_id'))
    if 'course_id' in request.form:
        course_id = int(request.form.get('course_id'))
    if 'user' in g and g.user != None:
        user_id = g.user.id
    else:
        user_id = None
    if 'course' in g:
        course_id = g.course.id
    else:
        course_id = None
    submission_url = request.form.get('lis_result_sourcedid', '')
    # Assignment group or individual assignment?
    if assignment_group_id is not None:
        group = AssignmentGroup.by_id(int(assignment_group_id) if assignment_group_id != None else None)
        assignments = natsorted(group.get_assignments(), key = lambda a: a.title())
        submissions = [a.get_submission(user_id, course_id=course_id, submission_url=submission_url) for a in assignments]
    elif assignment_id is not None:
        assignment = Assignment.by_id(int(assignment_id) if assignment_id != None else None)
        assignments = [assignment] if assignment else []
        submissions = [assignment.get_submission(user_id, course_id=course_id, submission_url=submission_url)] if assignment else []
    else:
        assignments = []
        submissions = []
    return assignments, submissions
コード例 #12
0
def add_group(lti=lti):
    ''' Adds a group to a course'''
    # Get arguments
    course_id = request.values.get('course_id', None)
    if course_id is None:
        return jsonify(success=False, message="No course id")
    new_name = request.values.get('name', None)
    if new_name is None:
        return jsonify(success=False, message="No name given.")
    # Verify permissions
    if not g.user.is_instructor(int(course_id)):
        return jsonify(
            success=False,
            message="You are not an instructor in this group's course.")
    # Perform action
    assignment_group = AssignmentGroup.new(owner_id=g.user.id,
                                           course_id=int(course_id),
                                           name=new_name)

    menu = request.values.get('menu', "select")
    launch_type = 'lti_launch_url' if menu != 'embed' else 'iframe'
    endpoint = 'assignments.load'
    select = url_quote(
        url_for(endpoint,
                assignment_group_id=assignment_group.id,
                _external=True,
                embed=menu == 'embed')
    ) + "&return_type=" + launch_type + "&title=" + url_quote(
        assignment_group.name
    ) + "&text=BlockPy%20Exercise&width=100%25&height=600"
    # Result
    return jsonify(success=True,
                   id=assignment_group.id,
                   name=assignment_group.name,
                   select=select)
コード例 #13
0
ファイル: lti.py プロジェクト: scareface972/blockpy
def index(lti=lti):
    """ initial access page to the lti provider.  This page provides
    authorization for the user.

    :param lti: the `lti` object from `pylti`
    :return: index page for lti provider
    """
    assignment_id = request.args.get('assignment_id', None)
    assignment_group_id = request.args.get('assignment_group_id', None)
    user, roles, course = ensure_canvas_arguments()
    # Assignment group or individual assignment?
    if assignment_group_id is not None:
        group = AssignmentGroup.by_id(assignment_group_id)
        assignments = group.get_assignments()
        submissions = [a.get_submission(user.id) for a in assignments]
    elif assignment_id is not None:
        assignments = [Assignment.by_id(assignment_id)]
        submissions = [assignments[0].get_submission(user.id)]
    else:
        return error()
    # Use the proper template
    if assignments[0].mode == 'maze':
        return render_template('lti/maze.html', lti=lti,
                               assignment= assignments[0], 
                               submission= submissions[0],
                               level=assignments[0].name)
    elif assignments[0].mode == 'explain':
        return render_template('lti/explain.html', lti=lti,
                               assignment= assignments[0], 
                               submission= submissions[0])
    else:
        return render_template('lti/index.html', lti=lti,
                               group=zip(assignments, submissions))
コード例 #14
0
ファイル: helpers.py プロジェクト: RealTimeWeb/Blockpy-Server
def get_assignments_from_request():
    assignment_id = request.args.get('assignment_id', None)
    assignment_group_id = request.args.get('assignment_group_id', None)
    if 'course_id' in request.args:
        course_id = int(request.args.get('course_id'))
    if 'course_id' in request.form:
        course_id = int(request.form.get('course_id'))
    if 'user' in g and g.user != None:
        user_id = g.user.id
    else:
        user_id = None
    if 'course' in g:
        course_id = g.course.id
    else:
        course_id = None
    submission_url = request.form.get('lis_result_sourcedid', '')
    # Assignment group or individual assignment?
    if assignment_group_id is not None:
        group = AssignmentGroup.by_id(int(assignment_group_id) if assignment_group_id != None else None)
        assignments = group.get_assignments()
        submissions = [a.get_submission(user_id, course_id=course_id, submission_url=submission_url) for a in assignments]
    elif assignment_id is not None:
        assignment = Assignment.by_id(int(assignment_id) if assignment_id != None else None)
        assignments = [assignment] if assignment else []
        submissions = [assignment.get_submission(user_id, course_id=course_id, submission_url=submission_url)] if assignment else []
    else:
        assignments = []
        submissions = []
    return assignments, submissions
コード例 #15
0
ファイル: lti.py プロジェクト: scareface972/blockpy
def shared(lti=lti):
    """ render the contents of the assignment template

    :param lti: the `lti` object from `pylti`
    :return: the staff.html template rendered
    """
    assignment_id = request.args.get('assignment_id', None)
    assignment_group_id = request.args.get('assignment_group_id', None)
    user, roles, course = ensure_canvas_arguments()
    # Assignment group or individual assignment?
    if assignment_group_id is not None:
        group = AssignmentGroup.by_id(assignment_group_id)
        assignments = group.get_assignments()
        submissions = [a.get_submission(user.id) for a in assignments]
    elif assignment_id is not None:
        assignments = [Assignment.by_id(assignment_id)]
        submissions = [assignments[0].get_submission(user.id)]
    else:
        return error()
    # Use the proper template
    if assignments[0].mode == 'maze':
        return render_template('lti/maze.html', lti=lti,
                               assignment= assignments[0], 
                               submission= submissions[0],
                               level=assignments[0].name)
    elif assignments[0].mode == 'explain':
        return render_template('lti/explain.html', lti=lti,
                               assignment= assignments[0], 
                               submission= submissions[0])
    else:
        return render_template('lti/index.html', lti=lti,
                               group=zip(assignments, submissions))
コード例 #16
0
ファイル: courses.py プロジェクト: awfssv/Blockpy-Server
def view_assignments(course_id):
    #TODO: ensure in course
    course = Course.by_id(course_id)
    assignments = Assignment.by_course(course_id)
    groups = AssignmentGroup.by_course(course_id)
    
    return render_template('courses/view_assignments.html', assignments=assignments, groups=groups, course=course, course_id=course_id)
コード例 #17
0
def select(lti=lti):
    """ Let's the user select from a list of assignments.
    """
    # Store current user_id and context_id
    user, roles, course = ensure_canvas_arguments()
    assignments = Assignment.by_course(course.id, exclude_builtins=True)
    groups = [(group, group.get_assignments())
              for group in AssignmentGroup.by_course(course.id)]
    strays = AssignmentGroup.get_ungrouped_assignments(course.id)
    return_url = session['launch_presentation_return_url']

    return render_template('lti/select.html',
                           assignments=assignments,
                           strays=strays,
                           groups=groups,
                           return_url=return_url,
                           menu='select')
コード例 #18
0
def edit_group(lti=lti):
    # Get arguments
    assignment_group_id = request.values.get('assignment_group_id', None)
    if assignment_group_id is None:
        return jsonify(success=False, message="No assignment group id.")
    assignment_group = AssignmentGroup.by_id(int(assignment_group_id))
    new_name = request.values.get('new_name', None)
    if new_name is None:
        return jsonify(success=False, message="No new_name given.")
    # Verify permissions
    if not g.user.is_instructor(assignment_group.course_id):
        return jsonify(
            success=False,
            message="You are not an instructor in this group's course.")
    # Perform action
    group = AssignmentGroup.edit(int(assignment_group_id), name=new_name)
    # Result
    return jsonify(success=True, name=group.name)
コード例 #19
0
ファイル: courses.py プロジェクト: d-demirci/blockpy-server
def view_assignments(course_id):
    if not g.user.in_course(course_id):
        return redirect(url_for('courses.index'))
    course = Course.by_id(course_id)
    assignments = Assignment.by_course(course_id)
    groups = AssignmentGroup.by_course(course_id)

    return render_template('courses/view_assignments.html', assignments=assignments,
                           groups=groups, course=course,
                           course_id=course_id)
コード例 #20
0
def add_group(lti=lti):
    user, roles, course = ensure_canvas_arguments()
    if not User.is_lti_instructor(roles):
        return jsonify(success=False,
                       message="You are not an instructor in this course.")
    assignment_group = AssignmentGroup.new(owner_id=user.id,
                                           course_id=course.id)
    return jsonify(success=True,
                   id=assignment_group.id,
                   name=assignment_group.name)
コード例 #21
0
ファイル: lti.py プロジェクト: awfssv/Blockpy-Server
def share(lti=lti):
    """ render the contents of the staff.html template

    :param lti: the `lti` object from `pylti`
    :return: the staff.html template rendered
    """
    user, roles, course = ensure_canvas_arguments()
    assignments = Assignment.by_course(course.id, exclude_builtins=True)
    groups = [(group, group.get_assignments())
              for group in AssignmentGroup.by_course(course.id)]
    strays = AssignmentGroup.get_ungrouped_assignments(course.id)
    return_url = session['launch_presentation_return_url']

    return render_template('lti/select.html',
                           assignments=assignments,
                           strays=strays,
                           groups=groups,
                           return_url=return_url,
                           menu='share')
コード例 #22
0
def get_group_score(group_id, user_id, course_id, hide_correctness):
    group = AssignmentGroup.by_id(group_id)
    assignments = natsorted(group.get_assignments(), key=lambda a: a.title())
    submissions = [
        a.get_submission(user_id, course_id=course_id) for a in assignments
    ]
    completed = sum([s.correct or s.status / 100 for s in submissions])
    total = len(assignments)
    score = completed / total
    return score
コード例 #23
0
def move_membership(lti=None):
    # Get the attributes
    assignment_id = request.values.get('assignment_id', None)
    old_group_id = request.values.get('old_group_id', None)
    new_group_id = request.values.get('new_group_id', None)
    if None in (assignment_id, new_group_id, old_group_id):
        return jsonify(
            success=False,
            message="Need assignment_id, old_group_id, and new_group_id.")

    # Ensure that the assignment exists and that the user can modify it
    assignment = Assignment.by_id(int(assignment_id))
    if not g.user.is_instructor(assignment.course_id):
        return jsonify(
            success=False,
            message="You are not an instructor in this assignment's course.")

    # Verify permissions
    if int(new_group_id) != -1:
        new_assignment_group = AssignmentGroup.by_id(int(new_group_id))
        if not g.user.is_instructor(new_assignment_group.course_id):
            return jsonify(
                success=False,
                message="You are not an instructor in this assignment's course."
            )
    if int(old_group_id) != -1:
        old_assignment_group = AssignmentGroup.by_id(int(old_group_id))
        if not g.user.is_instructor(old_assignment_group.course_id):
            return jsonify(
                success=False,
                message="You are not an instructor in this assignment's course."
            )
    # Perform action
    AssignmentGroupMembership.move_assignment(int(assignment_id),
                                              int(new_group_id))
    # Result
    return jsonify(success=True)
コード例 #24
0
def add_group(lti=lti):
    ''' Adds a group to a course'''
    # Get arguments
    course_id = request.values.get('course_id', None)
    if course_id is None:
        return jsonify(success=False, message="No course id")
    new_name = request.values.get('name', None)
    if new_name is None:
        return jsonify(success=False, message="No name given.")
    # Verify permissions
    if not g.user.is_instructor(int(course_id)):
        return jsonify(success=False, message="You are not an instructor in this group's course.")
    # Perform action
    assignment_group = AssignmentGroup.new(owner_id=g.user.id, course_id=int(course_id), name=new_name)
    # Result
    return jsonify(success=True, id=assignment_group.id, name=assignment_group.name)
コード例 #25
0
def index(lti=lti):
    """ initial access page to the lti provider.  This page provides
    authorization for the user.

    :param lti: the `lti` object from `pylti`
    :return: index page for lti provider
    """
    assignment_id = request.args.get('assignment_id', None)
    assignment_group_id = request.args.get('assignment_group_id', None)
    user, roles, course = ensure_canvas_arguments()
    # Assignment group or individual assignment?
    if assignment_group_id is not None:
        group = AssignmentGroup.by_id(assignment_group_id)
        assignments = group.get_assignments()
        submissions = [a.get_submission(user.id) for a in assignments]
    elif assignment_id is not None:
        assignments = [Assignment.by_id(assignment_id)]
        submissions = [assignments[0].get_submission(user.id)]
    else:
        return error()
    if 'ip_address_found' not in session or session[
            'ip_address_found'] != request.remote_addr:
        session['ip_address_found'] = request.remote_addr
        log_user_ip(user.id)
    # Use the proper template
    if assignments[0].mode == 'maze':
        return render_template('lti/maze.html',
                               lti=lti,
                               assignment=assignments[0],
                               submission=submissions[0],
                               level=assignments[0].name,
                               user_id=user.id)
    elif assignments[0].mode == 'explain':
        MAX_QUESTIONS = 5
        code, elements = submissions[0].load_explanation(MAX_QUESTIONS)
        return render_template('lti/explain.html',
                               lti=lti,
                               assignment=assignments[0],
                               submission=submissions[0],
                               code=code,
                               elements=elements,
                               user_id=user.id)
    else:
        return render_template('lti/index.html',
                               lti=lti,
                               group=zip(assignments, submissions),
                               user_id=user.id)
コード例 #26
0
ファイル: lti.py プロジェクト: acbart/lti-flask-skeleton
def index(lti=lti):
    """ initial access page to the lti provider.  This page provides
    authorization for the user.

    :param lti: the `lti` object from `pylti`
    :return: index page for lti provider
    """
    assignment_id = request.args.get('assignment_id', None)
    assignment_group_id = request.args.get('assignment_group_id', None)
    user, roles, course = ensure_canvas_arguments()
    # Assignment group or individual assignment?
    if assignment_group_id is not None:
        group = AssignmentGroup.by_id(assignment_group_id)
        assignments = group.get_assignments()
        submissions = [a.get_submission(user.id) for a in assignments]
    elif assignment_id is not None:
        assignments = [Assignment.by_id(assignment_id)]
        submissions = [assignments[0].get_submission(user.id)]
    else:
        return error()
    if 'ip_address_found' not in session or session['ip_address_found'] != request.remote_addr:
        session['ip_address_found'] = request.remote_addr
        log_user_ip(user.id)
    # Use the proper template
    if assignments[0].mode == 'maze':
        return render_template('lti/maze.html', lti=lti,
                               assignment= assignments[0], 
                               submission= submissions[0],
                               level=assignments[0].name,
                               user_id=user.id)
    elif assignments[0].mode == 'explain':
        MAX_QUESTIONS = 5
        code, elements = submissions[0].load_explanation(MAX_QUESTIONS)
        return render_template('lti/explain.html', lti=lti,
                               assignment= assignments[0], 
                               submission= submissions[0],
                               code = code,
                               elements=elements,
                               user_id=user.id)
    else:
        return render_template('lti/index.html', lti=lti,
                               group=zip(assignments, submissions),
                               user_id=user.id)
コード例 #27
0
def get_group_report(group_id, user_id, course_id, hide_correctness):
    group = AssignmentGroup.by_id(group_id)
    assignments = natsorted(group.get_assignments(), key=lambda a: a.title())
    submissions = [
        a.get_submission(user_id, course_id=course_id) for a in assignments
    ]
    completed = sum([s.correct or s.status / 100 for s in submissions])
    total = len(assignments)
    score = completed / total
    table = "\n".join([
        "<li><a href='#{slug}'>{name}</a> {completed}</li>".format(
            slug=slugify(a.name),
            name=a.name,
            completed=(
                " - " +
                "Completed" if s.correct else "<strong>Incomplete</strong>")
            if not hide_correctness else "")
        for a, s in zip(assignments, submissions)
    ])
    overview = '''
    <h1>Overview</h1>
    <div>Status: {completed}/{total} problems</div>
    <div>Score: {score}%</div>
    <div>Contents:
    <ol>
        {table}
    </ol></div>
    '''.format(completed=completed if not hide_correctness else '?',
               total=total,
               score=int(10000 * score) / 100 if not hide_correctness else '?',
               table=table)
    complete = overview + '<br><br>'.join([
        get_report(assignment.type, assignment.name, submission,
                   submission.get_block_image(), hide_correctness)
        for assignment, submission in zip(assignments, submissions)
    ]) + '<br><small>{uid}/{cid}/{aids}</small>'.format(
        uid=user_id,
        cid=course_id,
        aids=','.join([str(a.id) for a in assignments]))
    complete = '<div xml:lang="en">' + complete + '</div>'
    return score, complete
コード例 #28
0
def shared(lti=lti):
    """ render the contents of the assignment template

    :param lti: the `lti` object from `pylti`
    :return: the staff.html template rendered
    """
    print "REACHED"
    assignment_id = request.args.get('assignment_id', None)
    assignment_group_id = request.args.get('assignment_group_id', None)
    user, roles, course = ensure_canvas_arguments()
    # Assignment group or individual assignment?
    if assignment_group_id is not None:
        group = AssignmentGroup.by_id(assignment_group_id)
        assignments = group.get_assignments()
        submissions = [a.get_submission(user.id) for a in assignments]
    elif assignment_id is not None:
        assignments = [Assignment.by_id(assignment_id)]
        submissions = [assignments[0].get_submission(user.id)]
    else:
        return error()
    # Use the proper template
    if assignments[0].mode == 'maze':
        return render_template('lti/maze.html',
                               lti=lti,
                               assignment=assignments[0],
                               submission=submissions[0],
                               level=assignments[0].name,
                               user_id=user.id)
    elif assignments[0].mode == 'explain':
        return render_template('lti/explain.html',
                               lti=lti,
                               assignment=assignments[0],
                               submission=submissions[0],
                               user_id=user.id)
    else:
        return render_template('lti/index.html',
                               lti=lti,
                               group=zip(assignments, submissions),
                               user_id=user.id)
コード例 #29
0
def add_group(lti=lti):
    ''' Adds a group to a course'''
    # Get arguments
    course_id = request.values.get('course_id', None)
    if course_id is None:
        return jsonify(success=False, message="No course id")
    new_name = request.values.get('name', None)
    if new_name is None:
        return jsonify(success=False, message="No name given.")
    # Verify permissions
    if not g.user.is_instructor(int(course_id)):
        return jsonify(
            success=False,
            message="You are not an instructor in this group's course.")
    # Perform action
    assignment_group = AssignmentGroup.new(owner_id=g.user.id,
                                           course_id=int(course_id),
                                           name=new_name)
    # Result
    return jsonify(success=True,
                   id=assignment_group.id,
                   name=assignment_group.name)
コード例 #30
0
    def run(self, user_data_file, **kwargs):
        from models.models import Role, User, Course, Assignment, CourseAssignment, AssignmentGroup, AssignmentGroupMembership

        print("Adding Admin")
        admin = User(first_name='Cory',
                     last_name='Bart',
                     password=encrypt_password('password'),
                     confirmed_at=datetime.datetime.now(),
                     active=True,
                     email='*****@*****.**',
                     gender='Male')
        db.session.add(admin)
        db.session.flush()
        db.session.add(Role(name='instructor', user_id=admin.id))
        db.session.add(Role(name='admin', user_id=admin.id))

        print("Adding some students for color")
        for student in ('Dan Tilden', 'Anamary Leal', 'Ellie Cayford'):
            first, last = student.split()
            email = '{}{}@vt.edu'.format(first[0].lower(), last.lower())
            user = User(first_name=first, last_name=last, email=email)
            db.session.add(user)

        print("Adding default course")
        default_course = Course(name="Computational Thinking",
                                owner_id=admin.id,
                                service="native")
        db.session.add(default_course)
        db.session.flush()

        print("Adding public course")
        public_course = Course(name="Public Course",
                               owner_id=admin.id,
                               service="native",
                               visibility='public')
        db.session.add(public_course)
        db.session.flush()
        db.session.add(
            Role(name='instructor',
                 course_id=public_course.id,
                 user_id=admin.id))

        print("Adding local Canvas course")
        canvas_course = Course(
            name="Computational Thinking - Dev",
            owner_id=admin.id,
            service='canvas',
            visibility='private',
            external_id='cbdd860576c6c08ccb998b93009305c318bd269b')
        db.session.add(canvas_course)
        db.session.flush()

        print("Adding CS1 course")
        cs1_course = Course(name="CS 1",
                            owner_id=user.id,
                            service='canvas',
                            visibility='private')
        db.session.add(cs1_course)
        db.session.flush()

        print("Adding some assignments")
        assignment1 = Assignment(name="Assignment #1",
                                 body="a=b+c",
                                 course_id=default_course.id,
                                 owner_id=admin.id)
        db.session.add(assignment1)
        assignment2 = Assignment(name="Assignment #2",
                                 body="Figure it out!",
                                 course_id=default_course.id,
                                 owner_id=admin.id)
        db.session.add(assignment2)
        assignment3 = Assignment(name="Assignment #3",
                                 body="Clue",
                                 course_id=default_course.id,
                                 owner_id=admin.id)
        db.session.add(assignment3)

        ca1 = CourseAssignment(course_id=public_course.id,
                               assignment_id=assignment1.id)
        db.session.add(ca1)
        ca2 = CourseAssignment(course_id=public_course.id,
                               assignment_id=assignment2.id)
        db.session.add(ca2)

        ag1 = AssignmentGroup(name="Day 1 - Decision",
                              course_id=default_course.id)
        db.session.add(ag1)
        ag2 = AssignmentGroup(name="Day 2 - Iteration",
                              course_id=default_course.id)
        db.session.add(ag2)
        db.session.commit()

        db.session.add(
            AssignmentGroupMembership(assignment_group_id=ag1.id,
                                      assignment_id=assignment1.id))
        db.session.add(
            AssignmentGroupMembership(assignment_group_id=ag1.id,
                                      assignment_id=assignment2.id))
        db.session.add(
            AssignmentGroupMembership(assignment_group_id=ag2.id,
                                      assignment_id=assignment3.id))

        db.session.commit()
        print("Complete")
コード例 #31
0
ファイル: assignment_groups.py プロジェクト: briandk/blockpy
def add_group(lti=lti):
    user, roles, course = ensure_canvas_arguments()
    if not User.is_lti_instructor(roles):
        return jsonify(success=False, message="You are not an instructor in this course.")
    assignment_group = AssignmentGroup.new(owner_id=user.id, course_id=course.id)
    return jsonify(success=True, id=assignment_group.id, name=assignment_group.name)