Esempio n. 1
0
    def serialize(self) -> dict:
        data = self.__dict__.copy()
        del data['instruction_contents']
        del data['answer_contents']

        data['instructionContents'] = serialize_recursive(
            static_content_list_to_widget_list(self.instruction_contents))
        data['answerContents'] = serialize_recursive(static_content_list_to_widget_list(self.answer_contents))
        return data
Esempio n. 2
0
    def serialize(self) -> dict:
        data = self.__dict__

        if self.content:
            data['content'] = serialize_recursive(self.content)

        return data
Esempio n. 3
0
    def serialize(self) -> dict:
        data = super(StaticProblem, self).serialize().copy()

        data['content'] = serialize_recursive(self.content)
        data['used'] = self.used

        return data
Esempio n. 4
0
def static_sets():
    if request.method == 'POST':
        set_id = request.form['id']
        # TODO Make this not required
        source = None
        if 'source' in request.form:
            source = request.form['source']

        instruction_contents = []

        answer_contents = []

        if 'answers[]' in request.form:
            answers_info = request.form.getlist('answers[]')

            answers_images_info = request.files.getlist(
                'answersImages[]'
            ) if 'answersImages[]' in request.files else None

            answer_contents = decode_static_content_form_data_list(
                answers_info, answers_images_info)

        if 'instructions[]' in request.form:
            instructions_info = request.form.getlist('instructions[]')

            instructions_images_info = request.files.getlist(
                'instructionsImages[]'
            ) if 'instructionsImages[]' in request.files else None

            instruction_contents = decode_static_content_form_data_list(
                instructions_info, instructions_images_info)

        static_problem_set = StaticProblemSet(set_id, source,
                                              instruction_contents,
                                              answer_contents)

        # noinspection PyBroadException
        try:
            static.create_static_problem_set(static_problem_set)
        except Exception as e:
            return str(e), 405

        return Response(status=200)
    elif request.method == 'GET':
        static_problem_sets = static.static_sets()
        return dumps(serialize_recursive(static_problem_sets))
Esempio n. 5
0
def test_serialize_recursive(mock_data, mock_expected_data):
    # print(self.mock_expected_data)
    serialized = serialize_recursive(mock_data)
    assert serialized == mock_expected_data
 def serialize(self) -> dict:
     data = self.__dict__
     data['instruction_contents'] = serialize_recursive(
         self.instruction_contents)
     data['answer_contents'] = serialize_recursive(self.answer_contents)
     return data