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)
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
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))
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))
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
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
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)
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)
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)
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)
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)
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)
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
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)