def __init__(self, options=None):
super(EduModule, self).__init__(options)
self.activity_counter = 0
+
+ # text filters
+ def swap_endlines(txt):
+ if self.options['strofa']:
+ txt = txt.replace("/\n", "<br/>\n")
+ return txt
self.register_text_filter(functions.substitute_entities)
+ self.register_text_filter(swap_endlines)
+ @tagged('div', 'stanza')
+ def handle_strofa(self, element):
+ self.options = {'strofa': True}
+ return "", ""
+
def handle_powiesc(self, element):
return u"""
<div class="module" id="book-text">
handle_naglowek_scena = tag('h2')
handle_naglowek_osoba = handle_naglowek_podrozdzial = tag('h3')
handle_akap = handle_akap_dialog = handle_akap_cd = tag('p', 'paragraph')
- handle_strofa = tag('div', 'stanza')
+
handle_wyroznienie = tag('em')
handle_tytul_dziela = tag('em', 'title')
handle_slowo_obce = tag('em', 'foreign')
atxt = etree.tostring(a, encoding=unicode)
toc.append("<li>%s</li>" % atxt)
toc = "<ul class='toc'>%s</ul>" % "".join(toc)
- return "<h1 class='title'>Lekcja: ", "</h1>" + toc
+ add_header = "Lekcja: " if self.options['wldoc'].book_info.type in ('course', 'synthetic') else ''
+ return "<h1 class='title'>%s" % add_header, "</h1>" + toc
@tagged("h2")
def handle_naglowek_rozdzial(self, element):
<div class="activity">
<div class="text">
<span class="act_counter">%(counter)d.</span>
- %(opis)s
- %(wskazowki)s
+ %(opis)s""" % locals(), \
+u"""%(wskazowki)s
</div>
<aside class="info">
<section class="infobox time"><h1>Czas</h1><p>%(czas)s min</p></section>
def handle_lista(self, element, attrs={}):
ltype = element.attrib.get('typ', 'punkt')
if ltype == 'slowniczek':
- surl = element.attrib.get('href', None)
+ surl = element.attrib.get('src', None)
+ if surl is None:
+ print '** missing src on <slowniczek>, setting default'
+ surl = 'http://edukacjamedialna.edu.pl/slowniczek'
sxml = None
if surl:
sxml = etree.fromstring(self.options['provider'].by_uri(surl).get_string())
nxt = element.getnext()
definiens_s = ''
+ if not element.text:
+ print "!! Empty <definiendum/>"
+ return None
+
# let's pull definiens from another document
- if self.options['slowniczek_xml'] and (not nxt or nxt.tag != 'definiens'):
+ if self.options['slowniczek_xml'] is not None and (nxt is None or nxt.tag != 'definiens'):
sxml = self.options['slowniczek_xml']
- assert element.text != ''
defloc = sxml.xpath("//definiendum[text()='%s']" % element.text)
if defloc:
definiens = defloc[0].getnext()
if definiens.tag == 'definiens':
subgen = EduModule(self.options)
definiens_s = subgen.generate(definiens)
+ else:
+ print '!! Missing definiendum in source:', element.text
return u"<dt>", u"</dt>" + definiens_s
pre, post = super(Wybor, self).handle_cwiczenie(element)
is_single_choice = True
pytania = element.xpath(".//pytanie")
- if not pytania:
+ if not pytania:
pytania = [element]
for p in pytania:
solutions = re.split(r"[, ]+", p.attrib['rozw'])
if len(solutions) != 1:
is_single_choice = False
break
- choices = element.xpath(".//*[@nazwa]")
+ choices = p.xpath(".//*[@nazwa]")
uniq = set()
for n in choices: uniq.add(n.attrib['nazwa'])
if len(choices) != len(uniq):
return question.xpath(".//luka")
def solution_html(self, piece):
- return piece.text + ''.join(
- [etree.tostring(n, encoding=unicode)
- for n in piece])
+ sub = EduModule()
+ return sub.generate(piece)
+ # print piece.text
+ # return piece.text + ''.join(
+ # [etree.tostring(n, encoding=unicode)
+ # for n in piece])
def handle_pytanie(self, element):
qpre, qpost = super(Luki, self).handle_pytanie(element)
super(EduModuleFormat, self).__init__(wldoc, **kwargs)
def build(self):
- edumod = EduModule({'provider': self.wldoc.provider, 'urlmapper': self})
+ edumod = EduModule({'provider': self.wldoc.provider, 'urlmapper': self, 'wldoc': self.wldoc})
html = edumod.generate(self.wldoc.edoc.getroot())