Exemplo n.º 1
0
def get_assignment(lti=lti):
    '''
    Returns metadata about the assignment.
    '''
    assignment_id = request.values.get('assignment_id', None)
    if assignment_id is None:
        return jsonify(success=False, message="No assignment 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.")
    # TODO: Security hole, evil instructors could remove assignments outside of their course
    assignment = Assignment.by_id(assignment_id)
    return jsonify(success=True,
                   url=assignment.url,
                   name=assignment.name,
                   body=strip_tags(assignment.body)[:255],
                   on_run=assignment.on_run,
                   title=assignment.title(),
                   answer=assignment.answer,
                   type=assignment.type,
                   visibility=assignment.visibility,
                   disabled=assignment.disabled,
                   mode=assignment.mode,
                   version=assignment.version,
                   id=assignment.id,
                   course_id=assignment.course_id,
                   date_modified=assignment.date_modified.strftime(
                       " %I:%M%p on %a %d, %b %Y").replace(" 0", " "))
Exemplo n.º 2
0
def new_assignment(lti=lti):
    user, roles, course = ensure_canvas_arguments()
    menu = request.values.get('menu', "select")
    if not User.is_lti_instructor(roles):
        return "You are not an instructor in this course."
    assignment = Assignment.new(owner_id=user.id, course_id=course.id)
    launch_type = 'lti_launch_url' if menu != 'share' else 'iframe'
    endpoint = 'lti_assignments.index' if menu != 'share' else 'lti_assignments.shared'
    return jsonify(
        success=True,
        redirect=url_for('lti_assignments.edit_assignment',
                         assignment_id=assignment.id),
        id=assignment.id,
        name=assignment.name,
        body=strip_tags(assignment.body)[:255],
        title=assignment.title(),
        select=url_quote(
            url_for(endpoint, assignment_id=assignment.id, _external=True)) +
        "&return_type=" + launch_type + "&title=" +
        url_quote(assignment.title()) +
        "&text=BlockPy%20Exercise&width=100%25&height=600",
        edit=url_for('lti_assignments.edit_assignment',
                     assignment_id=assignment.id),
        date_modified=assignment.date_modified.strftime(
            " %I:%M%p on %a %d, %b %Y").replace(" 0", " "))
Exemplo n.º 3
0
def batch_edit(lti=lti):
    user, roles, course = ensure_canvas_arguments()
    if not User.is_lti_instructor(roles):
        return "You are not an instructor in this course."
    assignments = Assignment.by_course(course.id)
    return render_template('lti/batch.html',
                           assignments=assignments,
                           user_id=user.id,
                           context_id=course.id)
Exemplo n.º 4
0
def batch_edit(lti=lti):
    user, roles, course = ensure_canvas_arguments()
    if not User.is_lti_instructor(roles):
        return "You are not an instructor in this course."
    assignments = Assignment.by_course(course.id)
    return render_template('lti/batch.html', 
                           assignments=assignments,
                           user_id=user.id,
                           context_id=course.id)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def move_group(lti=lti):
    assignment_id = request.values.get('assignment_id', None)
    new_group_id = request.values.get('new_group_id', None)
    if None in (assignment_id, new_group_id):
        return jsonify(success=False, message="Need assignment_id and new_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.")
    AssignmentGroupMembership.move_assignment(assignment_id, new_group_id)
    return jsonify(success=True)
Exemplo n.º 7
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)
Exemplo n.º 8
0
def get_submission_code(lti=lti):
    user, roles, course = ensure_canvas_arguments()
    submission_id = request.values.get('submission_id', None)
    if submission_id is None:
        return "Sorry, no submission ID was given."
    submission = Submission.query.get(submission_id)
    if User.is_lti_instructor(session["roles"]) or submission.user_id == user.id:
        return submission.code if submission.code else "#No code given!"
    else:
        return "Sorry, you do not have sufficient permissions to spy!"
Exemplo n.º 9
0
def remove_assignment(lti=lti):
    assignment_id = request.values.get('assignment_id', None)
    if assignment_id is None:
        return jsonify(success=False, message="No assignment 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.")
    # TODO: Security hole, evil instructors could remove assignments outside of their course
    Assignment.remove(assignment_id)
    return jsonify(success=True)
Exemplo n.º 10
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)
Exemplo n.º 11
0
def remove_assignment(lti=lti):
    assignment_id = request.values.get('assignment_id', None)
    if assignment_id is None:
        return jsonify(success=False, message="No assignment 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.")
    # TODO: Security hole, evil instructors could remove assignments outside of their course
    Assignment.remove(assignment_id)
    return jsonify(success=True)
