Exemple #1
0
 def parse_problem(cls, problem_content):
     problem_content = Problem.parse_problem(problem_content)
     try:
         problem_content['exclude'] = load(problem_content['exclude']) or {}
     except ValueError as e:
         raise ValueError('Exclude fields does not contain valid YAML: %s' % e)
     try:
         problem_content['redact'] = load(problem_content['redact']) or {}
     except ValueError as e:
         raise ValueError('Redacted fields does not contain valid YAML: %s' % e)
     try:
         problem_content['hide'] = load(problem_content['hide']) or {}
     except ValueError as e:
         raise ValueError('Hide fields does not contain valid YAML: %s' % e)
     try:
         problem_content['feedback'] = load(problem_content['feedback']) or {}
     except ValueError as e:
         raise ValueError('Feedback does not contain valid YAML: %s' % e)
     problem_content['shuffle'] = problem_content.get('shuffle') == 'on'
     if problem_content.get('range', '').strip():
         r = problem_content.get('range').strip()
         values = ('network', 'transport', 'application', 'network-transport', 'network-application', 'transport-application')
         if r not in values:
             raise ValueError('The network layers selected must be a value in ' + repr(values))
         problem_content['range'] = r
     return problem_content
    def parse_problem(cls, problem_content):
        problem_content = Problem.parse_problem(problem_content)

        if "tolerance" in problem_content:
            if problem_content["tolerance"]:
                problem_content["tolerance"] = float(
                    problem_content["tolerance"])
            else:
                del problem_content["tolerance"]

        if "choices" in problem_content:
            problem_content["choices"] = [
                val
                for _, val in sorted(iter(problem_content["choices"].items()),
                                     key=lambda x: int(x[0]))
                if val["feedback"].strip()
            ]
        if "answers" in problem_content:
            problem_content["answers"] = [
                val for _, val in problem_content["answers"].items()
            ]

        for message in ["error_message", "success_message"]:
            if message in problem_content and problem_content[message].strip(
            ) == "":
                del problem_content[message]

        return problem_content
    def parse_problem(self, problem_content):
        problem_content = Problem.parse_problem(problem_content)
        try:
            problem_content["boxes"] = json.loads(problem_content["boxes"], object_pairs_hook=OrderedDict)
        except:
            raise Exception("Invalid JSON in boxes content")

        return problem_content
    def parse_problem(cls, problem_content):
        problem_content = Problem.parse_problem(problem_content)

        if "error_msg_visibility_start" in problem_content and problem_content[
                "error_msg_visibility"] == "hidden_until":
            if problem_content["error_msg_visibility_start"] == '':
                problem_content[
                    "error_msg_visibility_start"] = '2000-01-01 00:00:00'
            else:
                try:
                    datetime.strptime(
                        problem_content["error_msg_visibility_start"],
                        '%Y-%m-%d %X')
                except ValueError:
                    raise ValueError("Invalid date format")

        if "error_msg_attempts" in problem_content and problem_content[
                "error_msg_visibility"] == "after_attempt" and problem_content[
                    "error_msg_attempts"] == '':
            problem_content["error_msg_attempts"] = 0

        if "tolerance" in problem_content:
            if problem_content["tolerance"]:
                problem_content["tolerance"] = float(
                    problem_content["tolerance"])
            else:
                del problem_content["tolerance"]
        if "choices" in problem_content:
            problem_content["choices"] = [
                val
                for _, val in sorted(iter(problem_content["choices"].items()),
                                     key=lambda x: int(x[0]))
                if val["feedback"].strip()
            ]
        if "answers" in problem_content:
            problem_content["answers"] = [
                val for _, val in problem_content["answers"].items()
            ]

        for message in ["error_message", "success_message"]:
            if message in problem_content and problem_content[message].strip(
            ) == "":
                del problem_content[message]

        return problem_content
Exemple #5
0
 def parse_problem(self, problem_content):
     return Problem.parse_problem(problem_content)