示例#1
0
    def tests_to_dict(self):
        """ This method parses the tests cases information in a dictionary """
        # Transform grader_test_cases[] entries into an actual array (they are sent as separate keys).
        grader_test_cases = CourseEditTask.dict_from_prefix(
            "notebook_grader_test", self.task_data) or OrderedDict()
        # Remove the repeated information
        keys_to_remove = [
            key for key, _ in self.task_data.items()
            if key.startswith("notebook_grader_test[")
        ]
        for key in keys_to_remove:
            del self.task_data[key]

        # Convert the key to int to get a correct sort process
        grader_test_cases = {
            int(key): val
            for key, val in grader_test_cases.items()
        }

        grader_test_cases = OrderedDict(sorted(grader_test_cases.items()))
        for index, test in grader_test_cases.items():
            test["cases"] = {
                int(key): val
                for key, val in test["cases"].items()
            }
            test["cases"] = OrderedDict(sorted(test["cases"].items()))
        return grader_test_cases
示例#2
0
def on_task_editor_submit(course, taskid, task_data, task_fs):
    task_data["code_preview_pairs"] = CourseEditTask.dict_from_prefix(
        "code_preview_pairs", task_data)

    available_languages = get_all_available_languages()
    task_files = CourseTaskFiles.get_task_filelist(course._task_factory,
                                                   course.get_id(), taskid)
    task_files = {
        complete_name[1:] if complete_name.startswith("/") else complete_name
        for level, is_directory, name, complete_name in task_files
    }

    if "code_preview_pairs" in task_data and task_data["code_preview_pairs"]:
        for language, file in task_data["code_preview_pairs"].items():
            if language not in available_languages:
                del task_data["code_preview_pairs"][language]
            if file not in task_files:
                del task_data["code_preview_pairs"][language]

    to_delete = []
    for key in task_data:
        if "code_preview_pairs[" in key:
            to_delete.append(key)

    for key in to_delete:
        del task_data[key]
示例#3
0
def on_task_editor_submit(course, taskid, task_data, task_fs):
    task_data['code_preview_pairs'] = CourseEditTask.dict_from_prefix(
        'code_preview_pairs', task_data)

    to_delete = []
    for key in task_data:
        if 'code_preview_pairs[' in key:
            to_delete.append(key)

    for key in to_delete:
        del task_data[key]
示例#4
0
def on_task_submit(course, taskid, task_data, task_fs):

    task_data["task_hints"] = CourseEditTask.dict_from_prefix("task_hints", task_data)

    # Delete key for hint template if it exists
    if "KEY" in task_data["task_hints"].keys():
        del task_data["task_hints"]["KEY"]

    # Delete duplicate items if they exists

    fields_to_delete = []

    for key in task_data:
        if "task_hints[" in key:
            fields_to_delete.append(key)

    for key in fields_to_delete:
        del task_data[key]

    # Check the fields for each hint in task

    for hint_id in task_data["task_hints"]:
        if not task_data["task_hints"][hint_id].get("content", None):
            return json.dumps({"status": "error", "message": _("Some hints in task have empty content fields.")})

        if not task_data["task_hints"][hint_id]["title"]:
            return json.dumps({"status": "error", "message": _("Some hints in task have empty title fields.")})

        penalty = task_data["task_hints"][hint_id]["penalty"]

        try:
            if penalty and (float(penalty) < 0 or 100 < float(penalty)):
                return json.dumps(
                    {"status": "error", "message": _("Penalty for hints must be between 0.0% and 100.0%.")})
            elif not penalty:
                task_data["task_hints"][hint_id]["penalty"] = 0.0
        except (ValueError, TypeError):
            return json.dumps({"status": "error", "message": _("Each hint penalty must be a float.")})

        else:
            task_data["task_hints"][hint_id]["penalty"] = round(float(penalty), 1)

    # Add id for hints
    task_data["task_hints"] = set_hints_id(task_data["task_hints"])
    task_data["task_hints"] = OrderedDict(sorted(task_data["task_hints"].items()))

    # Update users hints in task when saved
    user_hint_manager().update_unlocked_users_hints(taskid, task_data["task_hints"])
示例#5
0
    def tests_to_dict(self):
        """ This method parses the tests cases information in a dictionary """

        # Transform grader_test_cases[] entries into an actual array (they are sent as separate keys).
        grader_test_cases = CourseEditTask.dict_from_prefix(
            "grader_test_cases", self.task_data) or OrderedDict()

        # Remove the repeated information
        keys_to_remove = [
            key for key, _ in self.task_data.items()
            if key.startswith("grader_test_cases[")
        ]
        for key in keys_to_remove:
            del self.task_data[key]

        return grader_test_cases
示例#6
0
    def tests_to_dict(self):
        """ This method parses the tests cases information in a dictionary """

        # Transform grader_test_cases[] entries into an actual array (they are sent as separate keys).
        grader_test_cases = CourseEditTask.dict_from_prefix(
            "grader_test_cases", self.task_data) or OrderedDict()

        # Remove the repeated information
        keys_to_remove = [
            key for key, _ in self.task_data.items()
            if key.startswith("grader_test_cases[")
        ]
        for key in keys_to_remove:
            del self.task_data[key]

        # Order test cases to load them correctly
        grader_test_cases = OrderedDict(
            sorted(grader_test_cases.items(),
                   key=lambda test: test[1]["input_file"]))
        return grader_test_cases