From d3e7ababd8598ba4c6639995063ae134e94c7cbe Mon Sep 17 00:00:00 2001 From: leonard_montalbano Date: Wed, 8 Jun 2022 16:13:29 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20de=20routes=20sp=C3=A9cifiquement=20r?= =?UTF-8?q?=C3=A9serv=C3=A9=20pour=20le=20debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/__init__.py | 1 + app/api/debug.py | 49 +++++++++++++++++++++++++++++++++++++++++++++ app/models/notes.py | 11 ++++++++++ 3 files changed, 61 insertions(+) create mode 100644 app/api/debug.py diff --git a/app/api/__init__.py b/app/api/__init__.py index 9be4d3b6..c51421f0 100644 --- a/app/api/__init__.py +++ b/app/api/__init__.py @@ -31,3 +31,4 @@ from app.api import evaluations from app.api import jury from app.api import absences from app.api import logos +from app.api import debug diff --git a/app/api/debug.py b/app/api/debug.py new file mode 100644 index 00000000..ba609407 --- /dev/null +++ b/app/api/debug.py @@ -0,0 +1,49 @@ +from app.api import bp +from app.api.auth import token_auth, token_permission_required +from app.models import NotesNotes, FormSemestre +from app.scodoc.sco_permissions import Permission +from flask import jsonify +from app import models +from app import db +import time +import random +import datetime + + +@bp.route("/create_note", methods=["GET"]) +@token_auth.login_required +@token_permission_required(Permission.APIView) +def create_note(): + note = NotesNotes() + db.session.add(note) + db.session.commit() + + return jsonify(note.to_dict()) + + +@bp.route("/change_value_note/", methods=["GET"]) +@token_auth.login_required +@token_permission_required(Permission.APIView) +def change_value_note(note_id: int): + note = NotesNotes.query.get_or_404(note_id) + note.value = 10 + db.session.commit() + + return jsonify(note.to_dict()) + + +@bp.route( + "/change_date_note/", methods=["GET"] +) # XXX TODO test avec notes_add() en plus +@token_auth.login_required +@token_permission_required(Permission.APIView) +def change_date_note(note_id: int): + + formsemestre = FormSemestre.query.get_or_404(1) + date_debut = formsemestre.date_debut + date_fin = formsemestre.date_fin + note = NotesNotes.query.get_or_404(note_id) + note.date = date_debut + random.random() * (date_fin - date_debut) + db.session.commit() + + return jsonify(note.to_dict()) diff --git a/app/models/notes.py b/app/models/notes.py index 6da4ef5d..7754997e 100644 --- a/app/models/notes.py +++ b/app/models/notes.py @@ -47,6 +47,17 @@ class NotesNotes(db.Model): date = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) uid = db.Column(db.Integer, db.ForeignKey("user.id")) + def to_dict(self): + return { + "id": self.id, + "etudid": self.etudid, + "evaluation_id": self.evaluation_id, + "value": self.value, + "comment": self.comment, + "date": self.date, + "uid": self.uid, + } + class NotesNotesLog(db.Model): """Historique des modifs sur notes (anciennes entrees de notes_notes)"""