Commit 2b36d46e authored by Jérôme Ortais's avatar Jérôme Ortais

Merge branch 'seed2' into 'master'

Passe le "seed" comme argument du GET

Closes #3

See merge request !2
parents fb2b63da ffcefc5c
......@@ -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;
}
......
......@@ -12,11 +12,11 @@
<h1>Utiliser Pyromaths en ligne</h1>
<script type="text/javascript">
$(function() {
$("#msgjs").hide();
$("#tabs").tabs();
});
</script>
{% if messages %}
<ul class="messages" id="errmsg">
{% for message in messages %}
......@@ -32,30 +32,30 @@
{% endfor %}
</ul>
<form method="get" action="{% url 'utiliser:creer' %}" id="idForm">
{% for niveau, exercices in EXERCICES %}
<div id="tabs-{{ forloop.counter0 }}">
<table class="tabs">
{% for name, description in exercices %}
{% if forloop.counter0|divisibleby:2 %}<tr>{% endif %}
<td>
<select id="ex-{{ name }}">
<option selected="selected">0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
{{ description }}
</td>
{% if not forloop.counter0|divisibleby:2 %}</tr>{% endif %}
{% endfor %}
</table>
</div>
{% endfor %}
<form method="get" action="{% url 'utiliser:creer' %}" id="idForm" >
{% csrf_token %}
{% for niveau, exercices in EXERCICES %}
<div id="tabs-{{ forloop.counter0 }}">
<table class="tabs">
{% for name, description in exercices %}
{% if forloop.counter0|divisibleby:2 %}<tr>{% endif %}
<td>
<select name="{{ name }}">
<option selected="selected">0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
{{ description }}
</td>
{% if not forloop.counter0|divisibleby:2 %}</tr>{% endif %}
{% endfor %}
</table>
</div>
{% endfor %}
<p id="msgjs">L'utilisation de Pyromaths en ligne nécessite l'activation de Javascript.</p>
<noscript>L'utilisation de Pyromaths en ligne nécessite l'activation de Javascript.</noscript>
<p>
<br/>
<input type="submit" value="Cr&eacute;er" />
......@@ -63,6 +63,36 @@
</p>
</form>
</div>
<script>
var exolist = [
{% for niveau, exercices in EXERCICES %}
{% for name, description in exercices %}
"{{ name }}"{% if not forloop.last or not forloop.parentloop.last %},{% endif %}
{% endfor %}
{% endfor %}
];
function generateSeeds(count) {
seeds = [];
for(; count > 0; count--){
seeds.push(Math.floor((Math.random() * 1000000000) + 1));
}
return seeds.join(",");
}
$('#idForm').submit(function(){ //listen for submit event
$.each(exolist, function(i,exo){
count = Number($("#ex-" + exo + " :selected").text());
if (count) {
$('<input />').attr('type', 'hidden')
.attr('name', exo)
.attr('value', generateSeeds(count))
.appendTo('#idForm');
}
});
return true;
});
</script>
{% endblock %}
{% block colonnedroite %}
......
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 = {
......
#!/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 <http://www.gnu.org/licenses/>.
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. 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():
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))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment