Ejemplo n.º 1
0
    def save_new_question(self, *args):
        """Passes the user information input (Question object) from GUI to SqlManager to save data
            in selected_database table.
        """
        question, answer1, answer2, answer3, answer4, answer5, state_var1, state_var2, state_var3, state_var4, state_var5 = args
        right_answers_list = [
            state_var1, state_var2, state_var3, state_var4, state_var5
        ]
        settings_obj = SettingVariables()
        selected_database = settings_obj.selected_database
        row_id = SqlManager().sql_get_last_row_id(selected_database) + 1
        new_question = Question(row_id, question.replace("\n", "."),
                                answer1.replace("\n", "."),
                                answer2.replace("\n", "."),
                                answer3.replace("\n", "."),
                                answer4.replace("\n", "."),
                                answer5.replace("\n", "."), right_answers_list,
                                2)
        new_question_list = [new_question]
        sql_m = SqlManager()
        sql_m.sql_insert_new_questions(new_question_list, selected_database)

        try:
            self.insert_top.destroy()
        except AttributeError as ae:
            print("Exception occurred in save_new_question - due to " +
                  str(ae))
        finally:
            self.gui_insert_menu()
Ejemplo n.º 2
0
    def insert_new_questions_from_file(*args):
        """Imports data from txt file into the selected_database table.
            *args: only needed to delete the gui entry_field after passing of data
        """
        with open("import_questions.txt", encoding="utf8") as f:
            r = f.read()

        test_questions = r.split("Exercise")
        test_questions = test_questions[1:]
        questions_list = []
        for i in range(0, len(test_questions)):
            questions_list.append(test_questions[i].split("\n\n"))

        for ii in range(0, len(questions_list)):
            states = []
            answer_states = questions_list[ii][1]
            for i in range(0, len(answer_states)):
                answer_state = answer_states[i]
                if answer_state == "*":
                    state = 1
                    states.append(state)
                elif answer_state == "-":
                    state = 0
                    states.append(state)

            question = questions_list[ii][0].replace("\n", ".")
            answer1 = questions_list[ii][2].replace("\n", "."),
            answer2 = questions_list[ii][3].replace("\n", "."),
            answer3 = questions_list[ii][4].replace("\n", "."),
            answer4 = questions_list[ii][5].replace("\n", "."),
            answer5 = questions_list[ii][6].replace("\n", "."),
            right_answers = [
                states[0], states[1], states[2], states[3], states[4]
            ]

            sql_m = SqlManager()
            table_content = sql_m.sql_get_database_content(
                SettingVariables().selected_database)
            if len(table_content) > 0:
                row_id = table_content[-1].row_id + 1
            else:
                row_id = 1

            variables = Question(row_id, question, answer1, answer2, answer3,
                                 answer4, answer5, right_answers)
            variables = [variables]

            sql_m = SqlManager()
            sql_m.sql_insert_new_questions(
                variables,
                SettingVariables().selected_database)
Ejemplo n.º 3
0
    def setUpInsertRow(self, table_name):
        """Inserts a row into the passed table(can be database or database copy table)."""
        row_id = self.setUpRowID(table_name)
        new_question = Question(row_id, "q", "a1", "a2", "a3", "a4", "a5", [0, 1, 0, 1, 0], 2)
        new_question = [new_question]
        sql_m = SqlManager()
        sql_m.sql_insert_new_questions(new_question, table_name)
        query_should = [row_id, "q", "a1", "a2", "a3", "a4", "a5", "[0, 1, 0, 1, 0]", 2]
        query_question_objects = sql_m.sql_get_database_content(table_name)
        q_obj = query_question_objects[-1]
        query_real = [q_obj.row_id,
                      q_obj.question,
                      q_obj.answer1,
                      q_obj.answer2,
                      q_obj.answer3,
                      q_obj.answer4,
                      q_obj.answer5,
                      q_obj.right_answers,
                      q_obj.firsts]

        return query_real, query_should