def getAssignmentsHelper(courseId, currentUser, strout): try: vmcfg = StorerCourseConfig(CourseList().course_config(courseId)) except: traceback.print_exc(file = strout) return json.dumps({'errorType': ERR_EXCEPTION, 'errorMessage':"Unable to load course config", 'errorTrace':strout.get()}) assignments = vmcfg.assignments() sorted_assg = sorted(assignments, lambda x, y: int(assignments.get(x, "OrderNumber")) - int(assignments.get(y, "OrderNumber"))) assg_arr = [] vmpaths = paths.VmcheckerPaths(vmcfg.root_path()) with opening_course_db(vmpaths.db_file()) as course_db: for key in sorted_assg: if assignments.is_hidden(key) and not currentUser in vmcfg.admin_list(): continue a = {} a['assignmentId'] = key a['assignmentTitle'] = assignments.get(key, "AssignmentTitle") a['assignmentStorage'] = assignments.getd(key, "AssignmentStorage", "") if a['assignmentStorage'].lower() == "large": a['assignmentStorageHost'] = assignments.get(key, "AssignmentStorageHost") a['assignmentStorageBasepath'] = assignments.storage_basepath( \ assignments.get(key, "AssignmentStorageBasepath"), currentUser) a['deadline'] = assignments.get(key, "Deadline") a['statementLink'] = assignments.get(key, "StatementLink") team = course_db.get_user_team_for_assignment(key, currentUser) if team is not None: a['team'] = team assg_arr.append(a) return json.dumps(assg_arr)
def getAssignmentAccountName(courseId, assignmentId, username, strout): try: vmcfg = StorerCourseConfig(CourseList().course_config(courseId)) except: traceback.print_exc(file = strout) return json.dumps({'errorType' : ERR_EXCEPTION, 'errorMessage' : "", 'errorTrace' : strout.get()}) vmpaths = paths.VmcheckerPaths(vmcfg.root_path()) with opening_course_db(vmpaths.db_file()) as course_db: return course_db.get_assignment_account(assignmentId, username)
def getAssignmentAccountName(courseId, assignmentId, username, strout): try: vmcfg = StorerCourseConfig(CourseList().course_config(courseId)) except: traceback.print_exc(file=strout) return json.dumps({ 'errorType': ERR_EXCEPTION, 'errorMessage': "", 'errorTrace': strout.get() }) vmpaths = paths.VmcheckerPaths(vmcfg.root_path()) with opening_course_db(vmpaths.db_file()) as course_db: return course_db.get_assignment_account(assignmentId, username)
def getAssignmentsHelper(courseId, currentUser, strout): try: vmcfg = StorerCourseConfig(CourseList().course_config(courseId)) except: traceback.print_exc(file=strout) return json.dumps({ 'errorType': ERR_EXCEPTION, 'errorMessage': "Unable to load course config", 'errorTrace': strout.get() }) assignments = vmcfg.assignments() sorted_assg = sorted( assignments, lambda x, y: int(assignments.get(x, "OrderNumber")) - int( assignments.get(y, "OrderNumber"))) assg_arr = [] vmpaths = paths.VmcheckerPaths(vmcfg.root_path()) with opening_course_db(vmpaths.db_file()) as course_db: for key in sorted_assg: if assignments.is_hidden( key) and not currentUser in vmcfg.admin_list(): continue a = {} a['assignmentId'] = key a['assignmentTitle'] = assignments.get(key, "AssignmentTitle") a['assignmentStorage'] = assignments.getd(key, "AssignmentStorage", "") if a['assignmentStorage'].lower() == "large": a['assignmentStorageHost'] = assignments.get( key, "AssignmentStorageHost") a['assignmentStorageBasepath'] = assignments.storage_basepath( \ assignments.get(key, "AssignmentStorageBasepath"), currentUser) a['deadline'] = assignments.get(key, "Deadline") a['statementLink'] = assignments.get(key, "StatementLink") team = course_db.get_user_team_for_assignment(key, currentUser) if team is not None: a['team'] = team assg_arr.append(a) return json.dumps(assg_arr)
def getAllGradesHelper(courseId, username, strout): try: # XXX: DON'T DO THIS: performance degrades very much! #update_db.update_grades(courseId) vmcfg = StorerCourseConfig(CourseList().course_config(courseId)) vmpaths = paths.VmcheckerPaths(vmcfg.root_path()) assignments = vmcfg.assignments() sorted_assg = sorted(assignments, lambda x, y: int(assignments.get(x, "OrderNumber")) - int(assignments.get(y, "OrderNumber"))) # Check if the current user is allowed to view all the grades # TODO: This should be implemented neater using some group # and permission model. user_can_view_all = False if vmcfg.public_results() or username in vmcfg.admin_list(): user_can_view_all = True user_grade_rows = None team_grade_rows = None with opening_course_db(vmpaths.db_file()) as course_db: if user_can_view_all: user_grade_rows = course_db.get_user_grades() team_grade_rows = course_db.get_team_grades() else: # Get all the individual grades that the user is allowed to see user_grade_rows = course_db.get_user_and_teammates_grades(username) # Get all the team grades that the user is allowed to see team_grade_rows = course_db.get_user_team_grades(user = username) ret = [] grades = {} for row in user_grade_rows: user, assignment, grade = row if not assignment in vmcfg.assignments(): continue if not vmcfg.assignments().show_grades_before_deadline(assignment): deadline = time.strptime(vmcfg.assignments().get(assignment, 'Deadline'), DATE_FORMAT) deadtime = time.mktime(deadline) if time.time() < deadtime: continue if vmcfg.assignments().is_hidden(assignment) and username not in vmcfg.admin_list(): continue grades.setdefault(user, {})[assignment] = grade for user in sorted(grades.keys()): ret.append({'gradeOwner' : 'user', 'name' : user, 'results' : grades.get(user)}) grades = {} for row in team_grade_rows: team, assignment, grade = row if not assignment in vmcfg.assignments(): continue if not vmcfg.assignments().show_grades_before_deadline(assignment): deadline = time.strptime(vmcfg.assignments().get(assignment, 'Deadline'), DATE_FORMAT) deadtime = time.mktime(deadline) if time.time() < deadtime: continue grades.setdefault(team, {})[assignment] = grade for team in sorted(grades.keys()): ret.append({'gradeOwner' : 'team', 'name' : team, 'results' : grades.get(team)}) return json.dumps(ret) except: traceback.print_exc(file = strout) return json.dumps({'errorType' : ERR_EXCEPTION, 'errorMessage' : "", 'errorTrace' : strout.get()})
def getAllGradesHelper(courseId, username, strout): try: # XXX: DON'T DO THIS: performance degrades very much! #update_db.update_grades(courseId) vmcfg = StorerCourseConfig(CourseList().course_config(courseId)) vmpaths = paths.VmcheckerPaths(vmcfg.root_path()) assignments = vmcfg.assignments() sorted_assg = sorted( assignments, lambda x, y: int(assignments.get(x, "OrderNumber")) - int( assignments.get(y, "OrderNumber"))) # Check if the current user is allowed to view all the grades # TODO: This should be implemented neater using some group # and permission model. user_can_view_all = False if vmcfg.public_results() or username in vmcfg.admin_list(): user_can_view_all = True user_grade_rows = None team_grade_rows = None with opening_course_db(vmpaths.db_file()) as course_db: if user_can_view_all: user_grade_rows = course_db.get_user_grades() team_grade_rows = course_db.get_team_grades() else: # Get all the individual grades that the user is allowed to see user_grade_rows = course_db.get_user_and_teammates_grades( username) # Get all the team grades that the user is allowed to see team_grade_rows = course_db.get_user_team_grades(user=username) ret = [] grades = {} for row in user_grade_rows: user, assignment, grade = row if not assignment in vmcfg.assignments(): continue if not vmcfg.assignments().show_grades_before_deadline(assignment): deadline = time.strptime( vmcfg.assignments().get(assignment, 'Deadline'), DATE_FORMAT) deadtime = time.mktime(deadline) if time.time() < deadtime: continue if vmcfg.assignments().is_hidden( assignment) and username not in vmcfg.admin_list(): continue grades.setdefault(user, {})[assignment] = grade for user in sorted(grades.keys()): ret.append({ 'gradeOwner': 'user', 'name': user, 'results': grades.get(user) }) grades = {} for row in team_grade_rows: team, assignment, grade = row if not assignment in vmcfg.assignments(): continue if not vmcfg.assignments().show_grades_before_deadline(assignment): deadline = time.strptime( vmcfg.assignments().get(assignment, 'Deadline'), DATE_FORMAT) deadtime = time.mktime(deadline) if time.time() < deadtime: continue grades.setdefault(team, {})[assignment] = grade for team in sorted(grades.keys()): ret.append({ 'gradeOwner': 'team', 'name': team, 'results': grades.get(team) }) return json.dumps(ret) except: traceback.print_exc(file=strout) return json.dumps({ 'errorType': ERR_EXCEPTION, 'errorMessage': "", 'errorTrace': strout.get() })