From c1b06b18b403836cdc10d890a97ac23de43da084 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 12 Sep 2021 23:06:23 +0200 Subject: [PATCH] petits bugs (abs) + exc messages --- app/__init__.py | 16 +++++++++++++++- app/scodoc/sco_abs.py | 5 ++++- app/views/absences.py | 7 ++++--- sco_version.py | 2 +- tools/build_release.sh | 6 ++++-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 33fbd23a5..1f68d0f5c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -90,6 +90,20 @@ class RequestFormatter(logging.Formatter): return super().format(record) +class ScoSMTPHandler(SMTPHandler): + def getSubject(self, record: logging.LogRecord) -> str: + stack_summary = traceback.extract_tb(record.exc_info[2]) + frame_summary = stack_summary[-1] + subject = f"Sco Exc: {record.exc_info[0].__name__} in {frame_summary.name} {frame_summary.filename}" + # stack_summary.reverse() + # with open("/tmp/looooo", "wt") as f: + # for frame_summary in stack_summary: + # f.write( + # f"{record.exc_info[0].__name__} in {frame_summary.name} {frame_summary.filename}\n" + # ) + return subject + + def create_app(config_class=DevConfig): app = Flask(__name__, static_url_path="/ScoDoc/static", static_folder="static") app.logger.setLevel(logging.DEBUG) @@ -150,7 +164,7 @@ def create_app(config_class=DevConfig): if app.config["MAIL_USE_TLS"]: secure = () host_name = socket.gethostname() - mail_handler = SMTPHandler( + mail_handler = ScoSMTPHandler( mailhost=(app.config["MAIL_SERVER"], app.config["MAIL_PORT"]), fromaddr="no-reply@" + app.config["MAIL_SERVER"], toaddrs=["exception@scodoc.org"], diff --git a/app/scodoc/sco_abs.py b/app/scodoc/sco_abs.py index a0fffc673..c318dd609 100644 --- a/app/scodoc/sco_abs.py +++ b/app/scodoc/sco_abs.py @@ -639,7 +639,10 @@ def add_absence( cnx = ndb.GetDBConnexion() cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor.execute( - "insert into absences (etudid,jour,estabs,estjust,matin,description, moduleimpl_id) values (%(etudid)s, %(jour)s, TRUE, %(estjust)s, %(matin)s, %(description)s, %(moduleimpl_id)s )", + """ + INSERT into absences (etudid,jour,estabs,estjust,matin,description, moduleimpl_id) + VALUES (%(etudid)s, %(jour)s, true, %(estjust)s, %(matin)s, %(description)s, %(moduleimpl_id)s ) + """, vars(), ) logdb( diff --git a/app/views/absences.py b/app/views/absences.py index 5896287d9..d944b84e7 100644 --- a/app/views/absences.py +++ b/app/views/absences.py @@ -277,6 +277,7 @@ def doSignaleAbsenceGrSemestre( Efface les absences aux dates indiquées par dates, ou bien ajoute celles de abslist. """ + moduleimpl_id = moduleimpl_id or None if etudids: etudids = etudids.split(",") else: @@ -1486,13 +1487,13 @@ def XMLgetAbsEtud(beg_date="", end_date="", REQUEST=None): if not exp.match(end_date): raise ScoValueError("invalid date: %s" % end_date) - Abs = sco_abs.list_abs_date(etud["etudid"], beg_date, end_date) + abs_list = sco_abs.list_abs_date(etud["etudid"], beg_date, end_date) REQUEST.RESPONSE.setHeader("content-type", scu.XML_MIMETYPE) doc = ElementTree.Element( "absences", etudid=str(etud["etudid"]), beg_date=beg_date, end_date=end_date ) - for a in Abs: + for a in abs_list: if a["estabs"]: # ne donne pas les justifications si pas d'absence doc.append( ElementTree.Element( @@ -1500,7 +1501,7 @@ def XMLgetAbsEtud(beg_date="", end_date="", REQUEST=None): begin=a["begin"], end=a["end"], description=a["description"], - justified=a["estjust"], + justified=int(a["estjust"]), ) ) log("XMLgetAbsEtud (%gs)" % (time.time() - t0)) diff --git a/sco_version.py b/sco_version.py index 88ad0a16c..5872639a8 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.0.16" +SCOVERSION = "9.0.18" SCONAME = "ScoDoc" diff --git a/tools/build_release.sh b/tools/build_release.sh index cf7e61db4..bd7dca383 100644 --- a/tools/build_release.sh +++ b/tools/build_release.sh @@ -15,9 +15,11 @@ source "$SCRIPT_DIR/utils.sh" SCODOC_RELEASE=$(grep SCOVERSION "$SCRIPT_DIR/../sco_version.py" | awk '{ print substr($3, 2, length($3)-2) }') # Dernière release -GITEA_RELEASE_URL="https://scodoc.org/git/api/v1/repos/viennet/ScoDoc/releases?pre-release=true" +GITEA_RELEASE_URL="https://scodoc.org/git/api/v1/repos/viennet/ScoDoc/releases" # ?pre-release=true" -LAST_RELEASE_TAG=$(curl "$GITEA_RELEASE_URL" | jq ".[].tag_name" | sort | tail -1 | awk '{ print substr($1, 2, length($1)-2) }') +# suppose que les realse sont nommées 9.0.17, ne considère pas les caractères non numériques +LAST_RELEASE_TAG=$(curl "$GITEA_RELEASE_URL" | jq ".[].tag_name" | tr -d -c "0-9.\n" | sort --version-sort | tail -1) +# | awk '{ print substr($1, 2, length($1)-2) }') echo echo "Version détectée dans le source: $SCODOC_RELEASE"