complète et corrige les fonctions pour avoir le CRUD d'un quiz et ses questions : 
from flask import Flask, request, jsonify, render_template, redirect, url_for
from .app import db

class Questionnaire(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))

    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return '<Questionnaire %r>' % self.name

    def to_json(self):
        return {
            'questions_url': url_for('get_questionnaire', quiz=self.id, _external=True),
            'id': self.id,
            'name': self.name
        }
    
    def get_quiz():
        return [questionnaire.to_json() for questionnaire in Questionnaire.query.all()]

    def get_quiz_id(questionnaire_id):
        return Questionnaire.query.get(questionnaire_id).to_json()

    def create_quiz(name):
        questionnaire = Questionnaire(name)
        db.session.add(questionnaire)
        db.session.commit()
        return questionnaire.to_json()

    def update_quiz(questionnaire_id, name):
        questionnaire = Questionnaire.query.get(questionnaire_id)
        questionnaire.name = name
        db.session.commit()
        return questionnaire.to_json()

    def delete_quiz(questionnaire_id):
        questionnaire = Questionnaire.query.get(questionnaire_id)
        db.session.delete(questionnaire)
        db.session.commit()
        return {'result': True}

class Question(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    contenu = db.Column(db.String(500)) 
    question_type = db.Column(db.String(120))
    questionnaire_id = db.Column(db.Integer, db.ForeignKey('questionnaire.id'))
    questionnaire = db.relationship('Questionnaire', backref=db.backref('questions', lazy='dynamic'))
    
    
    def __init__(self, contenu, questionnaire_id, question_type="question"):
        self.contenu = contenu
        self.questionnaire_id = questionnaire_id
        self.question_type = question_type
    
    def to_json(self):
        return {
            'id': self.id,
            'contenu': self.contenu,
            'questionnaire_id': self.questionnaire_id
        }
        
    def create_question(questionnaire_id, contenu, reponse):
        question = Question(contenu=contenu, reponse=reponse, questionnaire_id=questionnaire_id)
        db.session.add(question)
        db.session.commit()
        return question.to_json()
    
    __mapper_args__ = {
        'polymorphic_identity' : 'question',
        'with_polymorphic': '*',
        'polymorphic_on': question_type
    }


class SimpleQuestion(Question):
    id = db.Column(db.Integer, db.ForeignKey('question.id'), primary_key=True)
    proposition = db.Column(db.String(500))
    reponse = db.Column(db.String(500))

    def __init__(self, contenu, reponse, questionnaire_id, proposition):
        super().__init__(contenu=contenu, questionnaire_id=questionnaire_id, question_type="SimpleQuestion")
        self.proposition = proposition
        self.reponse = reponse
        
    def to_json(self):
        return {
            'id': self.id,
            'contenu': self.contenu,
            'reponse': self.reponse,
            'proposition': self.proposition,
            'type':self.question_type,
            'questionnaire_id': self.questionnaire_id
        }
    
    def create_question(questionnaire_id, contenu, reponse, proposition):
        question = SimpleQuestion(contenu=contenu, reponse=reponse, questionnaire_id=questionnaire_id, proposition=proposition)
        question.question_type = "SimpleQuestion"
        db.session.add(question)
        db.session.commit()
        return question.to_json()
    
    __mapper_args__ = {
            'polymorphic_identity' : 'SimpleQuestion',
            'with_polymorphic': '*',
            'polymorphic_load': 'inline',
        }

class QuestionMultiple(Question):
    id = db.Column(db.Integer, db.ForeignKey('question.id'), primary_key=True)
    proposition1 = db.Column(db.String(500))    
    proposition2 = db.Column(db.String(500))
    reponse = db.Column(db.Integer())

    def __init__(self, contenu, questionnaire_id, proposition1, proposition2, reponse):
        super().__init__(contenu=contenu, questionnaire_id=questionnaire_id)
        self.proposition1 = proposition1
        self.proposition2 = proposition2
        self.question_type = "QuestionMultiple"
        self.reponse = reponse
    
    def to_json(self):
        return {
            'id': self.id,
            'contenu': self.contenu,
            'reponse': self.reponse,
            'proposition1': self.proposition1,
            'proposition2': self.proposition2,
            'type' : self.question_type,
            'questionnaire_id': self.questionnaire_id
        }
    
    def create_question(questionnaire_id, contenu, reponse, proposition1, proposition2):
        if not isinstance(reponse, int) or reponse < 1 or reponse > 2:
            raise ValueError("La réponse doit être un entier qui correspond au numéro de la proposition correcte 1 ou 2.")
        question = QuestionMultiple(contenu=contenu, reponse=reponse, questionnaire_id=questionnaire_id, proposition1=proposition1, proposition2=proposition2)
        db.session.add(question)
        db.session.commit()
        return question.to_json()
    
    __mapper_args__ = {
            'polymorphic_identity' : 'QuestionMultiple',
            'with_polymorphic': '*',
            'polymorphic_load': 'inline',
        }from flask import abort, jsonify, make_response, request, url_for
from .app import app
from .models import Questionnaire, SimpleQuestion, QuestionMultiple

@app.route('/quiz/api/v1.0/quiz', methods=['GET'])
def get_quiz():
    return jsonify(Questionnaire.get_quiz())

@app.route('/quiz/api/v1.0/quiz/<int:quiz>/questions', methods=['GET'])
def get_questionnaire(quiz):
    questionnaire = Questionnaire.query.get(quiz)
    if questionnaire is None:
        abort(404)
    questions = []
    for question in questionnaire.questions:
        match question.question_type:
            case 'SimpleQuestion':
                simple_question = SimpleQuestion.query.get(question.id)
                questions.append(simple_question.to_json())
            case 'QuestionMultiple':
                multiple_question = QuestionMultiple.query.get(question.id)
                questions.append(multiple_question.to_json())
    return jsonify(questions)

@app.route('/quiz/api/v1.0/quiz/<int:quiz>/questions', methods=['POST'])
def create_question(questionnaire_id):
    if not request.json or not 'questionType' in request.json:
        abort(400)
    match request.json:
        case "SimpleQuestion":
            return jsonify(SimpleQuestion.create_question(questionnaire_id, request.json['contenu'], request.json['reponse'], request.json['proposition'])), 201
        case "QuestionMultiple":
            return jsonify(QuestionMultiple.create_question(questionnaire_id, request.json["contenu"], request.json["reponse"], request.json["proposition1"], request.json["proposition2"])), 201
        case _:
            return "Type de question invalide", 400

@app.route('/quiz/api/v1.0/quiz', methods=['POST'])
def create_quiz():
    if not request.json or not 'name' in request.json:
        abort(400)
    return jsonify(Questionnaire.create_quiz(request.json['name'])), 201

@app.route('/quiz/api/v1.0/quiz/<int:quiz>', methods=['PUT'])
def update_quiz(questionnaire_id):
    if not request.json or not 'name' in request.json:
        abort(400)
    return jsonify(Questionnaire.update_quiz(questionnaire_id, request.json['name']))

@app.route('/quiz/api/v1.0/quiz/<int:quiz>', methods=['DELETE'])
def delete_quiz(questionnaire_id):
    return jsonify(Questionnaire.delete_quiz(questionnaire_id))

<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="utf-8"/>
    <title>Vos quizz</title>

<link rel="stylesheet" href="css/flex.css"/>
<script src="js/jquery.min.js"></script>
<script src="js/todo.js"></script>
  </head>
  <body>
 <header>
 <h1>Choses à faire</h1>
 </header>

 <div id='main'>
    <nav id="nav1">
      <h2>Todo</h2>
        <input id="button" type="button" value="Recuperer les quizz" />
        <div id="quiz">
        </div>
    </nav>

    <article>
      <h2>Editeur de Tâches</h2>
      <section id="tools">
        <img id="add" src="img/new.png" alt="Nouvelle chose à faire"/>
        <img id="del" src="img/delete.png" alt="Enlever cette tache"/>
      </section>
      <section id="currenttquiz"> </section>
    </article>
 </div>
 <footer>
 <h4>©Département Informatique ⚛ IUT d'Orléans</h4>
 </footer>

  </body>
</html>
$(function () {
  $("#button").click(refreshQuiz);

  function remplirQuiz(quizz) {
    console.log(JSON.stringify(quizz));
    $("#quiz").empty();
    $("#quiz").append($("<ul>"));
    for (quiz of quizz) {
      $("#quiz ul").append(
        $("<li>").append($("<a>").text(quiz.name)).on("click", quiz, details)
      );
    }
  }
  function onerror(err) {
    $("#taches").html(
      "<b>Impossible de récupérer les taches à réaliser !</b>" + err
    );
  }

  function refreshQuiz() {
    $("#currenttquiz").empty();
    console.log("test");
    requete = "http://localhost:5000/quiz/api/v1.0/quiz";
    console.log("test1");
    fetch(requete)
      .then((response) => {
        if (response.ok) return response.json();
        else throw new Error("Problème ajax: " + response.status);
      })
      .then(remplirQuiz)
      .catch(onerror);
  }

  function details(event) {
    $("#currenttquiz").empty();
    formQuiz();
    fillFormQuiz(event.data);
  }

  class Questionnaire {
    constructor(id, name, uri) {
      this.id = id;
      this.name = name;
      this.uri = uri;
    }
  }
  $("#tools #add").on("click", formQuiz);
  $("#tools #del").on("click", delQuiz);

  function formQuiz(isnew) {
    $("#currenttquiz").empty();
    $("#currenttquiz")
      .append($('<span>Titre<input type="text" id="titre"><br></span>'))
      .append($('<span>Done<input type="checkbox" id="done"><br></span>'))
      .append($('<span><input type="hidden" id="questions_url"><br></span>'))
      .append(
        isnew
          ? $('<span><input type="button" value="Save Quiz"><br></span>').on(
              "click",
              saveNewQuiz
            )
          : $('<span><input type="button" value="Modify Quiz"><br></span>').on(
              "click",
              saveModifiedQuiz
            )
      );
  }

  function fillFormQuiz(t) {
    $("#currenttquiz #titre").val(t.name);
    t.questions_url = "http://localhost:5000/quiz/api/v1.0/quiz/" + t.id
    $("#currenttquiz #questions_url").val(t.questions_url);
    t.done
      ? $("#currenttquiz #done").prop("checked", true)
      : $("#currenttquiz #done").prop("checked", false);
  }

  function delQuiz() {
    if ($("#currenttquiz #questions_url").val()) {
      url = $("#currenttquiz #questions_url").val();
      fetch(url, {
        headers: {
          Accept: "application/json",
          "Content-Type": "application/json",
        },
        method: "DELETE",
      })
        .then((res) => {
          console.log("Delete Success:" + res);
        })
        .then(refreshQuiz)
        .catch((res) => {
          console.log(res);
        });
    }
  }

  function saveModifiedQuiz() {
    var quiz = new Questionnaire(
      $("#currenttquiz #titre").val(),
      $("#currenttquiz #done").is(":checked"),
      $("#currenttquiz #questions_url").val()
    );
    console.log("PUT");
    console.log(quiz.uri);
    console.log(JSON.stringify(quiz));
    fetch(quiz.uri, {
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json",
      },
      method: "PUT",
      body: JSON.stringify(quiz),
    })
      .then((res) => {
        console.log("Save Success");
        refreshQuiz();
      })
      .catch((res) => {
        console.log(res);
      });
  }
});