X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/f03d1fdbe472dbfb103d00b0e4ee9fa593c7b2c0..fe8e5b5e224d32baebbdaa2fecf4a847ed4e5354:/librarian/pyhtml.py
diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py
index a46659c..5c2e5c6 100644
--- a/librarian/pyhtml.py
+++ b/librarian/pyhtml.py
@@ -6,25 +6,27 @@
from lxml import etree
from librarian import OutputFile, RDFNS, DCNS
from xmlutils import Xmill, tag, tagged, ifoption
+from librarian import functions
import re
import random
+
class EduModule(Xmill):
def __init__(self, *args):
super(EduModule, self).__init__(*args)
self.activity_counter = 0
+ self.register_text_filter(lambda t: functions.substitute_entities(None, t))
def handle_powiesc(self, element):
return u"""
+
"
-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 }
+class Wybor(Exercise):
+ def handle_cwiczenie(self, element):
+ pre, post = super(Wybor, self).handle_cwiczenie(element)
+ is_single_choice = True
+ for p in element.xpath(".//pytanie"):
+ solutions = re.split(r"[, ]+", p.attrib['rozw'])
+ if len(solutions) != 1:
+ is_single_choice = False
+ break
+ self.options = {'single': is_single_choice}
return pre, post
def handle_punkt(self, element):
- if self.options['excercise'] and element.attrib.get('nazwa', None):
+ if self.options['exercise'] and element.attrib.get('nazwa', None):
qc = self.question_counter
self.piece_counter += 1
no = self.piece_counter
@@ -221,8 +247,7 @@ class Wybor(Excercise):
return super(Wybor, self).handle_punkt(element)
-
-class Uporzadkuj(Excercise):
+class Uporzadkuj(Exercise):
def handle_pytanie(self, element):
"""
Overrides the returned content default handle_pytanie
@@ -241,7 +266,7 @@ Overrides the returned content default handle_pytanie
""
-class Luki(Excercise):
+class Luki(Exercise):
def find_pieces(self, question):
return question.xpath("//luka")
@@ -287,19 +312,26 @@ class Zastap(Luki):
% self.piece_counter, ''
-class Przyporzadkuj(Excercise):
+class Przyporzadkuj(Exercise):
+ def handle_pytanie(self, element):
+ pre, post = super(Przyporzadkuj, self).handle_pytanie(element)
+ minimum = element.attrib.get("min", None)
+ if minimum:
+ self.options = {"min": int(minimum)}
+ return pre, post
+
def handle_lista(self, lista):
if 'nazwa' in lista.attrib:
attrs = {
'data-name': lista.attrib['nazwa'],
'class': 'predicate'
- }
+ }
self.options = {'predicate': True}
elif 'cel' in lista.attrib:
attrs = {
'data-target': lista.attrib['cel'],
'class': 'subject'
- }
+ }
self.options = {'subject': True, 'handles': 'uchwyty' in lista.attrib}
else:
attrs = {}
@@ -315,14 +347,17 @@ class Przyporzadkuj(Excercise):
return '
' % (element.attrib['rozw'], self.piece_counter), ''
elif self.options['predicate']:
- placeholders = u'
'
+ if self.options['min']:
+ placeholders = u'
' * self.options['min']
+ else:
+ placeholders = u'
'
return '
' % element.attrib, ''
else:
return super(Przyporzadkuj, self).handle_punkt(element)
-class PrawdaFalsz(Excercise):
+class PrawdaFalsz(Exercise):
def handle_punkt(self, element):
if 'rozw' in element.attrib:
return u'''