' %\
(add_class, self.question_counter, solution_s + minimum_s), \
@@ -410,49 +429,40 @@ class Exercise(EduModule):
return ""
-
class Wybor(Exercise):
+ def extra_attributes(self):
+ return {'subtype': 'single' if self.options['single'] else 'multiple'}
+
def handle_cwiczenie(self, element):
- pre, post = super(Wybor, self).handle_cwiczenie(element)
is_single_choice = True
pytania = element.xpath(".//pytanie")
if not pytania:
pytania = [element]
for p in pytania:
- solutions = re.split(r"[, ]+", p.attrib.get('rozw', ''))
+ solutions = p.xpath(".//punkt[@rozw='prawda']")
if len(solutions) != 1:
is_single_choice = False
break
- choices = p.xpath(".//*[@nazwa]")
- uniq = set()
- for n in choices: uniq.add(n.attrib.get('nazwa', ''))
- if len(choices) != len(uniq):
- is_single_choice = False
- break
self.options = {'single': is_single_choice}
- return pre, post
+ return super(Wybor, self).handle_cwiczenie(element)
def handle_punkt(self, element):
- if self.options['exercise'] and element.attrib.get('nazwa', None):
+ if self.options['exercise'] and element.attrib.get('rozw', None):
qc = self.question_counter
self.piece_counter += 1
no = self.piece_counter
eid = "q%(qc)d_%(no)d" % locals()
- aname = element.attrib.get('nazwa', None)
+ sol = element.attrib.get('rozw', None)
+ params = {'qc': qc, 'no': no, 'sol': sol, 'eid': eid}
if self.options['single']:
- return u"""
-
-
-"
+ input_tag = u'
'
else:
- return u"""
-
-
-"
-
+ input_tag = u'
'
+ return (u"""
+
+ """ + input_tag + u"""
+"
else:
return super(Wybor, self).handle_punkt(element)
@@ -480,6 +490,7 @@ Overrides the returned content default handle_pytanie
class Luki(Exercise):
INSTRUCTION = u"PrzeciÄ
gnij odpowiedzi i upuÅÄ w wybranym polu."
+
def find_pieces(self, question):
return question.xpath(".//luka")
@@ -564,6 +575,8 @@ class Przyporzadkuj(Exercise):
'data-target': lista.attrib['cel'],
'class': 'subject'
}
+ if lista.attrib.get('krotkie'):
+ self.options = {'short': True}
self.options = {'subject': True}
else:
attrs = {}
@@ -574,16 +587,29 @@ class Przyporzadkuj(Exercise):
if self.options['subject']:
self.piece_counter += 1
if self.options['handles']:
- return '
%s' % (element.attrib.get('rozw', ''), self.piece_counter, self.piece_counter), ''
+ return (
+ '
%s' % (
+ element.attrib.get('rozw', ''),
+ self.piece_counter,
+ self.piece_counter),
+ '')
else:
- return '
' % (element.attrib.get('rozw', ''), self.piece_counter), ''
+ extra_class = ""
+ if self.options['short']:
+ extra_class += ' short'
+ return '
' % (
+ element.attrib.get('rozw', ''),
+ self.piece_counter, extra_class), ''
elif self.options['predicate']:
if self.options['min']:
placeholders = u'
' * self.options['min']
else:
placeholders = u'
'
- return '
' % element.attrib.get('nazwa', ''), ''
+ return (
+ '
' % element.attrib.get('nazwa', ''),
+ '')
else:
return super(Przyporzadkuj, self).handle_punkt(element)
@@ -609,6 +635,7 @@ class EduModuleFormat(Format):
def __init__(self, wldoc, **kwargs):
super(EduModuleFormat, self).__init__(wldoc, **kwargs)
+ self.materials_by_slug = None
def build(self):
# Sort materials by slug.
@@ -630,17 +657,18 @@ class EduModuleFormat(Format):
def materials(self, slug):
"""Returns a list of pairs: (ext, iofile)."""
- order = dict(reversed(k) for k in enumerate(self.PRIMARY_MATERIAL_FORMATS))
+ order = {pmf: i for (i, pmf) in enumerate(self.PRIMARY_MATERIAL_FORMATS)}
mats = self.materials_by_slug.get(slug, {}).items()
if not mats:
- print "!! Material missing: '%s'" % slug
+ print ("!! Material missing: '%s'" % slug).encode('utf-8')
return sorted(mats, key=lambda (x, y): order.get(x, x))
def url_for_material(self, slug, fmt):
return "%s.%s" % (slug, fmt)
+ # WTF: tutaj byÅ bÅÄ
d, ale nikomu to nie przeszkadzaÅo?
def url_for_image(self, slug, fmt, width=None):
- return self.url_for_material(self, slug, fmt)
+ return self.url_for_material(slug, fmt)
def text_to_anchor(self, text):
return re.sub(r" +", " ", text)