fnp
/
librarian.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b22e181
)
Show radios
author
Marcin Koziej
<mkoziej@ksi.(none)>
Fri, 25 Jan 2013 11:25:16 +0000
(12:25 +0100)
committer
Marcin Koziej
<mkoziej@ksi.(none)>
Fri, 25 Jan 2013 11:25:16 +0000
(12:25 +0100)
librarian/pyhtml.py
patch
|
blob
|
history
diff --git
a/librarian/pyhtml.py
b/librarian/pyhtml.py
index
7114b12
..
a46659c
100644
(file)
--- a/
librarian/pyhtml.py
+++ b/
librarian/pyhtml.py
@@
-6,6
+6,7
@@
from lxml import etree
from librarian import OutputFile, RDFNS, DCNS
from xmlutils import Xmill, tag, tagged, ifoption
from lxml import etree
from librarian import OutputFile, RDFNS, DCNS
from xmlutils import Xmill, tag, tagged, ifoption
+import re
import random
class EduModule(Xmill):
import random
class EduModule(Xmill):
@@
-189,6
+190,13
@@
class Excercise(EduModule):
class Wybor(Excercise):
class Wybor(Excercise):
+ def handle_pytanie(self, element):
+ pre, post = super(Wybor, self).handle_pytanie(element)
+ solutions = re.split(r"[, ]+", element.attrib['rozw'])
+ if len(solutions) == 1:
+ self.options = { 'single': True }
+ return pre, post
+
def handle_punkt(self, element):
if self.options['excercise'] and element.attrib.get('nazwa', None):
qc = self.question_counter
def handle_punkt(self, element):
if self.options['excercise'] and element.attrib.get('nazwa', None):
qc = self.question_counter
@@
-196,9
+204,16
@@
class Wybor(Excercise):
no = self.piece_counter
eid = "q%(qc)d_%(no)d" % locals()
aname = element.attrib.get('nazwa', None)
no = self.piece_counter
eid = "q%(qc)d_%(no)d" % locals()
aname = element.attrib.get('nazwa', None)
- return u"""
+ if self.options['single']:
+ return u"""
<li class="question-piece" data-qc="%(qc)d" data-no="%(no)d" data-name="%(aname)s">
<li class="question-piece" data-qc="%(qc)d" data-no="%(no)d" data-name="%(aname)s">
-<input type="checkbox" name="" id="%(eid)s" />
+<input type="radio" name="q%(qc)d" id="%(eid)s" value="%(aname)s" />
+<label for="%(eid)s">
+ """ % locals(), u"</label></li>"
+ else:
+ return u"""
+<li class="question-piece" data-qc="%(qc)d" data-no="%(no)d" data-name="%(aname)s">
+<input type="checkbox" name="%(eid)s" id="%(eid)s" />
<label for="%(eid)s">
""" % locals(), u"</label></li>"
<label for="%(eid)s">
""" % locals(), u"</label></li>"
@@
-206,6
+221,7
@@
class Wybor(Excercise):
return super(Wybor, self).handle_punkt(element)
return super(Wybor, self).handle_punkt(element)
+
class Uporzadkuj(Excercise):
def handle_pytanie(self, element):
"""
class Uporzadkuj(Excercise):
def handle_pytanie(self, element):
"""
@@
-284,7
+300,7
@@
class Przyporzadkuj(Excercise):
'data-target': lista.attrib['cel'],
'class': 'subject'
}
'data-target': lista.attrib['cel'],
'class': 'subject'
}
- self.options = {'subject': True}
+ self.options = {'subject': True
, 'handles': 'uchwyty' in lista.attrib
}
else:
attrs = {}
pre, post = super(Przyporzadkuj, self).handle_lista(lista, attrs)
else:
attrs = {}
pre, post = super(Przyporzadkuj, self).handle_lista(lista, attrs)