def check_part_index(state, name, index, part_msg, missing_msg=None, expand_msg=None): """Return child state with indexed name part as its ast tree. ``index`` can be: - an integer, in which case the student/solution_parts are indexed by position. - a string, in which case the student/solution_parts are expected to be a dictionary. - a list of indices (which can be integer or string), in which case the student parts are indexed step by step. """ if missing_msg is None: missing_msg = "Are you sure you defined the {{part}}? " if expand_msg is None: expand_msg = "Did you correctly specify the {{part}}? " # create message ordinal = get_ord(index + 1) if isinstance(index, int) else "" fmt_kwargs = {"index": index, "ordinal": ordinal} fmt_kwargs.update(part=render(part_msg, fmt_kwargs)) append_message = {"msg": expand_msg, "kwargs": fmt_kwargs} # check there are enough parts for index has_part(state, name, missing_msg, fmt_kwargs, index) # get part at index stu_part = state.student_parts[name] sol_part = state.solution_parts[name] if isinstance(index, list): for ind in index: stu_part = stu_part[ind] sol_part = sol_part[ind] else: stu_part = stu_part[index] sol_part = sol_part[index] assert_ast(state, sol_part, fmt_kwargs) # return child state from part return part_to_child(stu_part, sol_part, append_message, state)
def check_part(name, part_msg, missing_msg=None, expand_msg=None, state=None): """Return child state with name part as its ast tree""" if missing_msg is None: missing_msg = "Are you sure you defined the {{part}}? " if expand_msg is None: expand_msg = "Did you correctly specify the {{part}}? " if not part_msg: part_msg = name append_message = {'msg': expand_msg, 'kwargs': {'part': part_msg}} has_part(name, missing_msg, state, append_message['kwargs']) stu_part = state.student_parts[name] sol_part = state.solution_parts[name] assert_ast(state, sol_part, append_message['kwargs']) return part_to_child(stu_part, sol_part, append_message, state)
def check_part(state, name, part_msg, missing_msg=None, expand_msg=None): """Return child state with name part as its ast tree""" if missing_msg is None: missing_msg = "你确定你定义了 {{part}}吗? " if expand_msg is None: expand_msg = "你是否正确指定了 {{part}}? " if not part_msg: part_msg = name append_message = {"msg": expand_msg, "kwargs": {"part": part_msg}} has_part(state, name, missing_msg, append_message["kwargs"]) stu_part = state.student_parts[name] sol_part = state.solution_parts[name] assert_ast(state, sol_part, append_message["kwargs"]) return part_to_child(stu_part, sol_part, append_message, state)
def check_part(state, name, part_msg, missing_msg=None, expand_msg=None): """Return child state with name part as its ast tree""" if missing_msg is None: missing_msg = "Are you sure you defined the {{part}}? " if expand_msg is None: expand_msg = "Did you correctly specify the {{part}}? " if not part_msg: part_msg = name append_message = FeedbackComponent(expand_msg, {"part": part_msg}) has_part(state, name, missing_msg, append_message.kwargs) stu_part = state.student_parts[name] sol_part = state.solution_parts[name] assert_ast(state, sol_part, append_message.kwargs) return part_to_child(stu_part, sol_part, append_message, state)