Exemplo n.º 12
0
def save_presentation(lti=lti):
    assignment_id = request.form.get('question_id', None)
    if assignment_id is None:
        return jsonify(success=False, message="No Assignment ID given!")
    presentation = request.form.get('presentation', "")
    name = request.form.get('name', "")
    if User.is_lti_instructor(session["roles"]):
        Assignment.edit(assignment_id=assignment_id, presentation=presentation, name=name)
        return jsonify(success=True)
    else:
        return jsonify(success=False, message="You are not an instructor!")
Exemplo n.º 13
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)
Exemplo n.º 14
0
def get_submission_code(lti=lti):
    user, roles, course = ensure_canvas_arguments()
    submission_id = request.values.get('submission_id', None)
    if submission_id is None:
        return "Sorry, no submission ID was given."
    submission = Submission.query.get(submission_id)
    if User.is_lti_instructor(
            session["roles"]) or submission.user_id == user.id:
        return submission.code if submission.code else "#No code given!"
    else:
        return "Sorry, you do not have sufficient permissions to spy!"
Exemplo n.º 15
0
def move_group(lti=lti):
    assignment_id = request.values.get('assignment_id', None)
    new_group_id = request.values.get('new_group_id', None)
    if None in (assignment_id, new_group_id):
        return jsonify(success=False,
                       message="Need assignment_id and new_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.")
    AssignmentGroupMembership.move_assignment(assignment_id, new_group_id)
    return jsonify(success=True)
Exemplo n.º 16
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)
Exemplo n.º 17
0
def select_builtin_assignment(lti=lti):
    assignment_type = request.args.get('assignment_type', None)
    assignment_id = request.args.get('assignment_id', None)
    user, roles, course = ensure_canvas_arguments()
    if not User.is_lti_instructor(roles):
        return "You are not an instructor in this course."
    assignment = Assignment.by_builtin(assignment_type, assignment_id, 
                                       owner_id=user.id, course_id=course.id)
    assignment_url = url_for('lti_assignments.index', 
                                    assignment_id=assignment.id, 
                                    _external=True)
    print assignment_url
    encoded_url = url_quote(assignment_url)
    return jsonify(url=encoded_url)
Exemplo n.º 18
0
def edit_assignment(assignment_id, lti=lti):
    user, roles, course = ensure_canvas_arguments()
    assignment = Assignment.by_id(assignment_id)
    if not assignment:
        return "Assignment ID not found"
    if not User.is_lti_instructor(roles):
        return "You are not an instructor in this course."
    if not assignment.context_is_valid(course.external_id):
        return "This assignment does not belong to this course."
    submission = assignment.get_submission(user.id)
    
    return render_template('lti/edit.html', 
                           assignment=assignment, 
                           submission=submission, 
                           user_id=user.id,
                           context_id=course.id)
Exemplo n.º 19
0
def edit_assignment(assignment_id, lti=lti):
    user, roles, course = ensure_canvas_arguments()
    assignment = Assignment.by_id(assignment_id)
    if not assignment:
        return "Assignment ID not found"
    if not User.is_lti_instructor(roles):
        return "You are not an instructor in this course."
    if not assignment.context_is_valid(course.external_id):
        return "This assignment does not belong to this course."
    submission = assignment.get_submission(user.id)

    return render_template('lti/edit.html',
                           assignment=assignment,
                           submission=submission,
                           user_id=user.id,
                           context_id=course.id)
Exemplo n.º 20
0
def select_builtin_assignment(lti=lti):
    assignment_type = request.args.get('assignment_type', None)
    assignment_id = request.args.get('assignment_id', None)
    user, roles, course = ensure_canvas_arguments()
    if not User.is_lti_instructor(roles):
        return "You are not an instructor in this course."
    assignment = Assignment.by_builtin(assignment_type,
                                       assignment_id,
                                       owner_id=user.id,
                                       course_id=course.id)
    assignment_url = url_for('lti_assignments.index',
                             assignment_id=assignment.id,
                             _external=True)
    print assignment_url
    encoded_url = url_quote(assignment_url)
    return jsonify(url=encoded_url)
