Commit 5e39dc50 authored by Louis's avatar Louis

Passe les 'seed' comme arguments de la requête GET

Closes #3
parent fb2b63da
......@@ -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 = {
......
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