fnp
/
librarian.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update to new format of cwiczenie wybor
[librarian.git]
/
librarian
/
pyhtml.py
diff --git
a/librarian/pyhtml.py
b/librarian/pyhtml.py
index
4f8f98c
..
67793f6
100644
(file)
--- a/
librarian/pyhtml.py
+++ b/
librarian/pyhtml.py
@@
-131,7
+131,7
@@
class EduModule(Xmill):
counter = self.activity_counter
counter = self.activity_counter
- if element.getnext().tag == 'aktywnosc' or (
self.activity_last
and self.activity_last.getnext() == element):
+ if element.getnext().tag == 'aktywnosc' or (
len(self.activity_last)
and self.activity_last.getnext() == element):
counter_html = """<span class="act_counter">%(counter)d.</span>""" % {'counter': counter}
else:
counter_html = ''
counter_html = """<span class="act_counter">%(counter)d.</span>""" % {'counter': counter}
else:
counter_html = ''
@@
-251,7
+251,7
@@
class EduModule(Xmill):
subgen = EduModule(self.options)
definiens_s = subgen.generate(definiens)
else:
subgen = EduModule(self.options)
definiens_s = subgen.generate(definiens)
else:
- print
"!! Missing definiendum in source: '%s'" % element.text
+ print
("!! Missing definiendum in source: '%s'" % element.text).encode('utf-8')
return u"<dt id='%s'>" % self.naglowek_to_anchor(element), u"</dt>" + definiens_s
return u"<dt id='%s'>" % self.naglowek_to_anchor(element), u"</dt>" + definiens_s
@@
-427,41
+427,30
@@
class Wybor(Exercise):
if not pytania:
pytania = [element]
for p in pytania:
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
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
def handle_punkt(self, element):
self.options = {'single': is_single_choice}
return pre, post
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()
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']:
if self.options['single']:
- return u"""
-<li class="question-piece" data-qc="%(qc)d" data-no="%(no)d" data-name="%(aname)s">
-<input type="radio" name="q%(qc)d" id="%(eid)s" value="%(aname)s" />
-<label for="%(eid)s">
- """ % locals(), u"</label></li>"
+ input_tag = u'<input type="radio" name="q%(qc)d" id="%(eid)s" value="%(eid)s" />'
else:
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>"
-
+ input_tag = u'<input type="checkbox" name="%(eid)s" id="%(eid)s" />'
+ return (u"""
+<li class="question-piece" data-qc="%(qc)d" data-no="%(no)d" data-sol="%(sol)s">
+ """ + input_tag + u"""
+<label for="%(eid)s">""") % params, u"</label></li>"
else:
return super(Wybor, self).handle_punkt(element)
else:
return super(Wybor, self).handle_punkt(element)
@@
-659,7
+648,7
@@
class EduModuleFormat(Format):
order = {pmf: i for (i, pmf) in enumerate(self.PRIMARY_MATERIAL_FORMATS)}
mats = self.materials_by_slug.get(slug, {}).items()
if not mats:
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 sorted(mats, key=lambda (x, y): order.get(x, x))
def url_for_material(self, slug, fmt):