def get(self, criterion_uuid): criterion = Criterion.get_active_by_uuid_or_404(criterion_uuid) require(READ, criterion) on_criterion_get.send( self, event_name=on_criterion_get.name, user=current_user ) return marshal(criterion, dataformat.get_criterion())
def get(self, criterion_uuid): criterion = Criterion.get_active_by_uuid_or_404(criterion_uuid) require(READ, criterion, title="Criterion Unavailable", message= "Sorry, your role does not allow you to view this criterion.") on_criterion_get.send(self, event_name=on_criterion_get.name, user=current_user) return marshal(criterion, dataformat.get_criterion())
def post(self): params = new_criterion_parser.parse_args() criterion = Criterion(user_id=current_user.id) require(CREATE, criterion) criterion.name = params.get("name") criterion.description = params.get("description", None) criterion.default = params.get("default") db.session.add(criterion) db.session.commit() on_criterion_create.send( self, event_name=on_criterion_create.name, user=current_user, criterion=criterion, data={'criterion': marshal(criterion, dataformat.get_criterion())} ) return marshal(criterion, dataformat.get_criterion())
def get(self, criterion_uuid): criterion = Criterion.get_active_by_uuid_or_404(criterion_uuid) require(READ, criterion, title="Criterion Unavailable", message="Sorry, your role does not allow you to view this criterion.") on_criterion_get.send( self, event_name=on_criterion_get.name, user=current_user ) return marshal(criterion, dataformat.get_criterion())
def post(self): params = new_criterion_parser.parse_args() criterion = Criterion(user_id=current_user.id) require(CREATE, criterion, title="Criterion Not Saved", message="Sorry, your role does not allow you to add criteria.") criterion.name = params.get("name") criterion.description = params.get("description", None) criterion.default = params.get("default") db.session.add(criterion) db.session.commit() on_criterion_create.send( self, event_name=on_criterion_create.name, user=current_user, criterion=criterion, data={'criterion': marshal(criterion, dataformat.get_criterion())}) return marshal(criterion, dataformat.get_criterion())
def post(self): params = new_criterion_parser.parse_args() criterion = Criterion(user_id=current_user.id) require(CREATE, criterion, title="Criterion Not Saved", message="Sorry, your role does not allow you to add criteria.") criterion.name = params.get("name") criterion.description = params.get("description", None) criterion.default = params.get("default") db.session.add(criterion) db.session.commit() on_criterion_create.send( self, event_name=on_criterion_create.name, user=current_user, criterion=criterion, data={'criterion': marshal(criterion, dataformat.get_criterion())} ) return marshal(criterion, dataformat.get_criterion())
def post(self, criterion_uuid): criterion = Criterion.get_active_by_uuid_or_404(criterion_uuid) require(EDIT, criterion) params = existing_criterion_parser.parse_args() criterion.name = params.get('name', criterion.name) criterion.description = params.get('description', criterion.description) criterion.default = params.get('default', criterion.default) db.session.commit() on_criterion_update.send( self, event_name=on_criterion_update.name, user=current_user, criterion=criterion ) return marshal(criterion, dataformat.get_criterion())
def post(self, criterion_uuid): criterion = Criterion.get_active_by_uuid_or_404(criterion_uuid) require(EDIT, criterion, title="Criterion Not Saved", message="Sorry, your role does not allow you to save this criterion.") params = existing_criterion_parser.parse_args() criterion.name = params.get('name', criterion.name) criterion.description = params.get('description', criterion.description) criterion.default = params.get('default', criterion.default) db.session.commit() on_criterion_update.send( self, event_name=on_criterion_update.name, user=current_user, criterion=criterion ) return marshal(criterion, dataformat.get_criterion())
def post(self, criterion_uuid): criterion = Criterion.get_active_by_uuid_or_404(criterion_uuid) require(EDIT, criterion, title="Criterion Not Saved", message= "Sorry, your role does not allow you to save this criterion.") params = existing_criterion_parser.parse_args() criterion.name = params.get('name', criterion.name) criterion.description = params.get('description', criterion.description) criterion.default = params.get('default', criterion.default) db.session.commit() on_criterion_update.send(self, event_name=on_criterion_update.name, user=current_user, criterion=criterion) return marshal(criterion, dataformat.get_criterion())
def get(self, course_uuid, assignment_uuid): """ Return a list of answers for a assignment based on search criteria. The list of the answers are paginated. If there is any answers from instructor or TA, their answers will be on top of the list. :param course_uuid: course uuid :param assignment_uuid: assignment uuid :return: list of answers """ course = Course.get_active_by_uuid_or_404(course_uuid) assignment = Assignment.get_active_by_uuid_or_404(assignment_uuid) require(READ, assignment) restrict_user = not allow(MANAGE, assignment) params = answer_list_parser.parse_args() if restrict_user and not assignment.after_comparing: # only the answer from student himself/herself should be returned params['author'] = current_user.uuid # this query could be further optimized by reduction the selected columns query = Answer.query \ .options(joinedload('file')) \ .options(joinedload('user')) \ .options(joinedload('scores')) \ .options(undefer_group('counts')) \ .join(UserCourse, and_( Answer.user_id == UserCourse.user_id, UserCourse.course_id == course.id )) \ .add_columns( UserCourse.course_role.__eq__(CourseRole.instructor).label("instructor_role"), UserCourse.course_role.__eq__(CourseRole.teaching_assistant).label("ta_role") ) \ .filter(and_( Answer.assignment_id == assignment.id, Answer.active == True, Answer.practice == False, Answer.draft == False, UserCourse.course_role != CourseRole.dropped )) \ .order_by(desc('instructor_role'), desc('ta_role')) if params['author']: user = User.get_by_uuid_or_404(params['author']) query = query.filter(Answer.user_id == user.id) elif params['group']: query = query.filter(UserCourse.group_name == params['group']) if params['ids']: query = query.filter(Answer.uuid.in_(params['ids'].split(','))) if params['top']: query = query.filter(Answer.top_answer == True) if params['orderBy']: criterion = Criterion.get_active_by_uuid_or_404(params['orderBy']) # order answer ids by one criterion and pagination, in case there are multiple criteria in assignment # does not include answers without a score (Note: ta and instructor never have a score) query = query.join(Score) \ .filter(Score.criterion_id == criterion.id) \ .order_by(Score.score.desc(), Answer.created.desc()) # limit answers up to rank if rank_display_limit is set and current_user is restricted (student) if assignment.rank_display_limit and restrict_user: score_for_rank = Score.get_score_for_rank( assignment.id, criterion.id, assignment.rank_display_limit) # display answers with score >= score_for_rank if score_for_rank != None: # will get all answer with a score greater than or equal to the score for a given rank # the '- 0.00001' fixes floating point precision problems query = query.filter(Score.score >= score_for_rank - 0.00001) else: query = query.order_by(Answer.created.desc()) page = query.paginate(params['page'], params['perPage']) # remove label entities from results page.items = [answer for (answer, instructor_role, ta_role) in page.items] on_answer_list_get.send( self, event_name=on_answer_list_get.name, user=current_user, course_id=course.id, data={'assignment_id': assignment.id}) return {"objects": marshal(page.items, dataformat.get_answer(restrict_user)), "page": page.page, "pages": page.pages, "total": page.total, "per_page": page.per_page}