Exemplo n.º 21
0
def new_assignment(lti=lti):
    user, roles, course = ensure_canvas_arguments()
    menu = request.values.get('menu', "select")
    if not User.is_lti_instructor(roles):
        return "You are not an instructor in this course."
    assignment = Assignment.new(owner_id=user.id, course_id=course.id)
    launch_type = 'lti_launch_url' if menu != 'share' else 'iframe'
    endpoint = 'lti_assignments.index' if menu != 'share' else 'lti_assignments.shared'
    return jsonify(success=True,
                   redirect=url_for('lti_assignments.edit_assignment', assignment_id=assignment.id),
                   id= assignment.id,
                   name= assignment.name,
                   body= strip_tags(assignment.body)[:255],
                   title= assignment.title(),
                   select = url_quote(url_for(endpoint, assignment_id=assignment.id, _external=True))+"&return_type="+launch_type+"&title="+url_quote(assignment.title())+"&text=BlockPy%20Exercise&width=100%25&height=600",
                   edit= url_for('lti_assignments.edit_assignment', assignment_id=assignment.id),
                   date_modified = assignment.date_modified.strftime(" %I:%M%p on %a %d, %b %Y").replace(" 0", " "))
Exemplo n.º 22
0
def save_presentation(lti=lti):
    assignment_id = request.form.get('question_id', None)
    if assignment_id is None:
        return jsonify(success=False, message="No Assignment ID given!")
    presentation = request.form.get('presentation', "")
    parsons = request.form.get('parsons', "false") == "true"
    text_first = request.form.get('text_first', "false") == "true"
    name = request.form.get('name', "")
    if User.is_lti_instructor(session["roles"]):
        Assignment.edit(assignment_id=assignment_id,
                        presentation=presentation,
                        name=name,
                        parsons=parsons,
                        text_first=text_first)
        return jsonify(success=True)
    else:
        return jsonify(success=False, message="You are not an instructor!")
Exemplo n.º 23
0
def get_assignment(lti=lti):
    '''
    Returns metadata about the assignment.
    '''
    assignment_id = request.values.get('assignment_id', None)
    if assignment_id is None:
        return jsonify(success=False, message="No assignment 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.")
    # TODO: Security hole, evil instructors could remove assignments outside of their course
    assignment = Assignment.by_id(assignment_id)
    return jsonify(success=True, url=assignment.url, name=assignment.name,
                   body= strip_tags(assignment.body)[:255],
                   on_run=assignment.on_run,
                   title= assignment.title(),
                   answer=assignment.answer, type=assignment.type,
                   visibility=assignment.visibility, disabled=assignment.disabled,
                   mode=assignment.mode, version=assignment.version,
                   id=assignment.id, course_id=assignment.course_id,
                   date_modified = assignment.date_modified.strftime(" %I:%M%p on %a %d, %b %Y").replace(" 0", " "))
Exemplo n.º 24
0
def save_code(lti=lti):
    assignment_id = request.form.get('question_id', None)
    assignment_version = int(request.form.get('version', -1))
    if assignment_id is None:
        return jsonify(success=False, message="No Assignment ID given!")
    code = request.form.get('code', '')
    filename = request.form.get('filename', '__main__')
    user = User.from_lti("canvas", session["pylti_user_id"], 
                         session.get("user_email", ""),
                         session.get("lis_person_name_given", ""),
                         session.get("lis_person_name_family", ""))
    is_version_correct = True
    if filename == "__main__":
        submission, is_version_correct = Submission.save_code(user.id, assignment_id, code, assignment_version)
    elif User.is_lti_instructor(session["roles"]):
        if filename == "on_run":
            Assignment.edit(assignment_id=assignment_id, on_run=code)
        elif filename == "on_change":
            Assignment.edit(assignment_id=assignment_id, on_step=code)
        elif filename == "starting_code":
            Assignment.edit(assignment_id=assignment_id, on_start=code)
    return jsonify(success=True, is_version_correct=is_version_correct)
Exemplo n.º 25
0
def save_code(lti=lti):
    assignment_id = request.form.get('question_id', None)
    assignment_version = int(request.form.get('version', -1))
    if assignment_id is None:
        return jsonify(success=False, message="No Assignment ID given!")
    code = request.form.get('code', '')
    filename = request.form.get('filename', '__main__')
    user = User.from_lti("canvas", session["pylti_user_id"],
                         session.get("user_email", ""),
                         session.get("lis_person_name_given", ""),
                         session.get("lis_person_name_family", ""))
    is_version_correct = True
    if filename == "__main__":
        submission, is_version_correct = Submission.save_code(
            user.id, assignment_id, code, assignment_version)
    elif User.is_lti_instructor(session["roles"]):
        if filename == "on_run":
            Assignment.edit(assignment_id=assignment_id, on_run=code)
        elif filename == "on_change":
            Assignment.edit(assignment_id=assignment_id, on_step=code)
        elif filename == "starting_code":
            Assignment.edit(assignment_id=assignment_id, on_start=code)
    return jsonify(success=True, is_version_correct=is_version_correct)
Exemplo n.º 26
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)