Import initial. En bonne voie.
darcs-hash:20070122013420-9e428-84217f310a5ffa3c2d1601379847c0b260a7c92d.gz
This commit is contained in:
parent
47bef2fb11
commit
b76a02d297
1 changed files with 44 additions and 0 deletions
44
wiki/macro/Questionnaire.py
Executable file
44
wiki/macro/Questionnaire.py
Executable file
|
@ -0,0 +1,44 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- encoding: iso-8859-15 -*-
|
||||
|
||||
#generation d'une question de questionnaire si il y a des arguments, sinon affiche le résultat
|
||||
|
||||
def parse(text):
|
||||
ligne = text.split("\\")
|
||||
question = []
|
||||
for l in ligne:
|
||||
l = l.split(":",1)
|
||||
if len(l)>=2:
|
||||
question+=[(l[0],l[1])]
|
||||
return question
|
||||
|
||||
def question(f,QR):
|
||||
r=""
|
||||
id = QR[0][0]
|
||||
r+=f.rawHTML("""<script type="text/javascript">
|
||||
var point_%(id)s = 0
|
||||
var point_globale = 0
|
||||
function ajoute_Q%(id)s(point)
|
||||
{
|
||||
point_globale = point_globale + point - point_%(id)s
|
||||
point_%(id)s = point
|
||||
document.getElementById('result').innerHTML = point_globale
|
||||
}
|
||||
</script>
|
||||
<p> %(Q)s </p>
|
||||
""" % { "id" : id , "Q" : QR[0][1]})
|
||||
QR=QR[1:]
|
||||
for (point,rep) in QR:
|
||||
r+=f.rawHTML("""<input type="radio" id="radio%(id)s" onclick="ajoute_Q%(id)s(%(point)s)" > %(rep)s\n"""% { "point" : point , "id" : id, "rep" : rep})
|
||||
return r
|
||||
|
||||
def result(f):
|
||||
return """<p id="result"> 0 </p>"""
|
||||
|
||||
def execute(macro,text):
|
||||
f = macro.formatter
|
||||
if text == "":
|
||||
return result(f)
|
||||
else:
|
||||
QR = parse(text)
|
||||
return question(f,QR)
|
Loading…
Add table
Add a link
Reference in a new issue