From 5e39dc50371c786960047b00d782bd97bcef24c2 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 16 Sep 2018 15:38:35 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Passe=20les=20'seed'=20comme=20arguments=20?= =?UTF-8?q?de=20la=20requ=C3=AAte=20GET?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3 --- utiliser/static/style.css | 2 +- utiliser/templates/utiliser/utiliser.html | 78 ++++++++++++++++------- utiliser/views.py | 30 ++++++--- 3 files changed, 77 insertions(+), 33 deletions(-) diff --git a/utiliser/static/style.css b/utiliser/static/style.css index 6e0512a..9bdf7ff 100644 --- a/utiliser/static/style.css +++ b/utiliser/static/style.css @@ -464,7 +464,7 @@ form#idForm input{ border:2px outset #ddc525; background-color: #f8f3d2; } -form#idForm select{ +table.tabs select{ color: #666; background-color: #f8f3d2; } diff --git a/utiliser/templates/utiliser/utiliser.html b/utiliser/templates/utiliser/utiliser.html index 7fc8e42..b7f9675 100644 --- a/utiliser/templates/utiliser/utiliser.html +++ b/utiliser/templates/utiliser/utiliser.html @@ -12,11 +12,11 @@

Utiliser Pyromaths en ligne

+ {% if messages %} -
+ {% for niveau, exercices in EXERCICES %} +
+ + {% for name, description in exercices %} + {% if forloop.counter0|divisibleby:2 %}{% endif %} + + {% if not forloop.counter0|divisibleby:2 %}{% endif %} + {% endfor %} +
+ + {{ description }} +
+
+ {% endfor %} + {% csrf_token %} - {% for niveau, exercices in EXERCICES %} -
- - {% for name, description in exercices %} - {% if forloop.counter0|divisibleby:2 %}{% endif %} - - {% if not forloop.counter0|divisibleby:2 %}{% endif %} - {% endfor %} -
- - {{ description }} -
-
- {% endfor %} -

L'utilisation de Pyromaths en ligne nécessite l'activation de Javascript.

+


@@ -63,6 +63,36 @@

+ + {% endblock %} {% block colonnedroite %} diff --git a/utiliser/views.py b/utiliser/views.py index 76919a4..cae06fe 100644 --- a/utiliser/views.py +++ b/utiliser/views.py @@ -1,3 +1,5 @@ +import functools +import itertools import os from django.shortcuts import render, redirect @@ -28,19 +30,31 @@ def choix(request): } ) +def _first(length=1): + def decorator_first(func): + @functools.wraps(func) + def wrapper_first(*args, **kwargs): + return itertools.islice(func(*args, **kwargs), length) + return wrapper_first + return decorator_first + +@_first(5) +def parseSeeds(*arguments): + """Itérateur sur (au maximum) cinq 'seeds' d'exercice.""" + for argument in arguments: + for text in argument.split(","): + try: + yield int(text) + except ValueError: + pass + def creer(request): # Génération de la liste d'exercices exercices = [] for key in request.GET: if key in BAG: - number = 0 - for string in request.GET.getlist(key): - try: - number += int(string) - except ValueError: - pass - for i in range(min(5, number)): - exercices.append(BAG[key]()) + for seed in parseSeeds(*request.GET.getlist(key)): + exercices.append(BAG[key](seed)) # Génération du PDF if exercices: parametres = { -- GitLab From c8e038b4124a2ffa7b830f14756b842ed8cdf24d Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 16 Sep 2018 16:14:01 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Ajout=20d'un=20script=20pour=20trouver=20le?= =?UTF-8?q?s=20exercices=20g=C3=A9n=C3=A9rant=20des=20erreurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/generate-from-GET.py | 114 +++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100755 utils/generate-from-GET.py diff --git a/utils/generate-from-GET.py b/utils/generate-from-GET.py new file mode 100755 index 0000000..b0f4d6a --- /dev/null +++ b/utils/generate-from-GET.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python3 + +# Copyright 2018 Louis Paternault +# +# Pyromaths is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyromaths is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero Public License for more details. +# +# You should have received a copy of the GNU Affero Public License +# along with Pyromaths. If not, see . + +import logging +import os +import sys +import textwrap +import urllib.parse + +from pyromaths.ex import ExerciseBag +from pyromaths.outils.System import Fiche + +# Un peu cracra, mais ce script ne sera jamais distribué (outil de développement uniquement). +sys.path.append(os.path.realpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir))) +from utiliser.views import parseSeeds + +# Logging configuration +logging.basicConfig(level=logging.INFO) +LOGGER = logging.getLogger() + +BAG = ExerciseBag() + +################################################################################ +# Couleurs + +GREEN = '\033[92m' +RED = '\033[91m' +ENDC = '\033[0m' + +def green(text): + return GREEN + text + ENDC + +def red(text): + return RED + text + ENDC +################################################################################ + +def usage(): + print(textwrap.dedent("""\ + Ce programme permet de trouver les exercices ayant produit des erreurs sur le serveur de pyromaths. + + USAGE: + + utils/generate-from-GET.py URL + + EXEMPLE: + + ./utils/generate-from-GET.py "http://example.com/creer/?EtatStableSysteme2=56&InterpolationMatrices=8%2C14%2C89" + + DESCRIPTION + + Ce programme teste chacun des exercices (avec graine) séparément, et affiche la liste des exercices ayant échoué. + """)) + +def parse_arguments(): + if "-h" in sys.argv or "--help" in sys.argv: + usage() + sys.exit(0) + + if len(sys.argv) != 2: + logging.error("Ce programme nécessite exactement un argument.") + sys.exit(1) + + for key, value in urllib.parse.parse_qs(urllib.parse.unquote(urllib.parse.urlparse(sys.argv[1]).query)).items(): + if key not in BAG: + continue + for seed in parseSeeds(*value): + yield key, seed + +def compileexo(name, seed): + parametres = { + 'enonce': True, + 'corrige': True, + 'exercices': [BAG[name](seed)], + 'titre': "Fiche de révisions", + } + try: + with Fiche(parametres) as fiche: + fiche.write_pdf() + except: + return False + return True + +if __name__ == "__main__": + failed = [] + + logging.info("Analyse des arguments") + exercices = list(parse_arguments()) + + logging.info("Test des exercices") + for name, seed in exercices: + if compileexo(name, seed): + print(green("Succès"), end=" ") + else: + print(red("Échec "), end=" ") + failed.append((name, seed)) + print("{}:{}".format(name, seed)) + + logging.info("Bilan : Les erreurs suivantes ont été détectées") + for name, seed in failed: + print("pyromaths generate {}:{}".format(name, seed)) -- GitLab From ffcefc5c865c296f9aaa631aec3e01971725dbf7 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 16 Sep 2018 16:18:01 +0200 Subject: [PATCH 3/3] Ajout d'un message d'aide --- utils/generate-from-GET.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/generate-from-GET.py b/utils/generate-from-GET.py index b0f4d6a..e50f9ba 100755 --- a/utils/generate-from-GET.py +++ b/utils/generate-from-GET.py @@ -71,7 +71,7 @@ def parse_arguments(): sys.exit(0) if len(sys.argv) != 2: - logging.error("Ce programme nécessite exactement un argument.") + logging.error("Ce programme nécessite exactement un argument. Utilisez l'option `--help` pour afficher l'aide.") sys.exit(1) for key, value in urllib.parse.parse_qs(urllib.parse.unquote(urllib.parse.urlparse(sys.argv[1]).query)).items(): -- GitLab